How we can convert Image to Video Conversion in Laravel using FFMpeg?

I am trying to transfer an image into a video using FFMpeg in Laravel and it generates the video with 0 seconds duration, and also, converted the image into mp4 format and stored it at my given location but the video length is 0 seconds.

You can use the PHP FFMpeg library to convert an image to a video. Here are the general steps you can follow:

  • First, you need to install the PHP FFMpeg library try the below-given command in your terminal:

    composer require php-ffmpeg/php-ffmpeg

  • Now, create an instance of the FFMpeg class in your Laravel controller, and add the path to your image file:

    use FFMpeg\\FFMpeg;
    $ffmpeg = FFMpeg::create();
    $image = $ffmpeg->open('path/to/image.jpg');
  • Save the FFMpeg class to convert the image to a video using the same keyword. For example, use the below command if you want to create a video in MP4 format.

    $video = $image->save(new \\FFMpeg\\Format\\Video\\X264(), 'path/to/output.mp4');

Otherwise, you can use this simple method to convert images into video.

Not only this you can also add audio to the video. For example

$audio = $ffmpeg->open('path/to/audio.mp3');
$video = $image->addAudio($audio)->save(new \\FFMpeg\\Format\\Video\\X264(), 'path/to/output.mp4');

Wow! that’s great, let me try this once.

Hi ,
Yes, it is. But, note you need to adjust the parameters of the save method depending on your requirements.

For more please go through the documentation for further details, and find out the solution if you face any issues GitHub - PHP-FFMpeg/PHP-FFMpeg: An object oriented PHP driver for FFMpeg binary

For more please go through the documentation for further details.