#!/usr/local/sbin/php -q . *! -----------------------------------------------------------------------------** *! $Log: split_mov.php,v $ *! */ $chunksize=10000000; // 10MB $startMarkerWithExif=chr(hexdec("ff")).chr(hexdec("d8")).chr(hexdec("ff")).chr(hexdec("e1")); echo "
\n";
// if (!isset($_GET['path']) || !isset($_GET['ext'])) {
// echo "Usage split_mov.php?path=<path_of_the_mov_file>&ext=<extension>";
// //echo "Usage split_mov.php?path=path_of_the_mov_file&ext=extension";
// echo "\n";
// exit (1);
// }
if (isset($_GET['path'])) $path_with_name=$_GET['path'];
else if (isset($argv[1])) $path_with_name=$argv[1];
else die("-1");
if (isset($_GET['ext'])) $extension=$_GET['ext'];
else if (isset($argv[2])) $extension=$argv[2];
else die("-2");
echo "Splitting $path_with_name into {$extension}s\n";
$last_slash_position = strrpos($path_with_name,"/");
if (!$last_slash_position) {
$path = "";
$mov_file = $path_with_name;
}else{
$path = substr($path_with_name,0,$last_slash_position+1);
$mov_file = substr($path_with_name,$last_slash_position+1);
}
split_mov($path,$mov_file,$extension,$startMarkerWithExif,$chunksize);
function split_mov($path,$mov_file,$ext,$startMarkerWithExif,$chunksize) {
$path_with_name = $path.$mov_file;
if (!is_file($path_with_name)) {
return -1;
}
$file=fopen($path_with_name,'r');
$markers=array(0);
$offset=0;
while (!feof($file)) {
fseek($file,$offset);
$s = fread($file,$chunksize);
$index=0;
while (true) {
$pos=strpos($s,$startMarkerWithExif,$pos);
if ($pos === false) break;
$markers[count($markers)]=$offset+$pos;
$pos++;
}
$offset+=(strlen($s)-strlen($startMarkerWithExif)+1); // so each marker will appear once
}
$markers[count($markers)]=$offset+strlen($s); // full length of the file
for ($i=1;$i<(count($markers)-1);$i++) {
fseek($file,$markers[$i]);
$s = fread($file,$markers[$i+1]-$markers[$i]);
$old_file_name= $path."tmp.".$ext;
$outFile=fopen($old_file_name,'w');
fwrite($outFile,$s);
fclose($outFile);
//read exif & rename
$exif_data = exif_read_data($old_file_name);
//converting GMT a local time GMT+7
$DateTimeOriginal_local=strtotime($exif_data['DateTimeOriginal']);/*-25200;*/
$new_file_name = $path.$DateTimeOriginal_local."_".$exif_data['SubSecTimeOriginal'].".".$ext;
rename($old_file_name,$new_file_name);
}
return 0;
}
?>