Search code examples
laravelffmpeglaravel-queueffmpeg-php

Laravel FFMPEG video conversion without waiting for queue


I'm building an application in Laravel (v9) where users upload videos, and these get converted to MP4 (showing progress percentage), thumbnail gets created… etc

Once the video is uploaded, I dispatch a new job in the background that runs all my FFMPEG commands, and marks the video as ready on the database once FFMPEG has finished.

However, if there are multiple users uploading multiple videos, this leaves them waiting, as Laravel’s queue executes each job one by one.

How can I make it so that videos get converted immediately without waiting for the previous job to finish?


Solution

  • You're always probably going to want to use a queue, but you could look into increasing the number of queue workers that are running at any given time. Take a look at the Laravel docs on running your queue via Supervisor and consider setting the numprocs value high enough to support the concurrent load you need to handle.

    The caveat is that each queue worker will need CPU/memory, so if you set the number of concurrent workers too high, it may exceed your server's capacity.

    You can use this article on php-fpm tuning to help figure out your server capacity needs. The article is focused on tuning web servers, but you can use the same technique to determine how much memory your queue workers are using, and from there determine how many workers you can reasonably run at once.

    One other option would be to look at Sidecar to run your ffmpeg processes in AWS Lambdas rather than relying on a queue at all. This project may help you get started…