I am currently working with the drawtext and drawbox filters to recreate a similar video appearance to what is shown below in the image. I am trying to see of a possible ways to add a count down timer to display video duration. The timer could either be placed in the upper left or right hand corners.

I am able to generate a test video showing a timer this way: ffplay -f lavfi -i testsrc OR ffmpeg -f lavfi -i testsrc -vf crop=29:52:256:94 -t 10 timer1.mp4. However, how can I display a timer?

drawbox/drawtext filter settings

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"

desired output

Desired output

  • 2
    Why did you remove the image showing the desired output? Without it, the question is totally unclear.
    – sebix
    May 23, 2015 at 8:45

1 Answer 1


This is possible but will require scripting. ffprobe will be used to determine the duration of the input, then the countdown and background box will be created by the drawtext filter.

reverse duration countdown timer
A 30 second input will start from 30 and count down to 0.


duration=$(ffprobe -loglevel error -show_entries format=duration -of default=nw=1:nk=1 "$input")
ffmpeg -i "$input" -vf "drawtext=fontfile=OpenSans-Regular.ttf:text='%{eif\:$duration-t\:d}':fontcolor=white:fontsize=24:x=w-tw-20:y=th:box=1:[email protected]:boxborderw=10,format=yuv420p" -c:v libx264 -c:a copy -movflags +faststart output.mp4
  • If you prefer rounded corners you may be able to make a PNG file with alpha, and then place it in your desired location using the overlay filter. Doesn't seem worth it to me though.

  • If you find the duration from ffprobe to be inaccurate then you will have to completely decode the file to get the actual duration and then parse the console output. One method would be: ffmpeg -i input -f null -.

  • This may be possible to do without ffprobe but I don't have an alternative method at the moment.

  • You can combine this filterchain with the one from ffmpeg drawtext filter - create transparent background with text to get exactly what you want. An oversimplified command could then look like:

    -vf "format,drawbox,drawtext,drawtext,format"
  • @Code_Ed_Student It will vary in width according to the number of digits. If that's annoying then dump all of the box related stuff from drawtext and make another box with drawbox instead. If you want to keep using the current method with drawtext then boxborderw will control the "padding", but you can't independently control top, right, bottom, and left like you can in CSS.
    – llogan
    May 17, 2015 at 1:01
  • Let us continue this discussion in chat.
    – llogan
    May 17, 2015 at 7:13
  • You are absolutely right, I am sticking with just having it in drawtext. I just increased the boxborderw to ultimately get what I needed it. Thanks for all the help! what are the coordinates to place timer in the left corner? May 17, 2015 at 14:22
  • @Code_Ed_Student Top left? That's the easy one because that's the default. You can probably use boxborderw + whatever margin you want, so if boxborderw is 10, and you want a 10 pixel margin separating the box from the left and top edges, then x=20:y=20 or x=20:y=x. You will have to experiment.
    – llogan
    May 17, 2015 at 17:20
  • I have another ffmpeg question in relation to crossfading: video.stackexchange.com/questions/15740/… Jun 11, 2015 at 18:26

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.