FFmpeg filter_complex cuts transcoding passes from three to one
This article details technical lessons learned from building a video transcoding pipeline, focusing on two specific bugs related to PHP memory management during cloud storage downloads and filesystem I/O performance in containerized environments. It also highlights an optimization using FFmpeg's `filter_complex` for single-pass multi-resolution encoding.
Key Takeaways
- `file_put_contents($localPath, $result['Body'])` pulled a 170MB object into PHP memory and hit a 128MB limit.
- Streaming the download in 1MB chunks dropped peak memory usage to roughly 5MB, regardless of file size.
- Temporary transcoding files in a container-mounted project directory were slowed by the host filesystem bridge; moving them to `/tmp` improved processing times.
- Using FFmpeg `filter_complex` decoded the source video once and produced 1080p, 720p, and 480p outputs in a single pass instead of three separate runs.
Why It Matters
The immediate lesson is that video pipelines can fail or slow down because of library behavior and filesystem placement, not just the transcoding command itself. In this case, PHP buffering and container volume mounts created hidden costs that only showed up on a 170MB clip and during repeated FFmpeg writes. For streaming teams, the broader point is that upload/download paths and temp storage choices are load-bearing parts of the stack, especially when workloads involve large files and thousands of I/O operations. What to watch: whether temp files live inside the container or on a mounted project directory, and whether FFmpeg is decoding once or once per rendition.
Read full article at medium.com