2

I'm using the current code to create a video with some text of several lines. When executed I'm receiving a video with the text joined vertically because of lacking space. How do I do to add line-height space?

ffmpeg -i videoInput.mp4 \
       -vf drawtext="./font/Roboto/Roboto-Bold.ttf: \
           text='testing text \ntesting text \ntesting text':\
           fontcolor=yellow:\
           fontsize=36:\
           box=1:\
           boxcolor=black@0.5: \
           boxborderw=160:\
           x=(w-text_w)/2:\
           y=(h-text_h)/2"\
    -codec:a copy \
    videoOutput.mp4
  • 1
    I think you can't specify line-height. But you can use several distinct drawtext lines, spearated by commas, each at a different position. But that may not be practical if your texts don't have the same number of lines. Maybe you get better results using the subtitles or the ass filter instead? – mivk May 23 '20 at 23:27
  • I have used the \n\n characters to separate the lines, but it is restrictive to that technique. I will look to subtitles filter, maybe it is a better way to styling text. Thank a lot for the insight. – Romualdo Arrechea Hernández May 23 '20 at 23:34

1 Answers1

2

To increase the line-height add a line_spacing parameter to the command,(http://ffmpeg.org/ffmpeg-filters.html#drawtext-1) So it looks like:

ffmpeg -i videoInput.mp4 \
       -vf drawtext="./font/Roboto/Roboto-Bold.ttf: \
           text='testing text \ntesting text \ntesting text':\
         line_spacing=30:\
           fontcolor=yellow:\
           fontsize=36:\
           box=1:\
           boxcolor=black@0.5: \
           boxborderw=160:\
           x=(w-text_w)/2:\
           y=(h-text_h)/2"\
    -codec:a copy \
    videoOutput.mp4

Or

Some trick is to append a double breakline on the desired text. It would look like:

  text='testing text \n\ntesting text \n\ntesting text'
ffmpeg -i videoInput.mp4 \
       -vf drawtext="./font/Roboto/Roboto-Bold.ttf: \
           text='testing text \n\ntesting text \n\ntesting text':\
           fontcolor=yellow:\
           fontsize=36:\
           box=1:\
           boxcolor=black@0.5: \
           boxborderw=160:\
           x=(w-text_w)/2:\
           y=(h-text_h)/2"\
    -codec:a copy \
    videoOutput.mp4