| | 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 | |