C.W.K.
Stream
Lesson 07 of 08 · published

Parallel Encoding

~10 min · parallel, batch, throughput

Level 0Viewer
0 XP0/73 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Two parallelism flavors

  1. Within an encode — FFmpeg's libx264/libx265 use multiple threads automatically. -threads 0 (default) lets the encoder pick. Capping (-threads 4) is rarely useful unless you're running multiple encodes.
  2. Across encodes — N FFmpeg processes encoding different files at the same time. This is where real throughput wins live.

The right N

For libx264 -preset slow on a 10-core M3 Pro, each encode pulls 4–6 cores. parallel -j 2 usually wins. -j 4 oversubscribes; encodes finish in roughly the same total time but each one feels slow. For hardware encoders, -j 1 or -j 2 — they share the media engine.

Code

GNU parallel with FFmpeg·bash
# Two encodes at a time, libx264 software
ls *.mov | parallel -j 2 \
  'ffmpeg -y -i {} -c:v libx264 -crf 20 -preset slow -c:a copy {.}.mp4'

# Echo as they start (helpful for log correlation)
ls *.mov | parallel -j 2 --joblog jobs.log \
  'echo "START {}"; ffmpeg -y -i {} -c:v libx264 -crf 20 -preset slow -c:a copy {.}.mp4; echo "DONE {}"'

# Hardware encoders — only 1 or 2 in parallel
ls *.mov | parallel -j 1 \
  'ffmpeg -y -i {} -c:v hevc_videotoolbox -b:v 6M -tag:v hvc1 -c:a copy {.}.mp4'
xargs alternative (no extra install)·bash
# Same idea with xargs
find . -name '*.mov' -print0 | xargs -0 -P 2 -I {} sh -c '
  ffmpeg -y -i "$1" -c:v libx264 -crf 20 -preset slow -c:a copy "${1%.mov}.mp4"
' _ {}

External links

Exercise

Set up a folder with 4 video files. Time encoding all 4 sequentially with libx264 -preset slow. Then run with parallel -j 2 and time again. Then -j 4. Plot total time vs job count — at what N does the curve flatten?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.