Skip to content

How to scale FFmpeg transcoding beyond one server

How fast FFmpeg really is, how to go from one server to a queue of workers, when chunked encoding helps, and when to stop running encoding servers.

By Bruno Celeste

What is the best dedicated server for heavy FFmpeg processing? A bigger server buys time, but it does not scale. Move encoding out of your web app into a queue with separate workers, scale the workers with the queue, and split long videos into chunks only when one machine is too slow for a single video. Or hand the encoding to an API and keep only your storage. The right choice depends less on the server than on how much of your time the pipeline takes.

How fast is FFmpeg, really?

Start by measuring, because everything else depends on how many minutes of video a machine encodes per minute. We ran the same H.264 encodes on two AWS instance families, ARM64 Graviton3 (c7g) and Intel Xeon (c7i), at three sizes each:

Instance 720p, medium 1080p, medium 1080p HLS ladder, veryfast
c7g.large, 2 vCPUs 1.3× 0.8× 0.9×
c7g.xlarge, 4 vCPUs 2.5× 1.5× 1.8×
c7g.2xlarge, 8 vCPUs 4.6× 2.9× 3.3×
c7i.large, 2 vCPUs 1.2× 0.7× 0.8×
c7i.xlarge, 4 vCPUs 2.3× 1.4× 1.6×
c7i.2xlarge, 8 vCPUs 4.1× 2.6× 2.7×

Speeds are multiples of realtime: at 1.5×, one hour of 1080p video takes 40 minutes. Below 1×, the server encodes more slowly than the video plays, so a small machine falls behind as soon as uploads arrive steadily.

How we measured: FFmpeg with libx264, in AWS us-east-1. Each encode ran alone on the whole instance, twice, and the two runs agreed within 1%. The 720p source is a 32-second camera clip. The 1080p source is one minute of Tears of Steel (Blender Foundation, CC BY), scaled to 1920 × 858 at 24 fps. Single encodes use -crf 23 -c:a aac; the ladder is the three-rendition HLS command from the S3 article, scaled by width to 1920, 1280 and 854 pixels. Your content and settings will give different numbers, so measure your own: FFmpeg prints the speed as it runs.

ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 -c:a aac output.mp4
# ... speed=1.5x

What the numbers show:

  • Resolution costs more than you think. On c7g.xlarge, 1080p ran at 1.5× against 2.5× for 720p, and this 1080p clip has fewer pixels than standard 16:9 video.
  • The preset matters more than the ladder. The three-rendition ladder at veryfast finished faster than a single 1080p file at medium. Slower presets compress better and take longer, so choose the preset before you choose the hardware.
  • Not every vCPU is a core. On Intel instances, two vCPUs are two threads of one physical core. Each Graviton vCPU is a full core, so at the same size, Graviton was faster in every test, by up to about a fifth, and it costs less per hour. Compare instances by measured speed, not by vCPU count.

A machine at 1.5× encodes 90 minutes of video per hour. Divide the minutes uploaded in your busiest hour by what one machine encodes per hour, and you have the number of machines you need at peak. Uploads rarely arrive evenly, so that peak is what you size for.

Step 1: get FFmpeg out of your web server

The first version usually runs FFmpeg inside the request that received the upload. That works until two uploads arrive together, a long video times out the request, or an encode uses every CPU core while your app is trying to answer other users.

Move encoding to a background worker. The web app stores the upload, records the video as processing, and adds a job to a queue. A worker takes the job, runs FFmpeg, writes the outputs to storage, and marks the video ready or failed.

An encoding pipeline: the app stores the upload and adds a job to a queue. Three FFmpeg workers take jobs from the queue and write HLS or MP4 outputs to storage. More workers are added as the queue grows.

The details that decide whether it holds up:

  • Make jobs idempotent. Queues deliver some messages twice, and workers die mid-encode. Running a job again must produce the same output at the same path, not a duplicate video.
  • Set the visibility timeout above the longest encode. If a job takes longer than the queue's timeout, another worker picks it up while the first is still encoding.
  • Give workers enough disk. FFmpeg can read from a URL, but outputs, segments and temporary files need local space, often more than the source itself. Chunking, below, removes this limit.
  • Report progress. -progress pipe:1 prints machine-readable progress, so your app can show more than "processing".
  • Separate bad files from bad luck. Retry network and capacity errors. Do not retry a corrupt upload forever; mark it failed with a reason your users can act on.

Step 2: scale the workers with the queue

Once encoding sits behind a queue, scaling is a question of how many workers you run. Scale on queue depth: add workers when jobs wait, remove them when the queue is empty. Two choices come up quickly:

  • Spot or preemptible instances cost much less, but the cloud can reclaim them with about two minutes' notice. Encodes must survive being stopped halfway, which is where idempotent jobs pay off.
  • Serverless functions scale to zero, but have hard limits. AWS Lambda stops a function after 15 minutes, with at most 10 GB of memory and 10 GB of temporary disk (Lambda quotas). That fits short clips, not a one-hour 1080p ladder.

The cost to watch is idle capacity. Workers sized for your busiest hour sit mostly unused the rest of the day, and machines that scale up from zero add startup time before the first job runs.

Step 3: encode long videos in chunks

When one machine is too slow for a single long video, split the video, encode the pieces on several machines, and join the results. On one machine, chunking does not help much: FFmpeg's x264 encoder already uses every core, so chunks encoded side by side share the same CPU time as a single encode. The gain comes from sending chunks to different workers.

Chunking also removes the disk limit. Each worker needs space only for its own chunk, and none if it reads the chunk from a signed URL. With HLS output, every chunk becomes segments that go straight to storage, so no machine ever holds the whole video. Disk stops limiting how large a file you can encode. A single MP4 output is the exception: joining it still writes the full file on one machine.

The basic sequence, which we tested on the 720p clip from the benchmark:

# 1. Split the video stream at keyframes, without re-encoding
ffmpeg -i input.mp4 -map 0:v -c copy -f segment -segment_time 8 \
  -reset_timestamps 1 chunk_%03d.mp4

# 2. Encode the audio once, separately
ffmpeg -i input.mp4 -map 0:a -c:a aac -b:a 128k audio.m4a

# 3. Encode every chunk (here 4 at a time; in production, one per worker)
ls chunk_*.mp4 | xargs -P 4 -I{} \
  ffmpeg -i {} -c:v libx264 -preset medium -crf 23 -an enc_{}

# 4. Join the chunks and add the audio back
for f in enc_chunk_*.mp4; do echo "file '$f'"; done > list.txt
ffmpeg -f concat -safe 0 -i list.txt -i audio.m4a \
  -map 0:v -map 1:a -c copy -movflags +faststart output.mp4

The output had the same 963 frames and the same duration as the source. The hard parts start after this:

  • Chunks are cut at existing keyframes, so their lengths vary with the source. Sources with long or open GOPs need care at the boundaries.
  • Rate control resets at every chunk. Each encoder sees only its own piece, so quality and bitrate can shift at the joins unless you control them.
  • Audio has to be encoded separately, or the joins produce gaps and drift.
  • For HLS ladders, every rendition must keep the same keyframe positions so players can switch between them.

The managed route

Everything above is engineering work that keeps going after launch: worker images, FFmpeg upgrades, odd input files, retries, capacity spikes and the bills for idle machines. A transcoding API takes it over, and you keep only the request and the result.

Chunkify runs this pipeline, chunked encoding included, behind its API and writes the outputs to your own S3, R2 or S3-compatible bucket. There are two ways in:

  • Video streaming: one call per video produces an adaptive HLS ladder chosen for that video's content, plus a poster and timeline previews. Billed once per input minute: $0.03 per minute of HD video on Pay as you go, $0.02 on Team. See the video streaming quickstart.
  • Transcoding: one call per output file, such as an MP4 or WebM, with H.264, H.265, AV1 or VP9 and optional per-title rate control. Billed per output minute: $0.008 for HD H.264, or $0.012 with per-title optimization. See Create a transcode.
import Chunkify from '@chunkify/chunkify';

const client = new Chunkify({
  projectAccessToken: process.env.CHUNKIFY_PROJECT_TOKEN,
});

const source = await client.sources.create({
  url: 'https://example.com/path/to/video.mov',
});

const transcoding = await client.transcodings.create({
  source_id: source.id,
  format: {
    id: 'mp4_h264',
    height: 720,
    per_title: true,
  },
  storage: { path: 'exports/video-720p.mp4' },
});

per_title: true lets Chunkify choose the bitrate from the video's content. To set the quality yourself, use crf or video_bitrate instead; without any of them, the codec's default CRF applies. Chunkify sends a transcoding.ready webhook when the file is published. Your app keeps its upload flow, its player and its storage.

When to keep your own pipeline

Keep FFmpeg in your own infrastructure when you need custom filters, specific encoder builds, unusual formats, or processing that must stay inside your environment. A transcoding API supports a defined set of formats and settings, not every FFmpeg option. You can also split the work: move standard uploads to an API and keep the special cases in your own pipeline. Chunkify vs FFmpeg compares the two in detail.

FAQ

What is the best server for FFmpeg?

For x264 and x265, more fast CPU cores help most, along with enough local disk for outputs. But one server has a ceiling. Size it from measurements: one machine encodes its realtime speed × 60 minutes of video per hour, so divide the minutes uploaded in your busiest hour by that, then plan for the queue and extra workers you will need when uploads double.

Should I use a GPU for encoding?

Usually not for on-demand video. GPU instances cost several times more per hour than CPU virtual machines, and they are harder to get on short notice, so they only pay off when they stay busy with steady, high volume. GPU encoders such as NVIDIA NVENC are much faster, which suits live streaming. But for files you store and deliver many times, CPU encoders such as x264 usually reach the same quality at a lower bitrate, which also saves storage and delivery. Compare both at your target quality, including what the instances cost while idle.

Can I run FFmpeg on AWS Lambda?

Yes, for short videos. Lambda's 15-minute limit and 10 GB of memory and temporary disk rule out long, high-resolution encodes unless you split them into chunks first.

How many videos can one server handle at once?

Fewer than the number of cores suggests. One x264 encode already uses several cores, so running many encodes at once mostly divides the same CPU time. Run one or two encodes per machine, measure the throughput, and add machines instead.

Does Chunkify use FFmpeg?

Yes. Chunkify uses FFmpeg too. The difference is who operates the system around it: the workers, scheduling, retries, encoding decisions and output validation.

Get started

Ready to add video to your app?

Pay as you go has no monthly fee. Start without a card and get $10 in welcome credit.

Build with agents
ClaudeCodexCursor

Add video uploads and playback to my app. Use the Chunkify skill at https://chunkify.dev/SKILL.md