Search code examples
ffmpegdrawtext

Need to set Multiple drawtext in same line one after the other. but unable to do so via FFMPEG command


Hi Am trying to create a FFMPEG command for Text overlay on video that has partially text as bold. I am using the following command. but am unable to figure out how to pass the x position of 1st ending part.

ffmpeg -i b.mp4 -vf "drawtext=fontfile=arial.ttf:text='Title of this video is ':fontcolor=blue:fontsize=20,drawtext=fontfile=ariali.ttf:text='How to have a healthy Life':fontcolor=yellow:fontsize=20:x=**<width of 1st text>**" -c:v libx264 -c:a copy -movflags +faststart output.mp4 -y

Solution

  • A workaround is to use the subtitles filter.

    example of bold and regular text in the same line

    ffmpeg -i input.mp4 -filter_complex subtitles=subs.ass -c:a copy output.mp4
    

    Example ASS file:

    [Script Info]
    ; Script generated by Aegisub 3.2.2
    ; http://www.aegisub.org/
    Title: Default Aegisub file
    ScriptType: v4.00+
    WrapStyle: 0
    ScaledBorderAndShadow: yes
    YCbCr Matrix: None
    
    [Aegisub Project Garbage]
    Last Style Storage: Default
    
    [V4+ Styles]
    Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
    Style: Default,Arial,38,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
    
    [Events]
    Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
    Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,{\c&HFFFF00&}Title of this video is {\c&H00FFFF&\b1}How to Have a Healthy Life.{\b0}