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

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.