[FFmpeg-user] center-align multiple text lines

Michael Koch astroelectronic at t-online.de
Tue Apr 28 15:46:36 EEST 2020

Am 11.04.2020 um 23:24 schrieb Moritz Barsnick:
> On Sat, Apr 11, 2020 at 23:03:31 +0200, Michael Koch wrote:
>> I want to show the content of a credits file scrolling up.The file
>> contains many lines of different lengths.
>> drawtext=textfile=credits.txt:x=(w-text_w)/2:y=h-100*t
>> The variable text_w is the width of the longest line in the text file.
>> This line is center-aligned in the frame, and all other (shorter) lines
>> are left-aligned to the same X position as the longest line.
>> But that's not what I want. Is it somehow possible that each line is
>> center-aligned?
> I can't answer your question, unfortunately, but how about an
> alternative? You can write your credits as ASS subtitles, and have
> ffmpeg render them on top of your video.
> The example I retrieved here:
> http://forum.doom9.org/showthread.php?t=82025
> works just fine.
> Use this as credits.ass:
> ---snip---
> [Script Info]
> ScriptType: v4.00+
> Collisions: Normal
> PlayResX: 640
> PlayResY: 480
> Timer: 100.0000
> [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: testStyle,Verdana,24,&H4099ffff,&H00000000,&Hc0000000,&H00000000,-1,0,0,0,100,100,0,0.00,1,1,0,8,0,0,0,0
> [Events]
> Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
> Dialogue: 0,0:00:02.00,0:00:12.00,testStyle,,0000,0000,0000,,{\move(320,400,320,80)}{\fad(1000,1000)}Foo bar
> Dialogue: 0,0:00:04.00,0:00:14.00,testStyle,,0000,0000,0000,,{\move(320,400,320,80)}{\fad(1000,1000)}Baz
> Dialogue: 0,0:00:06.00,0:00:16.00,testStyle,,0000,0000,0000,,{\move(320,400,320,80)}{\fad(1000,1000)}Qux quux quuux
> Dialogue: 0,0:00:08.00,0:00:18.00,testStyle,,0000,0000,0000,,{\move(320,400,320,80)}{\fad(1000,1000)}Xyzzy
> ---snip---
> and overlay it onto your video:
> $ ffmpeg -f lavfi -i testsrc=s=640x480 -vf subtitles=credits.ass -f nut - | ffplay -
> ASS is tricky to create manually, but you might figure out the concept
> from the example, or use a tool to create them.

Thank you very much. It works perfectly and it's not as complicated as 
it looks at first glimpse.


More information about the ffmpeg-user mailing list