1、安装PHP-FFMpeg扩展
composer require php-ffmpeg/php-ffmpeg
2、use的引用
use FFMpeg\FFMpeg;
use FFMpeg\Coordinate\TimeCode;
3、获取视频的基本信息
//1.获取ffmpeg实例
$ffmpeg = FFMpeg::create(array(
'ffmpeg.binaries' => '/usr/bin/ffmpeg',//安装的ffmpeg服务绝对地址
'ffprobe.binaries' => '/usr/bin/ffprobe',//安装的ffprobe服务绝对地址
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
));
//打开视频文件
$video = $ffmpeg->open('/path/to/file');
//视频的视频信息
$video_info = $video->getStreams()->videos()->first()->all();
//单独获取某一个
$profile = $video->getStreams()->videos()->first()->get('profile');
//获取视频尺寸有单独的方法
$dimensions=$video->getStreams()->videos()->first()->getDimensions();
//视频的音频信息
$audio_info_rate = $video->getStreams()->audios()->first()->all();
//单独获取某一个
$sample_rate = $video->getStreams()->audios()->first()->get('sample_rate');
4、截取视频的其中图片
//视频的路径
$path = public_path().'/进击的巨人燃剪.mp4';
//打开视频文件
$video = $ffmpeg->open($path);
//第几秒
$fromSecond = 33;
$frame = $video->frame(TimeCode::fromSeconds($fromSecond)); //提取第几秒的图像
//图片名称
$fileName = 'video/' . mt_rand() . '.jpg';
if (!is_dir(storage_path("video"))) {
mkdir(storage_path("video"), 0777);
}
//写入文件
$frame->save(storage_path($fileName));
return $fileName;
参考链接:https://blog.csdn.net/heart24kking/article/details/101426972