JayJay123
JayJay123

Reputation: 77

Why is ffmpeg processing time so slow?

I am using ffmpeg to convert and compress videos. When I upload my video file it takes a long time to process. The video can be 1.2mb or even 5.8mb or even 10mb and its still slow, I am just there staring at the screen waiting for 20 minutes or even more. What can I do to speed up the process? If you need me to provide you with my code here it is

    $viddy=new Video;   
  $file = $request->file('file');   
 $fileName =uniqid().$file->getClientOriginalName();

 $request->file->move(public_path('/app'), $fileName);
            $name_file=uniqid().'video.mp4';
         $ffp=FFMpeg::fromDisk('local')
         ->open($fileName)
    ->addFilter(function ($filters) {
        $filters->resize(new \FFMpeg\Coordinate\Dimension(640, 480));
    })
    ->export()
    ->toDisk('s3')
    ->inFormat(new \FFMpeg\Format\Video\X264('libmp3lame'))

    ->save($name_file);

               $imageName = Storage::disk('s3')->url($name_file);


    $viddy->title=$imageName;
    $viddy->save();

Thanks in advance

Upvotes: 1

Views: 3680

Answers (1)

Matthew Daly
Matthew Daly

Reputation: 9476

Processing videos is slow, and the only reliable way to actually speed it up is to throw more resources at it, which usually isn't worth it. YouTube is fast at least in part because they have Google's resources, which the likes of you and I usually don't.

However, you can speed up the user's perception of speed by moving the video processing to a message queue (which YouTube almost certainly uses too). That way the request will finish quickly, and you can process the queue in the background. Then, when it's finished you can notify the user in an appropriate fashion, whether that's an email or a notification via Websockets. As Derek Pollard mentioned, Laravel has its own queue implementation and you should refer to the documentation for that.

Another option might be to hand off video processing to a dedicated microservice, in which case that microservice would need to notify your application once processing is done. Or there are third party services that will do the same thing, if your budget allows for them. Regardless, this type of task is best done asynchronously rather than leaving the user waiting for 20 minutes or so.

Upvotes: 7

Related Questions