php如何获取mp4视频的封面图片

1.服务器上先安装FFmpeg

FFmpeg安装教程:https://www.zhiboblog.com/2007.html

2.在php中使用FFmpeg截取视频封面图片(使用注意:如果php禁用了shell_exec函数,需要在php.ini中搜索"disable_functions"找到shell_exec后取消禁用)

function getVideoCover( $input, $output ) {
   $command = "ffmpeg -v 0 -y -i $input -vframes 1 -ss 5 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 $output ";
   shell_exec( $command );
}
//使用方法(第一个参数是视频的路径,第二个参数是生成图片的路径)
getVideoCover('./test.mp4','./test.jpg');

以上就是php获取mp4视频的封面图片的方法。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: