幽灵资源网 Design By www.bzswh.com

请注意:这篇文章中会用到passthru,可能部分虚拟主机会将此命令禁用。

代码如下:

PHP

<"%s" 2>&1');
 
function getVideoInfo($file) {
  
  $command = sprintf(FFMPEG_PATH, $file);
  
  ob_start();
  passthru($command);
  $info = ob_get_contents();
  ob_end_clean();
  
  $data = array();
  if (preg_match("/Duration: (.*", $info, $match)) {
    $data['duration'] = $match[1]; //播放时间
    $arr_duration = explode(':', $match[1]);
    $data['seconds'] = $arr_duration[0] * 3600 + $arr_duration[1] * 60 + $arr_duration[2]; //转换播放时间为秒数
    $data['start'] = $match[2]; //开始时间
    $data['bitrate'] = $match[3]; //码率(kb)
  }
  if (preg_match("/Video: (.*", $info, $match)) {
    $data['vcodec'] = $match[1]; //视频编码格式
    $data['vformat'] = $match[2]; //视频格式
    $data['resolution'] = $match[3]; //视频分辨率
    $arr_resolution = explode('x', $match[3]);
    $data['width'] = $arr_resolution[0];
    $data['height'] = $arr_resolution[1];
  }
  if (preg_match("/Audio: (\w*), (\d*) Hz/", $info, $match)) {
    $data['acodec'] = $match[1]; //音频编码
    $data['asamplerate'] = $match[2]; //音频采样频率
  }
  if (isset($data['seconds']) && isset($data['start'])) {
    $data['play_time'] = $data['seconds'] + $data['start']; //实际播放时间
  }
  $data['size'] = filesize($file); //文件大小
  return $data;
}
 
//用法
$video_info = getVideoInfo('video.mp4');
print_r($video_info);
?>

总结

以上就是这篇文章的全部内容,希望对大家学习或使用PHP的时候能有所帮助。如果有疑问大家可以留言交流。

标签:
ffmpeg,获取视频码率,php,ffmpeg使用,ffmpeg,视频时间

幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com