user6618: 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


user1760: 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"



6618: <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.stack.imgur.com/DmScO.png" alt="Desired output"></p>
 1760: <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.stack.imgur.com/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>
