Video reencoding

hdds are expensive, eh?

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:

HEVC

CPU

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

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

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

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

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.

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