Changeset 70778f6755681e6f78d83e14d9b4ac1fdf45f152

Show
Ignore:
Timestamp:
01/07/12 04:04:19 (5 months ago)
Author:
Josef Wells <josef.wells@alumni.utexas.net>
Children:
0d83b9697a3d768e1d678f5275640d1aaa435e8d
Parents:
dc8b5689fca5fece234bf0b2b41d04db5ae4634c
git-committer:
Josef Wells <josef.wells@alumni.utexas.net> / 2012-01-06T21:04:19Z-0600
Message:

added ffmpeg back as fallback video info tool

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • controllers/components/video_filter.php

    rdc8b568 r70778f6  
    3636 
    3737  function _getVideoExtensions() { 
    38     if ($this->controller->getOption('bin.ffmpeg')) { 
     38    if ($this->controller->getOption('bin.exiftool') || $this->controller->getOption('bin.ffmpeg')) { 
    3939      return array('avi', 'mov', 'mpeg', 'mpg', 'mts', 'mp4', 'flv'); 
    4040    } else { 
     
    148148    if ($this->controller->getOption('bin.exiftool')) { 
    149149      $media = $this->_readExiftool(&$media, $filename); 
     150    } elseif ($this->controller->getOption('bin.ffmpeg')) { 
     151      $media = $this->_readFfmpeg(&$media, $filename); 
    150152    } else { 
    151153      $media = $this->_readGetId3(&$media, $filename); 
     
    218220  } 
    219221 
     222  function _readFfmpeg(&$media, $filename) { 
     223    $data =& $media['Media']; 
     224 
     225    $bin = $this->controller->getOption('bin.ffmpeg', 'ffmpeg'); 
     226    $this->Command->redirectError = true; 
     227    $result = $this->Command->run($bin, array('-i' => $filename, '-t', 0.0)); 
     228    $output = $this->Command->output; 
     229  
     230    if ($result != 1) { 
     231      Logger::err("Command '$bin' returned unexcpected $result"); 
     232      return false; 
     233    } elseif (!count($output)) { 
     234      Logger::err("Command returned no output!"); 
     235      return false; 
     236    } else { 
     237      Logger::trace($output); 
     238 
     239      foreach ($output as $line) { 
     240        $words = preg_split("/[\s,]+/", trim($line)); 
     241        if (count($words) >= 2 && $words[0] == "Duration:") { 
     242          $times = preg_split("/:/", $words[1]); 
     243          $time = $times[0] * 3600 + $times[1] * 60 + intval($times[2]); 
     244          $data['duration'] = $time; 
     245          Logger::trace("Extract duration of '$filename': $time"); 
     246        } elseif (count($words) >= 6 && $words[2] == "Video:") { 
     247          $words = preg_split("/,+/", trim($line)); 
     248          $data = preg_split("/\s+/", trim($words[2])); 
     249          list($width, $height) = split("x", trim($data[0])); 
     250          $data['width'] = $width; 
     251          $data['height'] = $height; 
     252          Logger::trace("Extract video size of '$filename': $width x $height"); 
     253        } 
     254      } 
     255    } 
     256    return $media; 
     257  } 
     258 
    220259  function _readGetId3(&$media, $filename) { 
    221260    App::import('vendor', 'getid3/getid3');