Answers.Body: <p>Short answer is No.</p>
  
  <p>Longer answer is, it depends.</p>
  
  <p>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 <code>-ss, -to, -t</code> 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 <code>-shortest</code> in there, is there an <code>amix</code>, which defaults to the longest of the inputs, or <code>amerge</code> which terminates upon the shortest input.</p>
  
  <p>By default, the ffmpeg console readout will display the progress of the encoding in realtime i.e. the duration encoded, so far.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-08T18:24:58.113Z
Answers.Text: 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?
Answers.UserDisplayName: VL-80
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-08T18:32:41.220Z
Answers.Text: As my last para states, ffmpeg already displays this info in the console output, which is streamed to `stderr`
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-08T18:34:27.757Z
Answers.Text: This is true. I completely overlooked it! Thanks again.
Answers.UserDisplayName: VL-80
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-11T02:11:59.903Z
Answers.Text: 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.
Answers.UserDisplayName: VL-80
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-08T17:42:22.910Z
Answers.LastActivityDate: 2016-05-08T17:42:22.910Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>See the <code>-report</code> option. From the manpages:</p>
  
  <blockquote>
    <p><strong>-report</strong></p>
    
    <p>Dump full command line and console output to a file named "<em>program-YYYYMMDD-HHMMSS.log</em>" in the current directory.  This file can be useful for bug reports.  It also implies "<code>-loglevel verbose</code>".</p>
    
    <p>Setting the environment variable <code>FFREPORT</code> to any value has the same effect. If the value is a '<code>:</code>'-separated <em>key</em><code>=</code><em>value</em> sequence, these options will affect the report; option values must be escaped if they contain special characters or the options delimiter '<code>:</code>' (see the ``Quoting and escaping'' section in the ffmpeg-utils manual).</p>
    
    <p>The following options are recognized:</p>
    
    <p><strong>file</strong></p>
    
    <p>set the file name to use for the report; <code>%p</code> is expanded to the name of the program, <code>%t</code> is expanded to a timestamp, "<code>%%</code>" is expanded to a plain "<code>%</code>"</p>
    
    <p><strong>level</strong></p>
    
    <p>set the log verbosity level using a numerical value (see "<code>-loglevel</code>").</p>
    
    <p>For example, to output a report to a file named <strong>ffreport.log</strong> using a log level of <strong>32</strong> (alias for log level "<code>info</code>"):</p>
    
    <p><code>FFREPORT=file=ffreport.log:level=32 ffmpeg -i input output</code></p>
    
    <p>Errors in parsing the environment variable are not fatal, and will not appear in the report.</p>
  </blockquote>
  
  <p>Combine with <code>-stats</code> and your one <code>| head -n 2 | tail -n 1</code> to go:</p>
  
  <blockquote>
    <p><strong>-stats (global)</strong></p>
    
    <p>Print encoding progress/statistics. It is on by default, to explicitly disable it you need to specify "<code>-nostats</code>".</p>
  </blockquote>
  
  <p>If you have trouble with its progress bar, which uses <code>\r</code> to rewrite the same line, you can <code>ffmpeg -stats ... 2&gt;&amp;1 | tr \\r \\n</code> to head&amp;tail.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-30T19:54:08.280Z
Answers.LastActivityDate: 2019-08-30T19:54:08.280Z
Answers.UserDisplayName: Luchostein
Body: <p>I am using <code>ffmpeg</code> to convert a video file to H.264 format. If I call <code>ffprobe</code> while <code>ffmpeg</code> is still running the duration of the video is not known. Only when <code>ffmpeg</code> finishes the <code>ffprobe</code> will display the duration.</p>
  
  <p>Similar, if I run <code>mplayer</code> to play the video while it is still being encoded the duration is either unknown or displays incorrectly.</p>
  
  <p>Is there a way to know duration of the resulted video (h264 in .mkv container) while it is still being encoded by <code>ffmpeg</code>?</p>
  
  <p><strong>Edit</strong>: <em>I will make the question a little bit more clear.</em></p>
  
  <p>I am interested in knowing how long is the video which was encoded <strong>so far</strong>. 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 <code>ffmpeg</code> encode <strong>so far</strong>. 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?</p>
  
Tags: <ffmpeg><encoding><mkv><libx264>
Title: How to calculate the length of the video file that was encoded so far?
UserDisplayName: VL-80
ThreadText: # How to calculate the length of the video file that was encoded so far?
  
  (Asked by: username_0 on 2016-05-08)
  
  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?
  
  **Tags:** ffmpeg, encoding, mkv, libx264
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-05-08. Score: 2 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: 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?  
  > **username_1**: As my last para states, ffmpeg already displays this info in the console output, which is streamed to `stderr`  
  > **username_0**: This is true. I completely overlooked it! Thanks again.  
  > **username_0**: 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.  
  
  ---
  
  ### Answer by username_2 on 2019-08-30. Score: 0
  
  See the `-report` option. From the manpages:
  
  > **-report**
  >
  > 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:
  >
  > **file**
  >
  > 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 "`%`"
  >
  > **level**
  >
  > 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.
  
  
  ---
  
  