While i try to get length of a flv video file i get 0 second where as it only happens with some videos, else my function works fine.
below is my code.
<?php
function mbmGetFLVDuration($file){
// read file
if (file_exists($file)){
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));
fclose($handle);
//
if (strlen($contents) > 3){
if (substr($contents,0,3) == "FLV"){
$taglen = hexdec(bin2hex(substr($contents,strlen($contents)-3)));
if (strlen($contents) > $taglen){
$duration = hexdec(bin2hex(substr($contents,strlen($contents)-$taglen,3))) ;
return $duration;
}
}
}
}
}
// not working video file
$result = ceil(mbmGetFLVDuration('not_working_copy.flv')/1000);
// working video file
//$result = ceil(mbmGetFLVDuration('working_copy.flv')/1000);
echo date('H:i:s',mktime(0,0,$result))
?>
i have attached both working and not working flv video in link below:
working video: http://blog.developeronhire.com/wp-content/uploads/downloads/2011/06/working_copy.flv
not working video: http://blog.developeronhire.com/wp-content/uploads/downloads/2011/06/not_working_copy.flv
any idea will be appreciated.
Thank you