<?php // 定义 FFmpeg的路径,最好在网站的全局配置文件里定义好 // 另外,重定向符号在FreeBSD等csh系统中为 >& define('KC_FFMPEG_PATH', '/usr/local/ffmpeg/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
php学习读取视频文件来获取视频属性的信息
最新推荐文章于 2024-08-26 08:48:02 发布