In this episode, we dive into encoding videos with FFmpeg in a Laravel app. First, we discuss why you want to queue up encoding jobs instead of running them synchronously—since video encoding can take a while, you don't want users waiting on uploads to finish! So, we walk through setting up database-backed queues in Laravel and making sure our encoding jobs get pushed to the queue instead of running instantly.
After setting up the queue, we bring in the laravel-ffmpeg
package, which makes working with FFmpeg in Laravel super smooth. We cover how to configure FFmpeg and FFprobe paths properly so Laravel can access them. Then we jump straight into the code, showing how to fetch the uploaded video from the disk, encode it as an MP4 (using the x264 codec), and save it back to the public directory with a new filename using a UUID.
We test out the workflow: uploading a video, seeing the job queued, running the queue worker, and watching the new file get created. Of course, we run into a typical issue—a job timing out because encoding is slow! So, we see how to adjust job timeouts so these big jobs can run to completion.
At the end of the episode, the video is successfully encoded, but we notice there's no progress shown to the user. Teaser for next time: we'll look at broadcasting job progress so users can see what's happening live!