14

I am currently working with the drawtext filter. So far I have only been successful with drawtext option configurations to use the right font and place the text horizontally centered. How could i get drawtext to display text on a video as shown below?

ffmpeg

ffmpeg -i "/media/test/test.mp4" -vf drawtext="fontfile=/usr/share/fonts/truetype/open-sans/OpenSans-Regular.ttf:text='Title of this Video':x=(w-tw)/2:y=(h-th)/2"  /media/test_edited.mp4"
0

2 Answers 2

26

Use drawbox for the box, and drawtext for the text.

Red beetle

ffmpeg -i input.mp4 -vf \
"format=yuv444p, \
 drawbox=y=ih/PHI:[email protected]:width=iw:height=48:t=fill, \
 drawtext=fontfile=OpenSans-Regular.ttf:text='Title of this Video':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th, \
 format=yuv420p" \
-c:v libx264 -c:a copy -movflags +faststart output.mp4
  • drawtext has a box option, but as far as I can tell it can't be an arbitrary width and is relative to the text size, so that is why drawbox is used instead.

  • The format filter is used to improve the color of the drawbox area; otherwise, depending on your input and output formats, the area could look de-saturated or monochrome. The format filter is then used again to ensure that the pixel format of the output file is compatible with all players.

  • The audio is being stream copied in this example because you may not want to needlessly re-encode it.

  • Old ffmpeg users will have to use t=max instead of t=fill.

13
  • Perfect, this is out of scope of the current question and I may need to create a new question. Any suggestions of how to add the snapchat timer. For example, I did some testing and ffmpeg contains a testsrc video source that contains a timer: ffplay -f lavfi -i testsrc. The digit 0 of the initial timer has a 29x52 pixels size and its postion from the top -left corner is 256 pixels horizontally and 94 pixels vertical. I can crop the area of one digit like this ffmpeg -f lavfi -i testsrc -vf crop=29:52:256:94 -t 10 timer1.mp4 May 16, 2015 at 7:43
  • I added an image with a timer to the question. The timer is a count down based on the video's duration . May 16, 2015 at 7:54
  • Yes, I will create a new question for it. You are correct. 30. 29, 28... etc. May 16, 2015 at 7:57
  • 1
    Great and you are right it did affect the box May 16, 2015 at 18:17
2

ffmpeg -i C:\Users\Developer_2\Videos\2.mkv -vf drawtext="fontfile=C\:/Regular.ttf: text='apcis.tmou.org': fontcolor=white: fontsize=24: box=1: bo[email protected]: x=w-tw:y=h-th" C:\inetpub\wwwroot\videos\1.mp4

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.