0

how text align center, right , left positions with drawtext with multi line as input.

"Hello \n world"

2 Answers2

2

FFMPEG doesn't seem to support Alignment in the drawtext command, we need to manually do so. i had the same issue, but to solve that i took a different approach, you can follow the same steps.

  1. After adding your text, when you want to save it..
  2. Convert those texts into the image
  3. Add those images to FFMPEG with the help of the "Image overlay command".

i hope these steps help.

Vaidehee Vala
  • 324
  • 3
  • 7
1

drawtext

I can think of two methods for text alignment in drawtext:

  1. Use a monospace font and add the required number of spaces in line 2.
  2. Use 2 drawtext instances to independently position each line.

Neither method is ideal.

subtitles

Using ASS subtitles could be a better solution.

The behavior of \pos changes depending on the Alignment. See the \pos tag documentation for examples.

Once you create the ASS file, such as with Aegisub, you can add the subtitles with ffmpeg.

Softsubs

ffmpeg -i input.mkv -i subs.ass -map 0 -map 1 -c copy output.mkv

Hardsubs

Using the subtitles filter:

ffmpeg -i input.mkv -vf "subtitles=subs.ass" -c:a copy output.mkv
llogan
  • 121,796
  • 28
  • 232
  • 243
  • Got it , But how to load external font file in .ass file for font – Konduri Sai Aditya Nov 18 '20 at 17:31
  • @KonduriSaiAditya That's a new question. Different topic. Should be a new and separate post. This answer is directly addressing "How text align text filter in ffmpeg with multi line text". Stack Overflow is intended to be 1 question per post. – llogan Nov 18 '20 at 19:13