获取 flv 视频长度 [英] get flv video length

查看:30
本文介绍了获取 flv 视频长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试获取 flv 视频文件的长度时,我得到 0 秒,因为它只发生在某些视频中,否则我的功能工作正常.

下面是我的代码.

 3){if (substr($contents,0,3) == "FLV"){$taglen = hexdec(bin2hex(substr($contents,strlen($contents)-3)));如果 (strlen($contents) > $taglen){$duration = hexdec(bin2hex(substr($contents,strlen($contents)-$taglen,3)));返回 $duration;}}}}}//不工作的视频文件$result = ceil(mbmGetFLVDuration('not_working_copy.flv')/1000);//工作视频文件//$result = ceil(mbmGetFLVDuration('working_copy.flv')/1000);echo date('H:i:s',mktime(0,0,$result))?>

我在下面的链接中附上了工作和不工作的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

任何想法将不胜感激.

谢谢

解决方案

当视频的元信息部分或完全损坏时,会出现此类问题.为了解决这个问题,请使用FFMPEG commnad line工具,在上传时修复此类损坏的文件.下面是使用 FFMPEG 提取视频持续时间的代码片段.

');打印_r($matches[1][0]);print_r($full);?>

要下载 FFMPEG,请访问 http://www.ffmpeg.org

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

解决方案

This type of problem occurs when the meta information of a video is partially or fully corrputed. In order to resolve this problem, use FFMPEG commnad line tool, to repair such corrupted file while uploading. below is a code snippet that extracts the video duration using 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);
?>

to download FFMPEG go to http://www.ffmpeg.org

这篇关于获取 flv 视频长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆