Extract f4v,flv timecode recorded using Flash Media Live Enconder FMLE
#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
<?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;
}
ffprobe -i /tmp/TESTE.f4v -select_streams 2 -show_packets -sexagesimal -show_data -v quiet -print_format json