Get the length of a video in FLV format

While I try to get the file length of the FLV video, I get 0 second when this happens only with some videos, otherwise 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 connected both working and non-working FLV video in the link below:

working video: http://blog.developeronhire.com/wp-content/uploads/downloads/2011/06/working_copy.flv

the video does not work: http://blog.developeronhire.com/wp-content/uploads/downloads/2011/06/not_working_copy.flv

Any idea would be appreciated.

thank

+5
source share
3 answers

, . , commf-line FFMPEG, . - , FFMPEG.

<?php
     ob_start();
     passthru("ffmpeg -i working_copy.flv  2>&1");
     $duration = ob_get_contents();
     $full = ob_get_contents();
     ob_end_clean();
     $search = "/duration.*?([0-9]{1,})/";
     print_r($duration);
     $duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
     print_r('<pre>');
 print_r($matches[1][0]);
 print_r($full);
?>

FFMPEG http://www.ffmpeg.org

+7

, , , FLV PHP memory_limit

$contents = fread($handle, filesize($file));

.

, . flvmeta :

$ flvmeta --check not_working_copy.flv
0x00488473: error E30013: unknown tag type 250
0x00488477: error E40023: timestamps are decreasing from 130543 to 0
2 error(s), 0 warning(s)

, , MediaInfo, , , ffmpeg.

PHP, , :

$ MediaInfo --Inform="Video;%Duration%" not_working_copy.flv
130000

.

+1

You can extract the metadata of the FLV video, you will find all the information, such as length, size, etc. See Link http://code.google.com/p/flv4php/ Good luck sujeet

0
source

All Articles