2

I am trying to convert my video using FFmpeg, but I'm getting an error message saying that the encoding failed. I'm not sure if the way I coded it might be wrong. I will just like someone to take a look at my code to see if I might have done something wrong. Here is my code

    $viddy=new Video;


        if($request->video){
            $my_video = $request->file('video');
          $video_name = uniqid().$my_video->getClientOriginalName();

     $ffmpeg = FFMpeg\FFMpeg::create([
    'ffmpeg.binaries'  => "C:/Users/jayjay/Desktop/ffmpeg/ffmpeg/bin/ffmpeg.exe",
    'ffprobe.binaries' => "C:/Users/jayjay/Desktop/ffmpeg/ffmpeg/bin/ffprobe.exe"
]);



        $videoName = Storage::disk('s3')->url($video_name);

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


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

                         //Save format to amasonS3
$video->save($format, Storage::disk('s3')->url('newvideo.mp4'));

        //Put the new video format in the database
          $viddy->video = $video;
        }

                $viddy->save();
12
  • Can you share the full and exact error message? Commented Oct 8, 2018 at 16:13
  • @NicoHaase Yes, this is what it says FFMpeg \ Exception \ RuntimeException Encoding failed Commented Oct 8, 2018 at 16:27
  • Possible duplicate of Laravel FFMPEG Error Encoding Failed using Laravel Queue Commented Oct 8, 2018 at 16:51
  • @LuckySaini Not really what I am looking for it kind of looks similar but its not Commented Oct 8, 2018 at 17:32
  • Try changing $format = new FFMpeg\Format\Video\X264(); to $format = new FFMpeg\Format\Video\X264('aac');. I faced a similar issue a few months ago. github.com/pascalbaljetmedia/laravel-ffmpeg/issues/85 Commented Oct 8, 2018 at 22:43

1 Answer 1

2

It looks like you are calling the save() method wrong, which is probably the result of the error. Also, it might make things easier to use the facade with this package when opening the file. Try it like this instead:

$video = FFMpegFacade::fromDisk('s3')->open($folder . '/' . $filename)

...

$video->export()->toDisk('s3')->inFormat($format)->save($folder . '/' . $new_filename);

To save the video in the database is a different story. If you want to save the raw data of the video, you can serialize and base64 encode, etc. But, since you are storing it to disk, it's usually easier to save the path to the video instead:

$viddy->video = $folder . '/' . $new_filename;
$viddy->save();
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I wished of changed my question to trying to resize the video because I am also trying to resize the video instead of the setting the killobitrate and the audio codec but I constantly get unable to probe and I really don't understand why when I'm actually following the example from github.com/pascalbaljetmedia/laravel-ffmpeg
No problem. If my solution worked for your original issue, please mark as correct. If you have a new problem that needs solved, please create a new post separate from this one and I'd be happy to take a look at it. Thanks.
Okay great I'm about to create now Will you be the first to answer? You have such a great help
Sure, just reply with the link here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.