PHP使用FFmpeg获取视频播放总时长与码率等信息
请注意:这篇文章中会用到passthru,可能部分虚拟主机会将此命令禁用。
代码如下:
PHP
<?php define('FFMPEG_PATH', '/usr/local/ffmpeg2/bin/ffmpeg -i "%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: (.*?), start: (.*?), bitrate: (d*) kb/s/", $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: (.*?), (.*?), (.*?)[,s]/", $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的时候能有所帮助。如果有疑问大家可以留言交流。
PHP将URL转换成短网址的算法分享
前言短网址服务,可能很多朋友都已经不再陌生,现在大部分微博、手机邮件提醒等地方已经有很多应用模式了,并占据了一定的市场。估计很多朋友
利用PHP将图片转换成base64编码的实现方法
先来说一下为什么我们要对图片base64编码base64是当前网络上最为常见的传输8Bit字节代码的编码方式其中之一。base64主要不是加密,它主要的用途是把某
微信支付PHP SDK —— 公众号支付代码详解
在微信支付开发者文档页面下载最新的phpSDKhttp://mch.weixin.qq.com/wiki/doc/api/jsapi.phpchapter=11_1这里假设你已经申请完微信支付1.微信后台配置如图我们先进行
编辑:广州鸿名健康科技有限公司
标签:代码,这篇文章,转换成,播放时间,音频