Encoding failed during converting and saving video using php-ffmpeg in laravel

Viewed 1329

i'm using https://github.com/PHP-FFMpeg/PHP-FFMpeg package to convert user video uploads to mp4 format, note that I'm using Laravel framework for development process.
But I'm facing error for this and Im not really sure what im doing wrong because all it says is that Encoding is failed. I attached the errors image below you can see that at the bottom.

This is my function which handles user uploads:

public function upload()
    {
        $this->putVideoIntoStorage();
        $this->ffmpeg->saveVideo($this->storageManager->getAbsolutePathOf($this->video->getClientOriginalName()));

        return $this->saveVideoIntoDatabase();
    }

This is the function which handles saving and converting video to mp4 using php-ffmpeg

 public function saveVideo(String $path)
    {

        $ffmpeg = FFMpeg::create([
            'ffmpeg.binaries' => config('services.ffmpeg.ffmpeg_path'),
            'ffprobe.binaries' => config('services.ffmpeg.ffprobe_path'),
            'timeout'          => 3600, // The timeout for the underlying process
            'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
        ]);


        $video = $ffmpeg->open($path);

        $video->save(new X264(), 'video.mp4');
    }

This is the error im getting: Errors Image
I can provide more details if you need just ask me, I would be really glad if someone can help me through this.

1 Answers

Here's the proper way to do it:

$format = new FFMpeg\Format\Video\X264();
$format->setAudioCodec("libmp3lame");

$video->save($format, '/path/to/new/file');
Related