Ffmpeg Hwaccel
Context: $ARGUMENTS
Quick start
- I don't know what my GPU supports: → Step 1 (detection)
- Just encode fast on whatever GPU I have: →
scripts/hwaccel.py transcode --accel auto - Zero-copy NVIDIA pipeline (decode+scale+encode on GPU): → Step 2, recipe A
- Intel Quick Sync on Windows/Linux: → Step 2, recipe B
- VA-API on Linux desktop: → Step 2, recipe C
- macOS (Intel or Apple Silicon): → Step 2, recipe D
- AMD on Windows: → Step 2, recipe E
When to use
- You need to transcode many/long files and CPU encode is too slow.
- You want real-time or faster-than-realtime encoding (live streaming, bulk archive conversion).
- You explicitly want NVENC, QSV, VAAPI, VideoToolbox, AMF or Vulkan.
- Hardware decoder (NVDEC/QSV-dec/VAAPI-dec) to offload decoding while still using CPU for something else.
If you just want best quality at the smallest size, prefer ffmpeg-transcode with libx264/libx265/libaom-av1 — hardware encoders trade quality for speed. See the gotcha about quality-per-bit below.
Step 1 — Detect what's available on this machine
# 1. Which hwaccel APIs does this ffmpeg build expose?
ffmpeg -hide_banner -hwaccels
# 2. Which HW encoders are compiled in?
ffmpeg -hide_banner -encoders | grep -E 'nvenc|qsv|vaapi|videotoolbox|amf|vulkan'
# 3. Which HW decoders / *_cuvid variants?
ffmpeg -hide_banner -decoders | grep -E 'cuvid|qsv|vaapi|videotoolbox'
# 4. Probe the NVENC / QSV / VAAPI backends
ffmpeg -hide_banner -f lavfi -i nullsrc -c:v h264_nvenc -f null - 2>&1 | head -20 # NVENC sanity
ffmpeg -hide_banner -init_hw_device qsv=hw -f lavfi -i nullsrc -c:v h264_qsv -f null - 2>&1 | head -20
vainfo # Linux VAAPI
Or just: uv run ${CLAUDE_SKILL_DIR}/scripts/hwaccel.py detect.
Platform cheat sheet (what to pick when auto):
| OS / GPU | First choice | Fallback |
|------------------------|--------------------|-------------------|
| macOS (any Mac) | videotoolbox | libx264 |
| Linux + NVIDIA | nvenc | vaapi |
| Linux + Intel iGPU | qsv (iHD driver) | vaapi |
| Linux + AMD | vaapi (Mesa) | libx264 |
| Windows + NVIDIA | nvenc | libx264 |
| Windows + Intel iGPU | qsv | d3d11va decode |
| Windows + AMD | amf | libx264 |
Step 2 — Pick a decode + filter + encode pipeline
The general shape is:
ffmpeg [hwaccel flags BEFORE -i] -i in.mp4 \
[-vf "GPU filter chain" OR "hwdownload,format=...,CPU filter chain"] \
[-c:v <hw encoder>] [rate control + preset flags] \
out.mp4
Key rule: hwaccel flags come before -i. Encoder flags come after.
Recipe A — NVIDIA end-to-end GPU (decode, scale, encode all on CUDA)
ffmpeg -hwaccel cuda -hwaccel_output_format cuda \
-i in.mp4 \
-vf "scale_cuda=1280:720:format=yuv420p" \
-c:v h264_nvenc -preset p5 -tune hq -rc vbr -cq 23 -b:v 0 -maxrate 12M -bufsize 24M \
-c:a copy out.mp4
HEVC: -c:v hevc_nvenc -pix_fmt p010le for 10-bit. AV1 (Ada/Blackwell): -c:v av1_nvenc -preset p5 -cq 30.
NVENC decode-only, CPU-encode (e.g. you need libx264 quality but want fast decode):
ffmpeg -hwaccel cuda -i in.mp4 -c:v libx264 -crf 18 out.mp4
(No -hwaccel_output_format cuda → ffmpeg downloads frames automatically.)
Explicit bridge when mixing GPU decode with CPU filters:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i in.mp4 \
-vf "hwdownload,format=nv12,unsharp=5:5:0.8,hwupload_cuda" \
-c:v h264_nvenc -preset p5 -cq 23 out.mp4
Recipe B — Intel Quick Sync (QSV)
ffmpeg -hwaccel qsv -c:v h264_qsv -i in.mp4 \
-vf "scale_qsv=1280:720" \
-c:v h264_qsv -preset medium -global_quality 23 -look_ahead 1 \
-c:a copy out.mp4
HEVC: -c:v hevc_qsv. AV1 (Arc / 12th gen+): -c:v av1_qsv. Rate control: -global_quality = ICQ, add -look_ahead 1 for LA-ICQ, or use -b:v 5M for CBR/VBR.
Recipe C — VA-API (Linux, Intel / AMD / NVIDIA with nvidia-vaapi-driver)
ffmpeg -vaapi_device /dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi \
-i in.mp4 \
-vf "scale_vaapi=1280:720,format=nv12|vaapi,hwupload" \
-c:v h264_vaapi -rc_mode CQP -qp 23 \
-c:a copy out.mp4
HEVC: -c:v hevc_vaapi -profile:v main (or main10 for 10-bit with -pix_fmt p010le). For CPU-source → VAAPI encode:
ffmpeg -vaapi_device /dev/dri/renderD128 -i in.mp4 \
-vf "format=nv12,hwupload" \
-c:v h264_vaapi -qp 23 out.mp4
Recipe D — VideoToolbox (macOS)
# H.264 — bitrate mode
ffmpeg -hwaccel videotoolbox -i in.mp4 \
-c:v h264_videotoolbox -b:v 5M -maxrate 6M -bufsize 10M \
-c:a copy out.mp4
# HEVC — quality mode on Apple Silicon; hvc1 tag for Safari/QuickTime
ffmpeg -hwaccel videotoolbox -i in.mp4 \
-c:v hevc_videotoolbox -tag:v hvc1 -q:v 50 -allow_sw 1 \
-c:a copy out.mov
# ProRes (Apple Silicon M1+ has a hardware ProRes encoder)
ffmpeg -i in.mov -c:v prores_videotoolbox -profile:v 3 -c:a copy out.mov
-q:v on HEVC_VT is 0–100 (higher = better quality). -allow_sw 1 lets VT fall back to software when hardware rejects the request (odd resolutions, unusual pixel formats).
Recipe E — AMD AMF (Windows)
ffmpeg -i in.mp4 \
-c:v h264_amf -rc vbr_latency -quality speed -b:v 5M -maxrate 8M \
-c:a copy out.mp4
HEVC: -c:v hevc_amf. Quality presets: speed | balanced | quality. RC modes: cqp | cbr | vbr_latency | vbr_peak (names differ between builds — check ffmpeg -h encoder=h264_amf).
Step 3 — Format bridges (hwupload / hwdownload) — the #1 cause of confusion
GPU frames live in opaque hardware surfaces (cuda, qsv, vaapi, videotoolbox). CPU filters (scale, crop, drawtext, unsharp, eq, pad) cannot touch them directly. Rules:
| Situation | Bridge you need |
|--------------------------------------------------|----------------------------------------------|
| GPU decode → GPU filter (scale_cuda) → HW enc | none — frames stay on GPU |
| GPU decode → CPU filter → HW enc | hwdownload,format=nv12, … ,hwupload_cuda |
| GPU decode → CPU filter → libx264 | hwdownload,format=nv12 |
| CPU source → VAAPI encoder | format=nv12,hwupload |
| CPU source → NVENC | none (NVENC takes CPU frames directly) |
| CPU source → QSV | format=nv12,hwupload=extra_hw_frames=64 |
The format= is not optional before hwupload on VAAPI/QSV — without it you'll see Impossible to convert between the formats.
Step 4 — Verify acceleration actually happened
ffmpeg -benchmark -v verbose -hwaccel cuda -i in.mp4 -c:v h264_nvenc -f null - 2>&1 | \
grep -E 'hwaccel|using|nvenc|nvdec|qsv|vaapi|videotoolbox'
Look for lines like Using auto hwaccel type cuda and [h264_nvenc @ …] Loaded Nvenc version …. Also watch fps= in the progress line: a 1080p H.264 → H.264 transcode should run hundreds of fps on a modern GPU. If you see 30–60 fps, you're probably still on the CPU.
GPU usage: nvidia-smi dmon -s u (NVIDIA), intel_gpu_top (Intel Linux), Activity Monitor → GPU History (macOS), Task Manager → Performance (Windows).
Available scripts
scripts/hwaccel.py— detect available HW + build a correct end-to-end GPU pipeline.detect→ printsffmpeg -hwaccels, encoder inventory, platform guess.transcode --input I --output O --accel {nvenc,qsv,vaapi,videotoolbox,amf,auto} [--codec {h264,hevc,av1}] [--quality 23] [--resolution 1280x720]--dry-runprints the command,--verbosedumps decisions.