php 检测h.264编码,php+ffmpeg判断视频编码格式是否h264?

&

define('KC_FFMPEG_PATH', '/usr/local/bin/ffmpeg -i "%s" 2>&1');

function video_info($file) {

ob_start();

passthru(sprintf(KC_FFMPEG_PATH, $file));

$info = ob_get_contents();

ob_end_clean();

// 通过使用输出缓冲,获取到ffmpeg所有输出的内容。

$ret = array();

// Duration: 01:24:12.73, start: 0.000000, bitrate: 456 kb/s

if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) {

$ret['duration'] = $match[1]; // 提取出播放时间

$da = explode(':', $match[1]);

$ret['seconds'] = $da[0] * 3600 + $da[1] * 60 + $da[2]; // 转换为秒

$ret['start'] = $match[2]; // 开始时间

$ret['bitrate'] = $match[3]; // bitrate 码率 单位 kb

}

// Stream #0.1: Video: rv40, yuv420p, 512x384, 355 kb/s, 12.05 fps, 12 tbr, 1k tbn, 12 tbc

if (preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $info, $match)) {

$ret['vcodec'] = $match[1]; // 编码格式

$ret['vformat'] = $match[2]; // 视频格式

$ret['resolution'] = $match[3]; // 分辨率

$a = explode('x', $match[3]);

$ret['width'] = $a[0];

$ret['height'] = $a[1];

}

// Stream #0.0: Audio: cook, 44100 Hz, stereo, s16, 96 kb/s

if (preg_match("/Audio: (\w*), (\d*) Hz/", $info, $match)) {

$ret['acodec'] = $match[1]; // 音频编码

$ret['asamplerate'] = $match[2]; // 音频采样频率

}

if (isset($ret['seconds']) && isset($ret['start'])) {

$ret['play_time'] = $ret['seconds'] + $ret['start']; // 实际播放时间

}

$ret['size'] = filesize($file); // 文件大小

return array($ret, $info);

}

// 调用方法:

print_r(video_info('/home/www/wwwroot/hhwx/public/uploadfiles/media_file/20180920/201809201112302548_h264.mp4'));

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值