Changeset a0cef0726e42c457e94830375e2bb939b655bb0d

Show
Ignore:
Timestamp:
01/07/12 14:12:16 (5 months ago)
Author:
Xemle <xemle@phtagr.org>
Children:
e449ecc0f26cb90b41ca32d98ed3f37f762c9f5a, 3054f5516c6b2f300b1c91214076b847c7b78c8e
Parents:
0d83b9697a3d768e1d678f5275640d1aaa435e8d
git-committer:
Xemle <xemle@phtagr.org> / 2012-01-07T14:12:16Z+0100
Message:

Improve importing video parameter extration

Use -n -S argments for exiftool to extract video data
to simplify parameter parsing.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • controllers/components/video_filter.php

    r70778f6 ra0cef07  
    182182    $bin = $this->controller->getOption('bin.exiftool', 'exiftool'); 
    183183    $this->Command->redirectError = true; 
    184     $result = $this->Command->run($bin, array('' => $filename)); 
     184    $result = $this->Command->run($bin, array('-n', '-S', $filename)); 
    185185    $output = $this->Command->output; 
    186186  
     
    192192      return false; 
    193193    } else { 
    194       Logger::trace($output); 
    195  
    196194      foreach ($output as $line) { 
    197         $words = preg_split("/\s+/", trim($line)); 
    198         if ($words[0] == "Duration") { 
    199           if ($words[3] == "s") { 
    200             $time = preg_split("/\./", $words[2]); 
    201             $data['duration'] = $time[0]; 
    202             Logger::trace("Extract duration of '$filename': $time[0]"); 
    203           } 
    204           else { 
    205             $times = preg_split("/:/", $words[2]); 
    206             $time = $times[0] * 3600 + $times[1] * 60 + intval($times[2]); 
    207             $data['duration'] = $time; 
    208             Logger::trace("Extract duration of '$filename': $time"); 
    209           } 
    210         } elseif ($words[0] == "Image" && $words[1] == "Width") { 
    211           $data['width'] = $words[3]; 
    212           Logger::trace("Extract video size of '$filename': $words[3]"); 
    213         } elseif ($words[0] == "Image" && $words[1] == "Height") { 
    214           $data['height'] = $words[3]; 
    215           Logger::trace("Extract video size of '$filename': $words[3]"); 
     195        if (!preg_match('/^(\w+): (.*)$/', $line, $m)) { 
     196          Logger::warn('Could not parse line: '.$line); 
     197          continue; 
    216198        } 
     199        if ($m[1] == 'ImageWidth') { 
     200          $data['width'] = intval($m[2]); 
     201          Logger::trace("Extract video width of '$filename': ".$data['width']); 
     202        } else if ($m[1] == 'ImageHeight') { 
     203          $data['height'] = intval($m[2]); 
     204          Logger::trace("Extract video height of '$filename': ".$data['height']); 
     205        } else if ($m[1] == 'Duration') { 
     206          $data['duration'] = ceil(intval($m[2])); 
     207          Logger::trace("Extract duration of '$filename': ".$data['duration']."s"); 
     208        } 
     209      }  
     210      if (!$data['width'] || !$data['height'] || !$data['duration']) { 
     211        Logger::warn("Could not extract width, height, or durration from '$filename'. Width is {$data['width']}, height is {$data['height']}, duration is {$data['duration']}"); 
    217212      } 
    218213    } 
     
    245240          Logger::trace("Extract duration of '$filename': $time"); 
    246241        } elseif (count($words) >= 6 && $words[2] == "Video:") { 
    247           $words = preg_split("/,+/", trim($line)); 
    248           $data = preg_split("/\s+/", trim($words[2])); 
     242          $words = preg_split("/,+/", trim($line)); 
     243          $data = preg_split("/\s+/", trim($words[2])); 
    249244          list($width, $height) = split("x", trim($data[0])); 
    250245          $data['width'] = $width;