Take the 2-minute tour ×
Video Production Stack Exchange is a question and answer site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation. It's 100% free, no registration required.

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 fmpeg -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"
share|improve this question
    
Why did you remove the image showing the desired output? Without it, the question is totally unclear. –  sebix May 23 at 8:45

1 Answer 1

up vote 4 down vote accepted

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.

Example:

input=input.mp4
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:boxcolor=black@0.5: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"
    
share|improve this answer
    
Ubuntu uses a forked version of FFmpeg, so that "libavfilter" is a fake. As of 15.04 FFmpeg has returned to Ubuntu, and the FFmpeg version of that package is named libavformat-ffmpeg* currently from the 2.5.6 branch. General users are recommended to use a build of ffmpeg from current git master (the most recent code). Releases are for distributors. Development is very active. Git master is stable and will have more features and bug fixes. I do not believe 2.6.2 contains the boxborderw option. –  LordNeckbeard May 16 at 22:39
    
@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. –  LordNeckbeard May 17 at 1:01
    
Let us continue this discussion in chat. –  LordNeckbeard May 17 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? –  Code_Ed_Student May 17 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. –  LordNeckbeard May 17 at 17:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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