<p>This is possible but will require scripting. <code>ffprobe</code> will be used to determine the duration of the input, then the countdown and background box will be created by the <a href="https://ffmpeg.org/ffmpeg-filters.html#drawtext" rel="nofollow noreferrer"><code>drawtext</code></a> filter.</p>

<p><img src="https://i.sstatic.net/84Gwd.jpg" alt="reverse duration countdown timer"><br>
<sub>A 30 second input will start from 30 and count down to 0.</sub></p>

<p>Example:</p>

<pre><code>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
</code></pre>

<ul>
<li><p>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 <a href="https://ffmpeg.org/ffmpeg-filters.html#overlay" rel="nofollow noreferrer"><code>overlay</code></a> filter. Doesn't seem worth it to me though.</p></li>
<li><p>If you find the duration from <code>ffprobe</code> 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: <code>ffmpeg -i input -f null -</code>.</p></li>
<li><p>This may be possible to do without <code>ffprobe</code> but I don't have an alternative method at the moment.</p></li>
<li><p>You can combine this filterchain with the one from <a href="https://video.stackexchange.com/a/15554/1760">ffmpeg drawtext filter - create transparent background with text</a> to get exactly what you want. An oversimplified command could then look like:</p>

<pre><code>-vf "format,drawbox,drawtext,drawtext,format"
</code></pre></li>
</ul>

CC BY-SA 3.0
2015-05-17T01:01:29.983Z
@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
CC BY-SA 3.0
2015-05-17T07:13:56.973Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/23855/discussion-between-lordneckbeard-and-code-ed-student).
llogan
CC BY-SA 3.0
2015-05-17T14:22:42.180Z
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
CC BY-SA 3.0
2015-05-17T17:20:41.267Z
@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
CC BY-SA 3.0
2015-06-11T18:26:54.223Z
I have another ffmpeg question in relation to crossfading: http://video.stackexchange.com/questions/15740/crossfading-audio-at-beginning-and-ending-of-video
Code_Ed_Student
CC BY-SA 4.0
2019-02-22T11:57:53.217Z
@llogan probably need your help over here: https://video.stackexchange.com/questions/26036/translate-ffmpeg-drawtext-bash-code-to-batch
Arete
CC BY-SA 4.0
2019-02-22T17:51:07.460Z
@Arete Unfortunately I know nothing of Windows batch file scripting.
llogan
CC BY-SA 3.0
2015-05-16T18:52:23.530Z
2015-05-16T22:47:34.000Z
2017-04-13T12:46:08.110Z
llogan
<p>I am currently working with the <code>drawtext</code> and <code>drawbox</code> 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.</p>

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

<p><strong>drawbox/drawtext filter settings</strong></p>

<pre><code>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"
</code></pre>

<p><strong>desired output</strong></p>

<p><img src="https://i.sstatic.net/DmScO.png" alt="Desired output"></p>

CC BY-SA 3.0
2015-05-23T08:45:33.027Z
Why did you remove the image showing the desired output? Without it, the question is totally unclear.
sebix
<video><ffmpeg>
ffmpeg - video with timer
Code_Ed_Student
# ffmpeg - video with timer

(Asked by: username_0 on 2015-05-16)

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

**Tags:** video, ffmpeg

> **Comments:**
> **username_1**: Why did you remove the image showing the desired output? Without it, the question is totally unclear.  

---

## 1 answers

### Answer by username_2 on 2015-05-16. Score: 10 | Accepted answer

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.

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"

> **Comments:**
> **username_2**: @username_0 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.  
> **username_2**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/23855/discussion-between-lordneckbeard-and-code-ed-student).  
> **username_0**: 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?  
> **username_2**: @username_0 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.  
> **username_0**: I have another ffmpeg question in relation to crossfading: http://video.stackexchange.com/questions/15740/crossfading-audio-at-beginning-and-ending-of-video  
> **username_3**: @username_2 probably need your help over here: https://video.stackexchange.com/questions/26036/translate-ffmpeg-drawtext-bash-code-to-batch  
> **username_2**: @username_3 Unfortunately I know nothing of Windows batch file scripting.  

---

