--- ffmpeg_wrapper2/ffmpeg_wrapper_class.inc	2011-07-17 21:32:45.000000000 -0400
+++ ffmpeg_wrapper/ffmpeg_wrapper_class.inc	2011-07-19 10:57:03.000000000 -0400
@@ -38,7 +38,7 @@
    *
    * @NOTE SECURITY ISSUE WITH COMMAND LINE ACCESS. SORRY.
    */
-  function command($command, $verbosity = -1) {
+  function command($command, $verbosity = 1) {
     // Check and see if anyone is overridding this
     if ($function = variable_get('ffmpeg_wrapper_engine', FALSE)) {
       if (function_exists($function)) {
@@ -65,12 +65,43 @@
     $process = proc_open($this->command, $descriptor_spec, $pipes, $this->cwd, NULL, array('binary_pipes' => TRUE));
 
     if (is_resource($process)) {
+
+      // parse the stderr for duration information if we're transcoding a file
+      if ($this->file) {
+        stream_set_blocking($pipes[2], 0);
+        while (! feof($pipes[2])) {
+  
+          $stderr = ($stderr) ? $stderr . fgets($pipes[2]) : fgets($pipes[2]);
+  
+          $duration = ($duration) ? $duration : $this->parse_duration($stderr);
+  
+          preg_match_all("/time=(.*?) bitrate/", $stderr, $matches); 
+          
+          $current_time = floatval($matches[1][count($matches[1])-1]);
+          
+          $progress = round($current_time / $duration * 100);
+   
+          if ($progress > 0 && $progress <= 100) {
+            cache_set('ffmpeg_wrapper_transcoding_progress_' . $this->file->fid, $progress);
+          }
+        }
+  
+        // reset to 0
+        cache_set('ffmpeg_wrapper_transcoding_progress_' . $this->file->fid, 0);
+      }
+      else {
+        // otherwise, normal operations
+        $stderr = stream_get_contents($pipes[2]);
+      }
+      
       fclose($pipes[0]);
-      $this->output = stream_get_contents($pipes[1]);
+
+      $this->output .= stream_get_contents($pipes[1]);
       fclose($pipes[1]);
-      $output = stream_get_contents($pipes[2]);
-      $this->output .= $output;
+      
+      $this->output .= $stderr;
       fclose($pipes[2]);
+
       $command_return = proc_close($process);
     }
 
@@ -327,7 +358,7 @@
   /**
    * Return meta data for this file. Escapes filepath
    *
-   * @param $filepath
+   * @param $file
    *   String, path to file
    * @return $file
    *   Array, contains meta data
@@ -465,10 +496,24 @@
       $this->command("-i \"$path\"");
       $output = $this->output;
     }
+    
+    return $this->parse_duration($output, $timecode);
+  }
+
 
+  /**
+   * Parses file duration
+   * @param $duration
+   *   String, the duration information in 00:00:00.000 format
+   * @param $timecode
+   *   Boolean, return time format or unix time
+   * @return $time
+   *   String, unix time or timecode
+   */  
+  function parse_duration($duration, $timecode) {
     // Parse the output looking for "Duration: 00:02:12"
     $pattern = "/Duration: ([0-9]+:[0-9]+:[0-9]+)\.[0-9]+/";
-    preg_match($pattern, $output, $matches);
+    preg_match($pattern, $duration, $matches);
     if (! $time = $matches[1]) {
       return FALSE;
     }
