I am using ffmpeg to convert a video file to H.264 format. If I call ffprobe while ffmpeg is still running the duration of the video is not known. Only when ffmpeg finishes the ffprobe will display the duration.

Similar, if I run mplayer to play the video while it is still being encoded the duration is either unknown or displays incorrectly.

Is there a way to know duration of the resulted video (h264 in .mkv container) while it is still being encoded by ffmpeg?

Edit: I will make the question a little bit more clear.

I am interested in knowing how long is the video which was encoded so far. Let's say the input file is 1 minute 45 seconds long. The resulting file should preserve the length. But I would like to know how much did ffmpeg encode so far. If we can determine the length of the video after conversion is done, shouldn't there be a way to determine the length of the video that was already processed and ready to be played?

2 Answers 2


Short answer is No.

Longer answer is, it depends.

If you're encoding a file, then generally the output is the duration of the input, unless there's speed change or trim filters or -ss, -to, -t options applied. For a live input, FFmpeg will stop the encode when it encounters EOF on the input, so unless you know that, you won't know the output duration. For multiple inputs of differing duration, it will depend on what the command is e.g. is there a -shortest in there, is there an amix, which defaults to the longest of the inputs, or amerge which terminates upon the shortest input.

By default, the ffmpeg console readout will display the progress of the encoding in realtime i.e. the duration encoded, so far.

  • Thank you for explanation. I edited my question and added some details, could you check it and see if you can add more data to your answer?
    – VL-80
    May 8, 2016 at 18:24
  • As my last para states, ffmpeg already displays this info in the console output, which is streamed to stderr
    – Gyan
    May 8, 2016 at 18:32
  • This is true. I completely overlooked it! Thanks again.
    – VL-80
    May 8, 2016 at 18:34
  • Also, I would like to add there is an FFmpeg option -progress that causes it to output the aforementioned progress information in a machine friendly format that can be easily parsed.
    – VL-80
    May 11, 2016 at 2:11

See the -report option. From the manpages:


Dump full command line and console output to a file named "program-YYYYMMDD-HHMMSS.log" in the current directory. This file can be useful for bug reports. It also implies "-loglevel verbose".

Setting the environment variable FFREPORT to any value has the same effect. If the value is a ':'-separated key=value sequence, these options will affect the report; option values must be escaped if they contain special characters or the options delimiter ':' (see the ``Quoting and escaping'' section in the ffmpeg-utils manual).

The following options are recognized:


set the file name to use for the report; %p is expanded to the name of the program, %t is expanded to a timestamp, "%%" is expanded to a plain "%"


set the log verbosity level using a numerical value (see "-loglevel").

For example, to output a report to a file named ffreport.log using a log level of 32 (alias for log level "info"):

FFREPORT=file=ffreport.log:level=32 ffmpeg -i input output

Errors in parsing the environment variable are not fatal, and will not appear in the report.

Combine with -stats and your one | head -n 2 | tail -n 1 to go:

-stats (global)

Print encoding progress/statistics. It is on by default, to explicitly disable it you need to specify "-nostats".

If you have trouble with its progress bar, which uses \r to rewrite the same line, you can ffmpeg -stats ... 2>&1 | tr \\r \\n to head&tail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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