laravel-ffmpeg
laravel-ffmpeg copied to clipboard
Converting Image To Video
I'm trying to convert an image to a video with a specific time.
On using FFMPEG.
ffmpeg -loop 1 -i aa.png -c:v libx264 -t 3 -pix_fmt yuv420p output.mp4
It works fine turning a single image to a 3 second video.
and using laravel-ffmpeg
// $temp_file is aa.png
FFMpeg::fromDisk('temp_media')
->open($temp_file)
->addFilter('-loop', 1)
->addFilter('-c:v', 'libx264')
->addFilter('-t', 3)
->addFilter('-pix_fmt', 'yuv420p')
->export()
->toDisk('temp_media')
->save('output.mp4');
It's converted into mp4 but the video length is only 0 secs. Maybe i'm missing something?
Thanks in advance.
Can you share the command using the dd method?
FFMpeg::fromDisk('temp_media')
->open($temp_file)
->addFilter('-loop', 1)
->addFilter('-c:v', 'libx264')
->addFilter('-t', 3)
->addFilter('-pix_fmt', 'yuv420p')
->export()
->dd('output.mp4');
Same issue here. I think the error depends on the order of the attributes, especially the -i attribute.
If you run this the encoding was fine:
ffmpeg -y -loop 1 -r 25 -t 15 -i datasheet.jpeg -qscale 0 test.mp4
But if you run the exported attributes list from laravel-ffmpeg the encoded file will be 0sec length:
ffmpeg -y -i datasheet.jpeg -loop 1 -r 25 -t 15 -qscale 0 test.mp4
The only difference is the -i parameter was in different place. What do you think @pascalbaljet ?
Thanks!
@pascalbaljet any idea? Same problem.
That's right @kovkor. We can use setInitialParameters on openAdvanced @pascalbaljet :
$ffmpeg = FFMpeg::create();
$video = $ffmpeg->openAdvanced([$file]);
$video->setInitialParameters(['-loop 1', '-r 25', '-t 15']);
dd($video->getFinalCommand());
-y -loop 1 -r 25 -t 15 -i /path/to/image.png
use:
$format = new \FFMpeg\Format\Video\X264;
$format->setInitialParameters([
'-loop', '1',
'-t', $duration_in_seconds,
]);