title: ffmpeg not returning duration, cant play video until complete. Stream images 2 video via PHP
body: <p>I am real struggling with ffmpeg. I am trying to convert images to video, I have an ip camera which I am recording from. The recordings are mjpegs 1 frame per image. </p>
  
  <p>I am trying to create a script in php so I can recreate a video from date to date, this requires inputting the images via image2pipe and then creating the video. </p>
  
  <p>The trouble is, ffmpeg does return the duration and start stats, so I have no way of working out when the video is done or what percentage is done. The video won't play until its finished, and its not a very good UE.</p>
  
  <p>Any ideas of how I can resolve this, the video format can be anything I am open to suggestions.</p>
  
  <p>PHP:</p>
  
  <pre><code>//Shell command
  exec('cat /image/dir/*.jpg | ffmpeg -y -c:v mjpeg -f image2pipe -r 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart myvids/vidname.mp4 1&gt;vidname.txt 2&gt;&amp;1')
  
  //This is loaded via javascript when the video is loaded (which is failing due to stats being wrong
  $video_play = "&lt;video width=\"320\" height=\"240\" src=\"myvids/vidname.mp4\" type=\"video/mp4\"\
  id=\"player1\" controls=\"controls\" preload=\"none\"&gt;&lt;/video&gt;";
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>//Javascript to create the loop until video is loaded
  &lt;script&gt;
             $(document).ready(function() {
                  var loader = $("#clip_load").percentageLoader();
                  $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
                  var interval = setInterval(updateProgress,1000);
                  function updateProgress(){ $.get( "'.base_url().'video/getVideoCompile_Process?l='.$vid_name.'-output.txt&amp;t=per", function( data ) { if(data=&gt;\'100\'){ $("#clip_load").html(\''.$video_play.'\'); clearInterval(interval); }else{loader.setProgress(data); } });                    }
              });
              &lt;/script&gt;
  </code></pre>
  
  <p>PHP (page is called via javascript:</p>
  
  <pre><code>//This is the script which returns the current percentage
  $logloc = $this-&gt;input-&gt;get('l');
  $content = @file_get_contents($logloc);
  
  if($content){
      //get duration of source
      preg_match("/Duration: (.*?), start:/", $content, $matches);
  
      $rawDuration = $matches[1];
  
      //rawDuration is in 00:00:00.00 format. This converts it to seconds.
      $ar = array_reverse(explode(":", $rawDuration));
      $duration = floatval($ar[0]);
      if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
      if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;
  
      //get the time in the file that is already encoded
      preg_match_all("/time=(.*?) bitrate/", $content, $matches);
  
      $rawTime = array_pop($matches);
  
      //this is needed if there is more than one match
      if (is_array($rawTime)){$rawTime = array_pop($rawTime);}
  
      //rawTime is in 00:00:00.00 format. This converts it to seconds.
      $ar = array_reverse(explode(":", $rawTime));
      $time = floatval($ar[0]);
      if (!empty($ar[1])) $time += intval($ar[1]) * 60;
      if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;
  
      //calculate the progress
      $progress = round(($time/$duration) * 100);
      if ($this-&gt;input-&gt;get('t')=='per'){
          echo $progress;
      }else{
              echo "Duration: " . $duration . "&lt;br&gt;";
              echo "Current Time: " . $time . "&lt;br&gt;";
      echo "Progress: " . $progress . "%";}
  }else{ echo "cannot locate";}
  </code></pre>
  
  <p>Thanks</p>