I am new to Laravel 4. I have installed php-ffmpeg
in my local Laravel setup, but I need help on how to use this ffmpeg with Laravel 4?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Assuming that you already have ffmpeg
installed on your localhost server, then in Laravel, you need to set the paths for the ffmpeg and ffprobe binaries, like so:
$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => '/usr/local/Cellar/ffmpeg/2.1.3/bin/ffmpeg',
'ffprobe.binaries' => '/usr/local/Cellar/ffmpeg/2.1.3/bin/ffprobe',
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
));
By doing so, then you can:
// set the path of the video file, which you might consider to get the input from the user
$video = $ffmpeg->open('video.mpg');
// apply filters to resize the clip
$video
->filters()
->resize(new FFMpeg\Coordinate\Dimension(320, 240))
->synchronize();
// crop a frame from a particular timecode
$video
->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
->save('frame.jpg');
// transcode clip
$video
->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4');
There are more examples provided in the PHP-FFMpeg documentation on github