Centos8安装ffmpeg PHP获取视频封面第一帧 获取视频时长
1、需先下载安装yasm
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
解压
tar -xvf yasm-1.3.0.tar.gz
安装
cd yasm-1.3.0/
./configure && make && make install
2、下载ffmpeg
wget http://www.ffmpeg.org/releases/ffmpeg-4.1.6.tar.gz
解压
tar -xvf ffmpeg-4.1.6.tar.gz
安装
cd ffmpeg-4.1.6/
./configure && make && make install
3、查看版本号
ffmpeg -version
4、获取视频时长 视频第一帖封面
/** * 获取视频时长 * @param type $file * @return type */ private function getTime($file) { $vtime = exec("ffmpeg -i " . $file . " 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"); //总长度 $duration = explode(":", $vtime); // $duration_in_seconds = $duration[0] * 3600 + $duration[1] * 60 + floor($duration[2]); // 视频时长 秒 $duration_in_seconds = $duration[1] * 60 . ':' . floor($duration[2]); // 视频时长 秒 return $duration_in_seconds; } /** * 获取视频第一帖为封面图片 * @param type $file * @param string $time * @param type $filename * @return type */ private function getCover($file, $time = 1, $filename = '') { if (empty($time)) $time = '1'; //默认截取第一秒第一帧 if (empty($filename)) { $videoCover = substr($file, 0, strrpos($file, ".")); $file_len = strlen($videoCover); $videoCover = substr($videoCover, strrpos($videoCover, "/"), $file_len); $videoCoverName = ltrim($videoCover, '/') . '.jpg'; //缩略图命名 } else { $videoCoverName = $filename . '.jpg'; //缩略图命名 } $file_img = '/www/wwwroot/www.mousdw.com/public/uploads/video_img/' . $videoCoverName; $str = "ffmpeg -i " . $file . " -y -f mjpeg -ss 3 -t " . $time . " -s 320x240 " . $file_img; $result = system($str); return '/uploads/video_img/' . $videoCoverName; }