Skip to main content

Hardware Acceleration

Frame supports hardware-accelerated video encoding using your GPU, providing significantly faster encoding speeds compared to software encoding. This guide covers NVIDIA NVENC and Apple VideoToolbox encoders.

Overview

Hardware encoders use dedicated silicon on your GPU to encode video, offloading work from the CPU.

Benefits

  • 5-10x faster encoding compared to software codecs
  • Lower CPU usage - frees CPU for other tasks
  • Real-time encoding possible for high-resolution video
  • Lower power consumption on laptops

Tradeoffs

  • Slightly larger files (10-20%) at equivalent quality settings
  • Less control over encoding parameters
  • Requires compatible hardware (recent NVIDIA GPU or Apple Silicon)
Hardware encoding is ideal when speed is more important than achieving the absolute smallest file size.

Hardware Decode Acceleration

In addition to hardware encoding, Frame supports hardware decode acceleration via the hwDecode option. Setting: hwDecode: true

How It Works

  • Decodes the input video using GPU hardware acceleration
  • Available for both NVENC (CUDA) and VideoToolbox encoders
  • Further reduces CPU usage during conversion

When to Enable

  • Encoding high-resolution video (4K, 8K)
  • Processing multiple files simultaneously
  • Minimizing CPU load
  • Laptop/battery-powered usage

Implementation

When hwDecode is enabled, Frame automatically adds the appropriate hardware acceleration flags: For NVENC (NVIDIA):
-hwaccel cuda -hwaccel_output_format cuda
For VideoToolbox (Apple):
-hwaccel videotoolbox
Hardware decode requires the source video codec to be supported by your GPU. Most modern GPUs support H.264/H.265 decode acceleration.

NVIDIA NVENC

NVIDIA’s hardware encoder available on GeForce, Quadro, and Tesla GPUs.

Requirements

  • NVIDIA GPU with NVENC support (GTX 600 series or newer)
  • Recent drivers installed
  • CUDA support enabled

Supported Codecs

h264_nvenc

Hardware-accelerated H.264 encoding using NVIDIA GPU.Codec ID: h264_nvenc

Use Cases

  • Fast H.264 encoding (5-10x faster than libx264)
  • Real-time recording and streaming
  • Batch processing large video libraries
  • 4K video encoding
  • Screen recording

Quality Control

Frame uses NVIDIA’s VBR (Variable Bitrate) mode with CQ (Constant Quality):Quality Setting: The quality field (0-100) maps to NVENC’s CQ parameter:
  • Quality 100 → CQ 1 (best quality, largest files)
  • Quality 50 → CQ 26 (balanced)
  • Quality 0 → CQ 51 (lowest quality, smallest files)
The formula: CQ = 52 - (quality / 2)
  • Quality 60-70: High quality (CQ 22-17)
  • Quality 50: Balanced (CQ 26) - Default
  • Quality 30-40: Lower quality (CQ 32-27)

Example Configuration

{
  "videoCodec": "h264_nvenc",
  "quality": 50,
  "preset": "medium",
  "hwDecode": true
}
NVENC quality “50” produces comparable results to software CRF 23-25, but encodes 5-10x faster.

NVENC Presets

NVENC uses different preset names than software encoders. Frame automatically maps software presets to NVENC equivalents: Native NVENC Presets:
  • p1 - Fastest (lowest quality)
  • p2
  • p3
  • p4 - Balanced
  • p5
  • p6
  • p7 - Slowest (best quality)
Software Preset Mapping: When using standard software preset names, Frame maps them:
  • ultrafast, superfast, veryfast, fasterfast
  • fastfast
  • mediummedium (default)
  • slowslow
  • slower, veryslowslow
You can use either NVENC native presets (p1-p7) or standard preset names (fast/medium/slow) in Frame.

NVENC Advanced Options

Frame exposes two NVENC-specific quality enhancement options:

Spatial Adaptive Quantization

Setting: nvencSpatialAq: true

What It Does

Allocates more bits to complex/detailed areas of the frame and fewer bits to flat areas.

Benefits

  • Improved perceived quality
  • Better detail preservation in complex scenes
  • More efficient bit allocation

When to Use

  • Content with varying complexity (movies, nature footage)
  • When quality is important
  • Minimal speed impact (~5% slower)

Implementation

-spatial_aq 1
Spatial AQ is recommended for most use cases. It provides better quality with minimal performance impact.

Apple VideoToolbox

Apple’s hardware encoder for macOS and iOS devices, integrated into Apple Silicon and Intel Macs with T2 chips.

Requirements

  • Apple Silicon (M1, M2, M3, M4 series) - Recommended
  • Intel Mac with T2 chip (limited support)
  • macOS 10.13 or newer

Supported Codecs

h264_videotoolbox

Hardware-accelerated H.264 encoding using Apple’s VideoToolbox framework.Codec ID: h264_videotoolbox

Use Cases

  • Fast encoding on Apple Silicon Macs
  • Native macOS/iOS video encoding
  • Real-time recording on Mac
  • Batch processing on M-series chips
  • Low power consumption encoding on laptops

Quality Control

VideoToolbox uses a different quality system than software encoders:Quality Setting: The quality field (0-100) directly maps to VideoToolbox’s quality parameter:
  • Quality 0-100 (higher is better)
  • Quality 50 is the default (balanced)
  • Quality 60-80 for high quality
Unlike CRF (lower is better), VideoToolbox quality is higher = better.

Presets

VideoToolbox does not use presets - it has its own optimized encoding path.

Example Configuration

{
  "videoCodec": "h264_videotoolbox",
  "quality": 50,
  "hwDecode": true
}
On Apple Silicon, VideoToolbox encoding is extremely efficient and fast, especially for 4K video.

VideoToolbox Advanced Options

videotoolboxAllowSw

Setting: videotoolboxAllowSw: true

What It Does

Allows VideoToolbox to fall back to software encoding if hardware encoding fails or is unavailable.

When to Use

  • Ensuring encoding always succeeds
  • Compatibility with older/unsupported configurations
  • Testing on systems with limited hardware support

Implementation

-allow_sw 1

Example Configuration

{
  "videoCodec": "h264_videotoolbox",
  "quality": 50,
  "videotoolboxAllowSw": true
}
When software fallback is triggered, encoding speed will be significantly slower (similar to libx264).

Hardware vs Software Encoding

When to Use Hardware Encoding

Use hardware encoding when:
  • Processing large video libraries
  • Real-time encoding or streaming
  • Quick turnaround needed
  • Batch processing many files
  • 4K/8K video encoding
  • Laptop/battery usage (lower power consumption)
Recommended:
  • NVIDIA: h264_nvenc or hevc_nvenc
  • Apple: h264_videotoolbox or hevc_videotoolbox
Use software encoding when:
  • Archival quality is paramount
  • Minimizing file size is critical
  • Encoding time is not a concern
  • Maximum compression efficiency needed
  • Advanced encoding controls required
Recommended:
  • libx264 (H.264) with slow/slower preset
  • libx265 (H.265) with slow preset

Quality Comparison

At equivalent quality settings, file size differences:
EncoderRelative File SizeEncoding Speed
libx264 (veryslow)1.0x (baseline)1x
libx264 (medium)1.1x4x
h264_nvenc (slow)1.2x10x
h264_videotoolbox1.15x8x
libx265 (slow)0.6x0.3x
hevc_nvenc (slow)0.75x8x
hevc_videotoolbox0.7x6x
Hardware encoders produce 10-20% larger files but encode 5-10x faster. Choose based on your priorities.

Performance Tips

Optimizing for Speed

For fastest possible encoding:
{
  "videoCodec": "h264_nvenc",
  "preset": "fast",
  "quality": 50,
  "hwDecode": true,
  "nvencSpatialAq": false,
  "nvencTemporalAq": false
}
Expected Speed:
  • 4K video: 100-200+ FPS on modern GPUs
  • 1080p video: 300-500+ FPS
  • Real-time encoding for up to 8K

Troubleshooting

Error: Encoder not found

NVIDIA

  • Update GPU drivers to latest version
  • Verify GPU supports NVENC (GTX 600+)
  • Check that CUDA is installed
  • For AV1: Requires RTX 40 series

Apple

  • Requires macOS 10.13+
  • Verify Apple Silicon or T2 chip
  • Update macOS to latest version

Error: Hardware decode acceleration failed

  • Source video codec may not support hardware decode
  • Try disabling hwDecode option
  • Check GPU driver version
  • Verify sufficient VRAM available

Output quality is poor

  • Increase quality setting (50 → 60 → 70)
  • For NVENC: Enable Spatial AQ and Temporal AQ
  • Use slower preset (medium → slow → p7)
  • Consider software encoding for archival quality

See Also

Build docs developers (and LLMs) love