Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-27T10:17:59.223Z
Answers.Text: Thanks. I couldn't +1 because I've only got 11 rep.
Answers.UserDisplayName: Spiritman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-20T03:54:16.513Z
Answers.LastActivityDate: 2024-06-21T09:26:20.330Z
Answers.LastEditDate: 2024-06-21T09:26:20.330Z
Answers.UserDisplayName: filtuhchayn
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-10T14:57:41.640Z
Comments.Text: 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.
Comments.UserDisplayName: MarianD
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-10T16:28:35.187Z
Comments.Text: 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.
Comments.UserDisplayName: Spiritman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-03-10T16:59:58.173Z
Comments.Text: 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.;-)
Comments.UserDisplayName: MarianD
Tags: <ffmpeg><filter><command-line>
Title: Which FFmpeg variable gives the total duration of a video?
UserDisplayName: Spiritman
ThreadText: # 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.  
  
  ---
  
  