Skip to content

Instantly share code, notes, and snippets.

@hebertreis
Created December 2, 2015 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hebertreis/ae9f590d72058a159606 to your computer and use it in GitHub Desktop.
Save hebertreis/ae9f590d72058a159606 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment