Skip to content

Instantly share code, notes, and snippets.

@ha1t
Created December 20, 2011 16:05
Show Gist options
  • Save ha1t/1502090 to your computer and use it in GitHub Desktop.
Save ha1t/1502090 to your computer and use it in GitHub Desktop.
TSの先頭80秒のstreamパターン変化を読み取り、変化があった時間を返す
<?php
/**
* streamの変化を調べる
* @url http://zion009.blog98.fc2.com/blog-entry-36.html
*/
$src = $argv[1];
$temp_file = '/tmp/tmp.mp4';
$temp_text = '/tmp/tmp.text';
$cmd = "ffmpeg -i {$src} -y -v verbose -t 80 -s 128x96 {$temp_file} 2> {$temp_text}";
exec($cmd);
function get_offset($temp_text)
{
$is_capture = false;
$result = array();
foreach (file($temp_text) as $line) {
if (strpos($line, 'frame changed from') !== false) {
$is_capture = true;
}
if ($is_capture === true) {
$result[] = $line;
$regex_result = preg_match('_time=00:(\d\d:\d\d.\d\d)_', $line, $matches);
//if (strpos($line, 'time') !== false) {
if ($regex_result) {
$parts = explode(':', $matches[1]);
$offset = ($parts[0] * 60) + ceil($parts[1]) + 1;
return (int)$offset;
}
}
}
return 0;
}
echo get_offset($temp_text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment