PHP中使用FFMPEG获取视频缩略图和视频总时长实例
代码如下:
//获得视频文件的缩略图 function getVideoCover($file,$time,$name) { if(empty($time))$time = '1';//默认截取第一秒第一帧 $strlen = strlen($file); // $videoCover = substr($file,0,$strlen-4); // $videoCoverName = $videoCover.'.jpg';//缩略图命名 //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; //echo $str."</br>"; $result = system($str); } //获得视频文件的总长度时间和创建时间 function getTime($file){ $vtime = exec("ffmpeg -i ".$file." 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");//总长度 $ctime = date("Y-m-d H:i:s",filectime($file));//创建时间 //$duration = explode(":",$time); // $duration_in_seconds = $duration[0]*3600 + $duration[1]*60+ round($duration[2]);//转化为秒 return array('vtime'=>$vtime, 'ctime'=>$ctime ); }
相关推荐
cherayliu 2019-12-22
dingwun 2020-11-16
wangdaren 2020-08-15
wqiaofujiang 2020-07-05
PGzxc 2020-07-04
ShoppingChen 2020-06-25
cherayliu 2020-06-17
83096129 2020-06-08
83096129 2020-06-08
PGzxc 2020-06-01
ShoppingChen 2020-05-29
cherayliu 2020-05-11
ShoppingChen 2020-05-11
83096129 2020-05-10
PGzxc 2020-05-07
cherayliu 2020-04-27