These patches will add a progress bar to display the transcoding status to the user. This uses Drupal's built-in #ahah progress bar to achieve this and works by parsing ffmpeg's stderr on the fly. Comments/feedback welcome as always.

Comments

Nathan Goulding’s picture

To make it so PHP doesn't exhaust its memory on large files, here's a better while loop:

<?php

        stream_set_blocking($pipes[2], 0);
        while (! feof($pipes[2])) {
          $current = fgets($pipes[2]);
  
          if (empty($current) || $current == $last) {
            continue;
          }
  
          $stderr .= $current;
  
          $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);
          }
          
          $last = $current;
        }
?>
arthurf’s picture

This is super slick. I've made some changes to how you've done this do fix an issue where you transcode the same file more than once, fixed some php warnings, and done some cleanup here and there. Code is committed- test at will!

Nathan Goulding’s picture

Glad you like it. :) The only thing I can see that could be changed would be to remove:

<?php
  $progress['message'] = 'HERE :' . $cache->data;
?>

Which sometimes flashes across the screen briefly before transcoding a file for the first time.

arthurf’s picture

Woops! Debugging code there.

arthurf’s picture

Debugging code removed