Search code examples
ffmpeg

Align text in top middle of any photo/video frame in ffmpeg


I would like to know how to align the text in any sized photo/video frame in the top middle. I understand how to center the text on the x axis in any frame, so how do I make it always be at the top as well?

Heres what I've been doing so far:

ffmpeg -i input.jpg -vf "drawtext=font='Impact': text='Test Text': fontcolor=white: borderw=3: fontsize-75: x=(w-tw)/2:y=((h-text_h)/2)" output.jpg

Solution

  • By top-middle, I assume you mean horizontally centered and vertically centered within the top-third of the frame. That means the text has to be vertically centered around 1/6th the height. So, x=(w-tw)/2:y=h/6-th/2