Introduction
I have some old videos, recorded in h264, so wanted to try to optimize them.
Given a jump in AI, this is now very easy to investigate and figure out.
There are 3 options, all below:
- cpu encoding, best quality, but lasts longs
- hw encoding, very fast, but quality/size is worse
HEVC
CPU
- preset veryslow — slower preset = smaller file at same quality
- crf 22 — quality slider; lower = sharper + bigger
- pix_fmt yuv420p10le — 10-bit encoding; better compression, less banding
- x265-params rc-lookahead=60 — analyzes more future frames for better bit allocation
- x265-params lookahead-slices=0 — single-threaded lookahead; small quality gain
- x265-params aq-mode=3 — protects textured dark/detail regions (fixes blurry-face issue)
- x265-params aq-strength=1.0 — strength of aq-mode; raise to 1.2 if detail is soft
podman run --rm -v "$PWD:/data:Z" lscr.io/linuxserver/ffmpeg \
-i /data/input.mkv \
-map 0 \
-c:v libx265 -preset veryslow -crf 22 -pix_fmt yuv420p10le \
-x265-params rc-lookahead=60:lookahead-slices=0:aq-mode=3:aq-strength=1.0 \
-c:a copy -c:s copy \
/data/output.mkv
Intel
- init_hw_device qsv=hw:/dev/dri/renderD128 — create QSV encoder session on GPU
- filter_hw_device hw — tell filters to use that device
- vf ‘format=p010,hwupload=extra_hw_frames=64’ — convert to 10-bit and upload frames to GPU
- preset slow — best HW preset; no veryslow exists
- global_quality 22 — ICQ quality value, roughly comparable to crf
- profile:v main10 — required to enable 10-bit on hardware
- look_ahead 1 -look_ahead_depth 40 — bit allocation based on upcoming frames; may be ignored by driver
- extbrc 1 — extended rate control; better bit distribution
podman run --rm --device /dev/dri -v "$PWD:/data:Z" lscr.io/linuxserver/ffmpeg \
-init_hw_device qsv=hw:/dev/dri/renderD128 \
-filter_hw_device hw \
-i /data/input.mkv \
-map 0 \
-vf 'format=p010,hwupload=extra_hw_frames=64' \
-c:v hevc_qsv -preset slow -global_quality 22 -profile:v main10 \
-look_ahead 1 -look_ahead_depth 40 -extbrc 1 \
-c:a copy -c:s copy \
/data/output.mkv
AMD
- vaapi_device /dev/dri/renderD128 — select VAAPI GPU device
- vf ‘format=p010,hwupload’ — convert to 10-bit and upload to GPU
- rc_mode CQP — constant-QP mode (quality-based like crf)
- global_quality 22 — QP value in CQP mode
- profile:v main10 — 10-bit profile
podman run --rm --device /dev/dri -v "$PWD:/data:Z" lscr.io/linuxserver/ffmpeg \
-vaapi_device /dev/dri/renderD128 \
-i /data/input.mkv \
-map 0 \
-vf 'format=p010,hwupload' \
-c:v hevc_vaapi -rc_mode CQP -global_quality 22 -profile:v main10 \
-c:a copy -c:s copy \
/data/output.mkv
Notes
“Minimum size and maximum quality” is genuinely a tradeoff at a single slider, and that slider is the quality value (crf / global_quality). 22 is a good sweet spot for film/video. If your test clip at 22 looks indistinguishable from the source, try 24 to shrink further, then 25, stopping when you first notice degradation. There’s no parameter that beats just walking this value.
Even fully tuned, QSV will land roughly 15-25% larger than the veryslow x265 command for equal visual quality. Since runtime is explicitly not an issue, the CPU command is the one that actually matches your goal. Run QSV only if you ever need it fast.
AV1
CPU
- preset 4 — 0-13 scale, lower = slower/better; 2-4 best quality per size
- crf 26 — quality slider; same level as HEVC crf 22, ~25% smaller
- pix_fmt yuv420p10le — 10-bit
- svtav1-params tune=0 — optimize for perceived detail over metrics
podman run --rm -v "$PWD:/data:Z" lscr.io/linuxserver/ffmpeg \
-i /data/input.mkv \
-map 0 \
-c:v libsvtav1 -preset 4 -crf 26 -pix_fmt yuv420p10le \
-svtav1-params tune=0 \
-c:a copy -c:s copy \
/data/output.mkv
Intel
Requires an Intel Arc discrete GPU (A380 and up) or an Arc iGPU (Meteor Lake / Core Ultra and newer) with up-to-date media driver. Older Intel iGPUs (UHD 770 and back) can decode but not encode AV1, so this command will fail on those. No profile flag needed — AV1 main includes 10-bit
- init_hw_device qsv=hw:/dev/dri/renderD128 — GPU session (same setup as hevc_qsv)
- filter_hw_device hw — filters use the QSV device
- vf ‘format=p010,hwupload=extra_hw_frames=64’ — 10-bit + GPU upload
- preset slow — HW preset
- global_quality 26 — quality value on AV1 scale
- look_ahead 1 -look_ahead_depth 40 — future-aware bit allocation
- extbrc 1 — extended rate control
podman run --rm --device /dev/dri -v "$PWD:/data:Z" lscr.io/linuxserver/ffmpeg \
-init_hw_device qsv=hw:/dev/dri/renderD128 \
-filter_hw_device hw \
-i /data/input.mkv \
-map 0 \
-vf 'format=p010,hwupload=extra_hw_frames=64' \
-c:v av1_qsv -preset slow -global_quality 26 \
-look_ahead 1 -look_ahead_depth 40 -extbrc 1 \
-c:a copy -c:s copy \
/data/output.mkv
AMD
Requires a Radeon RX 7000 series or newer for hardware AV1 encoding.
- vaapi_device /dev/dri/renderD128 — VAAPI device
- vf ‘format=p010,hwupload’ — 10-bit + GPU upload
- rc_mode CQP — constant-QP mode
- global_quality 26 — QP value
podman run --rm --device /dev/dri -v "$PWD:/data:Z" lscr.io/linuxserver/ffmpeg \
-vaapi_device /dev/dri/renderD128 \
-i /data/input.mkv \
-map 0 \
-vf 'format=p010,hwupload' \
-c:v av1_vaapi -rc_mode CQP -global_quality 26 -profile:v main \
-c:a copy -c:s copy \
/data/output.mkv