Created
December 2, 2015 13:46
-
-
Save hebertreis/ae9f590d72058a159606 to your computer and use it in GitHub Desktop.
Extract f4v,flv timecode recorded using Flash Media Live Enconder FMLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#open terminal in your mac our linux | |
php extractTimeCode.php /tmp/TESTE.f4v | |
# output | |
#Running: ffprobe -i /tmp/TESTE.f4v -select_streams 2 -show_packets -sexagesimal -show_data -v quiet -print_format json | |
#total=12 | |
#Seconds 0 => 2015-11-24 11:07:20 | |
#Seconds 0.513 => 2015-11-24 11:07:20 | |
#Seconds 1.015 => 2015-11-24 11:07:21 | |
#Seconds 1.515 => 2015-11-24 11:07:21 | |
#Seconds 2.016 => 2015-11-24 11:07:22 | |
#Seconds 2.516 => 2015-11-24 11:07:22 | |
#Seconds 3.016 => 2015-11-24 11:07:23 | |
#Seconds 3.517 => 2015-11-24 11:07:23 | |
#Seconds 4.017 => 2015-11-24 11:07:24 | |
#Seconds 4.517 => 2015-11-24 11:07:24 | |
#Seconds 5.019 => 2015-11-24 11:07:25 | |
#Seconds 5.52 => 2015-11-24 11:07:25 | |
#Seconds 6.02 => 2015-11-24 11:07:26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('UTC'); | |
if(isset($argv[1])){ | |
$input = $argv[1]; | |
}else{ | |
die('missing argument filename'.PHP_EOL); | |
} | |
if(strpos($input, 'http') === false and strpos($input, 'rtmp') === false and strpos($input, 'https') === false){ | |
if(!file_exists($input)){ | |
die('file not found'.PHP_EOL); | |
} | |
} | |
$ffmpeg_cmd = "ffprobe -i $input -select_streams 2 -show_packets -sexagesimal -show_data -v quiet -print_format json"; | |
echo "Running: ".$ffmpeg_cmd.PHP_EOL; | |
exec($ffmpeg_cmd,$packets); | |
$packets = json_decode(implode($packets)); | |
if(!property_exists($packets,'packets')){ | |
die('Erro, check ffmpeg or ffprobe command!'); | |
} | |
echo "total=".count($packets->packets).PHP_EOL; | |
foreach($packets->packets as $packet){ | |
echo 'Seconds '.$packet->pts/1000; | |
echo ' => '; | |
$data = $packet->data; | |
$data = exec('echo "' .$data.'" | xxd -r'); | |
$data = trim(preg_replace('/\s+/', ' ',$data)); | |
$data = str_replace('st','',$data); | |
$data = substr($data,0,23); | |
$data = preg_replace('/[^A-Za-z0-9\-\:\s]/', '', $data); | |
$data = date_create_from_format('d-m-Y H:i:s',$data); | |
$data = $data->format('Y-m-d H:i:s'); | |
echo $data; | |
echo PHP_EOL; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffprobe -i /tmp/TESTE.f4v -select_streams 2 -show_packets -sexagesimal -show_data -v quiet -print_format json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment