composer require php-ffmpeg/php-ffmpeg
使用方法
//截取图片 $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(3)) ->save($rootPath . "public/uploads/" . $fileName);//保存3张图 $ffprobe = FFMpeg\FFProbe::create($configuration);//保存 $duration = $ffprobe->format($video_filePath)->get('duration'); $time = s_to_hs($duration);//获取视频的时长
$watermarkPath = '/mnt/hgfs/www/test/water.png';$absolute = ['x' => 50,'y' => 100];$relative = [ 'position' => 'relative', 'bottom' => 50, 'right' => 50];//传入参数 以及水印地址$video->filters()->watermark($watermarkPath, $absolute);$video->save(new FFMpeg\Format\Video\X264('libfdk_aac'), '/mnt/hgfs/www/test/1080_new.mp4');
$audio = $ffmpeg->open($a1);$waveform = $audio->waveform(640, 120, array('#00FF00'));$waveform->save('wtest.png');//必须保存为 png 格式
// Open your video file$video = $ffmpeg->open( 'music.mp4' );// Set an audio format$audio_format = new FFMpeg\Format\Audio\Mp3();// Extract the audio into a new file as mp3$video->save($audio_format, 'music.mp3');// Set the audio file$audio = $ffmpeg->open( 'music.mp3' );// Create the waveform$waveform = $audio->waveform();$waveform->save( 'test2.png' );
$video = $ffmpeg->open($v1080);$video->filters()->crop(new FFMpeg\Coordinate\Point("t*100", 0, true), new FFMpeg\Coordinate\Dimension(960, 540));$video->save(new FFMpeg\Format\Video\X264('libfdk_aac'), '/mnt/hgfs/www/test/1080_new.mp4');
$audio = $ffmpeg->open($a1);$format = new FFMpeg\Format\Audio\Flac();$format->on('progress', function ($audio, $format, $percentage) { echo "$percentage % 进度";});$format->setAudioChannels(2)->setAudioKiloBitrate(256);$audio->save($format, 'a1.flac');
$video = $ffmpeg->open($v1080);$video->gif(FFMpeg\Coordinate\TimeCode::fromSeconds(10), new FFMpeg\Coordinate\Dimension(400, 200), 3)->save('1080.gif
$ffprobe = FFMpeg\FFProbe::create($path); //视频 $videoInfo = $ffprobe->format($v1080); //音频 $audioInfo = $ffprobe->format($a1); //也可以使用 get 获取特定值,第二个参数为默认值(若该参数不存在将返回此默认值) $duration = $ffprobe->format($v1080)->get('duration',100); echo ""; print_r($videoInfo); print_r($audioInfo);echo ""; echo '视频时长:'.$duration;