Search code examples
ffmpegdrawtext

How to increase line-height of text using drawtext with FFMPEG?


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:\
           [email protected]: \
           boxborderw=160:\
           x=(w-text_w)/2:\
           y=(h-text_h)/2"\
    -codec:a copy \
    videoOutput.mp4

Solution

  • 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:\
               [email protected]: \
               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:\
               [email protected]: \
               boxborderw=160:\
               x=(w-text_w)/2:\
               y=(h-text_h)/2"\
        -codec:a copy \
        videoOutput.mp4