相关疑难解决方法(0)

如何在PHP中获取视频持续时间,维度和大小?

我想知道如何在PHP中获取上传的视频文件的持续时间,尺寸和大小.该文件可以是任何视频格式.

php video duration ffmpeg

41
推荐指数
3
解决办法
10万
查看次数

得到flv视频长度

虽然我试图得到一个flv视频文件的长度我得到0秒,因为它只发生在一些视频,否则我的功能工作正常.

下面是我的代码.

<?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))
?>
Run Code Online (Sandbox Code Playgroud)

我在下面的链接中附加了工作和不工作的flv视频:

工作视频:http: //blog.developeronhire.com/wp-content/uploads/downloads/2011/06/working_copy.flv

不工作的视频:http: //blog.developeronhire.com/wp-content/uploads/downloads/2011/06/not_working_copy.flv

任何想法将不胜感激.

谢谢

php video flv

5
推荐指数
1
解决办法
5556
查看次数

标签 统计

php ×2

video ×2

duration ×1

ffmpeg ×1

flv ×1