laravel-ffmpeg icon indicating copy to clipboard operation
laravel-ffmpeg copied to clipboard

Converting Image To Video

Open primoashbee opened this issue 4 years ago • 5 comments

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.

primoashbee avatar Oct 11 '21 01:10 primoashbee

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');

pascalbaljet avatar Oct 26 '21 20:10 pascalbaljet

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!

kovkor avatar Nov 05 '21 09:11 kovkor

@pascalbaljet any idea? Same problem.

cortier avatar Jun 06 '22 21:06 cortier

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

Kristories avatar Jul 23 '22 18:07 Kristories

use:

$format = new \FFMpeg\Format\Video\X264;

$format->setInitialParameters([
    '-loop', '1',
    '-t', $duration_in_seconds,
]);
        

irakan avatar Jul 18 '23 12:07 irakan