ffmpeg是一款开源、跨平台的视频处理程序,可用在Windows、mac、linux等平台,可以方便的运用多种语言脚本来调用其执行视频的操作。
下面介绍使用ffmpeg获取视频首帧的方法。
&1";
//调用php的exec方法去执行脚本
exec($shell, $output, $return_val);
//获取输出信息
print_r($output);
FFmpeg获得视频文件的缩略图
function getVideoCover($file,$time,$name) {
if(empty($time))$time = '1';//默认截取第一秒第一帧
$strlen = strlen($file);
//exec("ffmpeg -i ".$file." -y -f mjpeg -ss ".$time." -t 0.001 -s 320x240 ".$name."",$out,$status);
$str = "ffmpeg -i ".$file." -y -f mjpeg -ss 3 -t ".$time." -s 320x240 ".$name;
$result = system($str);
}
Fmpeg读取视频信息
&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)) {