1、安装ffmpeg
lnmp:https://blog.csdn.net/weixin_44056947/article/details/119460529
宝塔:https://www.cnblogs.com/mo3408/p/13198975.html
2、composer安装getid3
composer require james-heinrich/getid3
3、使用方法
function getVideoImage($video_url, $width = 200, $height = 200)
{
$date = date("Ymd");
$savePath = "./uploads/video_first_frame/$date/";
if (!file_exists($savePath)) {
mkdir($savePath, 0777, true);
}
$filename = "1.png";
$url = $savePath . $filename;
$shell = "ffmpeg -i " . $video_url . " -y -f mjpeg -ss 3 -t 1 -s ".$width."x".$height." $url";
exec($shell,$result,$status);
if($status){
return false;
}
return $savePath.$filename;
}
$getID3 = new \getID3();
$ThisFileInfo = $getID3->analyze("./heiheihei.mp4");
$result = getVideoImage($ThisFileInfo['filenamepath'],$ThisFileInfo['video']['resolution_x'],$ThisFileInfo['video']['resolution_y']);