1

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:[email protected]: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.

3
  • 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
    Commented Mar 10, 2022 at 14:57
  • 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
    Commented Mar 10, 2022 at 16:28
  • 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
    Commented Mar 10, 2022 at 16:59

1 Answer 1

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 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.

1
  • Thanks. I couldn't +1 because I've only got 11 rep.
    – Spiritman
    Commented Jun 27 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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