<p>Not practical within a filterchain, sorry.</p>
<p>Filters are only passed information about each frame as they arrive. In fact, beside certain exceptions where <a href="https://ffmpeg.org/doxygen/trunk/structAVFrameSideData.html" rel="nofollow noreferrer">side-data</a> can be passed from the decoder to filters, a filter is completely blind to anything about the source video that isn't a decoded frame and metadata about <em>that one frame</em>. A filter only knows when the input has ended because it receives EOF from the stream.</p>
<p>You could probably come up with an ugly hack where you split the video, force it to be transparent, and draw text on one copy before passing it through <code>reverse,select='eq(n,0)',loop=-1</code> to get the last frame and repeat it, which would have the total duration as text on an alpha background. You could then overlay it but that's ugly and would require keeping the entire stream in memory.</p>

CC BY-SA 4.0
2024-06-27T10:17:59.223Z
Thanks. I couldn't +1 because I've only got 11 rep.
Spiritman
CC BY-SA 4.0
2024-06-20T03:54:16.513Z
2024-06-21T09:26:20.330Z
2024-06-21T09:26:20.330Z
filtuhchayn
<p>I've spent hours searching the documentation and forums for a simple variable and it's driving me crazy. Can anyone tell me what the variable is that gives the total duration of a video, so that I can draw a progress bar on a video played by FFplay?</p>
<p>My filter is:</p>
<pre><code>drawbox=x=0:y=ih-8:w=pts/duration*iw:h=8:color=green@0.5:t=fill
</code></pre>
<p>but <code>duration</code> is not recognised. I've tried t, time, total_time, dur, len, length, total_length, s, secs, stream_length, all to no avail. (A box does get drawn if I just put w=50, for example, so the rest is correct, but I need it to change over time.)</p>
<p>I'm amazed I haven't yet found a comprehensive list of these variables.</p>
<p>If anyone can help, I'd be super grateful. Thanks.</p>

CC BY-SA 4.0
2022-03-10T14:57:41.640Z
Total duration of video is a pretty complicated thing before the video itself is finished.;-) So there is no such a variable. An individual filter may obtain (from the previous) info such as the presentation time stamp or width, but not the **total** time.
MarianD
CC BY-SA 4.0
2022-03-10T16:28:35.187Z
That's true during streaming and encoding, but during ffplay playback the file is already complete and not being altered. I guess I'll need a whole routine just to probe the duration before playback. Pity, a single command line would've been so elegant.
Spiritman
CC BY-SA 4.0
2022-03-10T16:59:58.173Z
FFplay also accept filters. - Anyway, there is not such a variable (for total duration), it is not such a simple thing even for a complete video. Media players only *estimate* the total time – in most cases with acceptable tolerance (say within 1-second interval). You have to deal with this fact, as did I and many other people.;-)
MarianD
<ffmpeg><filter><command-line>
Which FFmpeg variable gives the total duration of a video?
Spiritman
# Which FFmpeg variable gives the total duration of a video?

(Asked by: username_0 on 2022-03-09)

I've spent hours searching the documentation and forums for a simple variable and it's driving me crazy. Can anyone tell me what the variable is that gives the total duration of a video, so that I can draw a progress bar on a video played by FFplay?
My filter is:
drawbox=x=0:y=ih-8:w=pts/duration*iw:h=8:color=green@0.5:t=fill

but duration is not recognised. I've tried t, time, total_time, dur, len, length, total_length, s, secs, stream_length, all to no avail. (A box does get drawn if I just put w=50, for example, so the rest is correct, but I need it to change over time.)
I'm amazed I haven't yet found a comprehensive list of these variables.
If anyone can help, I'd be super grateful. Thanks.

**Tags:** ffmpeg, filter, command-line

> **Comments:**
> **username_1**: Total duration of video is a pretty complicated thing before the video itself is finished.;-) So there is no such a variable. An individual filter may obtain (from the previous) info such as the presentation time stamp or width, but not the **total** time.  
> **username_0**: That's true during streaming and encoding, but during ffplay playback the file is already complete and not being altered. I guess I'll need a whole routine just to probe the duration before playback. Pity, a single command line would've been so elegant.  
> **username_1**: FFplay also accept filters. - Anyway, there is not such a variable (for total duration), it is not such a simple thing even for a complete video. Media players only *estimate* the total time – in most cases with acceptable tolerance (say within 1-second interval). You have to deal with this fact, as did I and many other people.;-)  

---

## 1 answers

### Answer by username_2 on 2024-06-20. Score: 1

Not practical within a filterchain, sorry.

Filters are only passed information about each frame as they arrive. In fact, beside certain exceptions where [side-data](https://ffmpeg.org/doxygen/trunk/structAVFrameSideData.html) can be passed from the decoder to filters, a filter is completely blind to anything about the source video that isn't a decoded frame and metadata about *that one frame*. A filter only knows when the input has ended because it receives EOF from the stream.

You could probably come up with an ugly hack where you split the video, force it to be transparent, and draw text on one copy before passing it through `reverse,select='eq(n,0)',loop=-1` to get the last frame and repeat it, which would have the total duration as text on an alpha background. You could then overlay it but that's ugly and would require keeping the entire stream in memory.

> **Comments:**
> **username_0**: Thanks. I couldn't +1 because I've only got 11 rep.  

---

