title: ffmpeg Progress Bar - Encoding Percentage in PHP
body: <p>I've written a whole system in PHP and bash on the server to convert and stream videos in HTML5 on my VPS. The conversion is done by ffmpeg in the background and the contents is output to <strong>block.txt</strong>.</p>
  
  <p>Having looked at the following posts:</p>
  
  <p><a href="https://stackoverflow.com/questions/747982/can-ffmpeg-show-a-progress-bar">Can ffmpeg show a progress bar?</a></p>
  
  <p>and</p>
  
  <p><a href="https://stackoverflow.com/questions/3770927/ffmpeg-video-encoding-progress-bar">ffmpeg video encoding progress bar</a></p>
  
  <p>amongst others, I can't find a working example.</p>
  
  <p>I need to grab the currently encoded progress as a percentage.</p>
  
  <p><strong>The first post I linked above gives:</strong></p>
  
  <pre><code>$log = @file_get_contents('block.txt');
  
  preg_match("/Duration:([^,]+)/", $log, $matches);
  list($hours,$minutes,$seconds,$mili) = split(":",$matches[1]);
  $seconds = (($hours * 3600) + ($minutes * 60) + $seconds);
  $seconds = round($seconds);
  
  $page = join("",file("$txt"));
  $kw = explode("time=", $page);
  $last = array_pop($kw);
  $values = explode(' ', $last);
  $curTime = round($values[0]);
  $percent_extracted = round((($curTime * 100)/($seconds)));
  
  echo $percent_extracted;
  </code></pre>
  
  <p>The $percent_extracted variable echoes zero, and as maths is not my strong point, I really don't know how to progress here.</p>
  
  <p><strong>Here's one line from the ffmpeg output from block.txt (if it's helpful)</strong></p>
  
  <blockquote>
    <p>time=00:19:25.16 bitrate= 823.0kbits/s frame=27963 fps= 7 q=0.0 size=
    117085kB time=00:19:25.33 bitrate= 823.1kbits/s frame=27967 fps= 7
    q=0.0 size= 117085kB time=00:19:25.49 bitrate= 823.0kbits/s
    frame=27971 fps= 7 q=0.0 size= 117126kB</p>
  </blockquote>
  
  <p>Please help me output this percentage, once done I can create my own progress bar. Thanks.</p>