Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save charlesroper/aaf12af8413b82533842be7997c5c5bf to your computer and use it in GitHub Desktop.

Select an option

Save charlesroper/aaf12af8413b82533842be7997c5c5bf to your computer and use it in GitHub Desktop.
FFmpeg HEVC Hardware Encoding (AMD AMF)
tags
ffmpeg
video-encoding
hevc
amd-amf
wsl-interop
powershell
date-created 2026-03-17 22:45:53 +0000
date-modified 2026-03-17 23:09:58 +0000

FFmpeg HEVC Hardware Encoding (AMD AMF)

Also see [[FFmpeg AV1 Hybrid Encoding Pipeline]]

This note details the optimal hardware encoding pipelines for compressing video to HEVC (H) using an AMD Radeon discrete GPU.

To ensure maximum performance and bypass brittle Linux translation layers in WSL2, the WSL commands utilise the Interop feature to call the native Windows ffmpeg.exe binary directly from the Linux terminal.

Strategy 1: CQP (Constant Quantisation Parameter)

CQP locks the compression algorithm to a strict mathematical value across the entire video. It guarantees consistent mathematical quality but results in highly unpredictable file sizes. It is best suited for archiving raw footage or creating intermediate files.

Note: The AMD VBAQ (Variance Based Adaptive Quantisation) feature fundamentally conflicts with CQP and is automatically disabled when using this method.

WSL Bash (Interop)

ffmpeg.exe -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 \
  -c:v hevc_amf -quality quality -rc cqp -qp_i 28 -qp_p 28 -qp_b 28 \
  -c:a copy \
  output_cqp.mkv

PowerShell

ffmpeg -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 `
  -c:v hevc_amf -quality quality -rc cqp -qp_i 28 -qp_p 28 -qp_b 28 `
  -c:a copy `
  output_cqp.mkv

Strategy 2: VBR with VBAQ

Variable Bitrate (VBR) paired with Variance Based Adaptive Quantisation (VBAQ) dynamically analyses the visual complexity of every frame. It steals bits from flat, simple backgrounds and reallocates them to complex textures where human eyes need the detail most. This is the gold standard for everyday viewing, streaming, and hitting strict file size targets.

WSL Bash (Interop)

ffmpeg.exe -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 \
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 5M -maxrate 7M -vbaq 1 \
  -c:a copy \
  output_vbaq.mkv

PowerShell

ffmpeg -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 `
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 5M -maxrate 7M -vbaq 1 `
  -c:a copy `
  output_vbaq.mkv

Parameter Breakdown

  • -hwaccel d3d11va: Instructs FFmpeg to use Direct3D 11 Video Acceleration for hardware decoding.
  • -hwaccel_device 1: Routes the workload to the discrete GPU (index 1). Ensure this flag is placed before the input file.
  • -c:v hevc_amf: Calls the AMD Advanced Media Framework encoder to physically compress the video into HEVC.
  • -quality quality: An AMF preset that explicitly prioritises visual fidelity over absolute encoding speed.
  • -rc cqp / -qp_i 28 / -qp_p 28 / -qp_b 28: Sets the rate control to Constant Quantisation, locking the I, P, and B frames to a compression value of 28. Lower values increase quality and file size; higher values degrade quality to save space.
  • -rc vbr_peak: Sets the rate control to a peak-constrained Variable Bitrate, allowing the encoder to adjust compression frame by frame.
  • -b:v 5M: Sets the target average video bitrate (data budget) to 5 Megabits per second.
  • -maxrate 7M: Sets a hard ceiling of 7 Megabits per second to prevent file size bloat during complex action scenes.
  • -vbaq 1: Explicitly enables Variance Based Adaptive Quantisation to optimise detail retention in complex areas.
  • -c:a copy: Stream-copies the original audio track without re-encoding it, preserving quality and saving CPU cycles.

Network Delivery Strategies (VBR & VBAQ)

When encoding for specific network conditions, Variable Bitrate (VBR) paired with Variance Based Adaptive Quantisation (VBAQ) provides the optimal balance of visual fidelity and predictable file sizes.

For harsh network conditions, reducing the physical resolution is necessary so the encoder is not starved of data. The filter -vf "scale=720:-2" locks the width to 720 pixels and automatically calculates the height to maintain the aspect ratio, ensuring the dimension remains mathematically divisible by two.

1. Harsh Mobile (3G / Poor 4G)

  • Target: 800 kbps
  • Max: 1200 kbps
  • Resolution: Scaled to 720p width

WSL Bash (Interop)

ffmpeg.exe -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 \
  -vf "scale=720:-2" \
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 800k -maxrate 1200k -vbaq 1 \
  -c:a copy \
  output_harsh_mobile.mkv

PowerShell

ffmpeg -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 `
  -vf "scale=720:-2" `
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 800k -maxrate 1200k -vbaq 1 `
  -c:a copy `
  output_harsh_mobile.mkv

2. Standard Mobile (Good 4G)

  • Target: 2 Mbps
  • Max: 3 Mbps
  • Resolution: Native 1080p

WSL Bash (Interop)

ffmpeg.exe -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 \
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 2M -maxrate 3M -vbaq 1 \
  -c:a copy \
  output_standard_mobile.mkv

PowerShell

ffmpeg -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 `
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 2M -maxrate 3M -vbaq 1 `
  -c:a copy `
  output_standard_mobile.mkv

3. Standard Broadband (HD)

  • Target: 5 Mbps
  • Max: 7.5 Mbps
  • Resolution: Native 1080p

WSL Bash (Interop)

ffmpeg.exe -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 \
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 5M -maxrate 7.5M -vbaq 1 \
  -c:a copy \
  output_broadband.mkv

PowerShell

ffmpeg -hwaccel d3d11va -hwaccel_device 1 -i input.mp4 `
  -c:v hevc_amf -quality quality -rc vbr_peak -b:v 5M -maxrate 7.5M -vbaq 1 `
  -c:a copy `
  output_broadband.mkv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment