2

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
    Turn [debug mode](https://laravel.com/docs/7.x/errors) on, you should then have access to a stack trace with helpful errors. – Chris Haas Jun 08 '20 at 11:50
  • 1
    Tip: move long-running processes to a `Job`, which allows you to quickly return a response to the user, and than start processing the code. You may also try to run the above code in a tinker session `php artisan tinker` with an already uploaded file and check for errors. – Maarten Veerman Jun 08 '20 at 15:31

1 Answers1

0

Here's the proper way to do it:

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

$video->save($format, '/path/to/new/file');
Mehul V.
  • 620
  • 3
  • 13