Overview
Hardware acceleration uses dedicated GPU encoders (VideoToolbox on macOS, NVENC on NVIDIA, etc.) to dramatically speed up video encoding while reducing CPU load. This is particularly beneficial for large video batches or high-resolution content.Hardware acceleration is enabled by default (
--video-acceleration=true). The converter automatically detects available encoders and falls back to software encoding if unavailable.Supported Platforms
macOS (VideoToolbox)
Appleβs hardware encoder for H.265/HEVC:- Codec:
hevc_videotoolbox - Detection: Checks FFmpeg encoders via
ffmpeg -encoders - Output Tag:
hvc1(for better QuickTime compatibility) - Performance: 3-5x faster than software encoding
- Quality: Bitrate-based (CRF not supported)
- Intel Macs with Quick Sync (2011+)
- Apple Silicon (M1/M2/M3) with dedicated media engines
Linux/Windows (Future Support)
Currently not implemented but planned:- NVIDIA NVENC (H.264/H.265)
- AMD VCE (H.264/H.265)
- Intel Quick Sync (H.264/H.265/AV1)
The codebase is architected to support additional encoders. Contributions for NVENC/VCE support are welcome!
How It Works
Acceleration Detection (video.go:482-514)
On first video conversion, the system:
- Checks if
--video-accelerationis enabled - Calls
utils.CheckVideoAcceleration()to probe FFmpeg encoders - Verifies
hevc_videotoolboxis available - Caches result for subsequent conversions (via
sync.Once)
Encoding Profile Selection (video.go:39-104)
The buildVideoEncodingProfile() function determines encoding parameters:
Hardware Acceleration Path:
Bitrate Estimation
Hardware encoders donβt support CRF (Constant Rate Factor), so the converter estimates appropriate bitrates based on source characteristics (video.go:130-152):
Algorithm
Example Calculations
| Source File | File Size | Duration | Source Bitrate | Target Bitrate | Buffer Size |
|---|---|---|---|---|---|
| 4K video | 500 MB | 60s | 66.7 Mbps | 43.4 Mbps | 86.7 Mbps |
| 1080p video | 100 MB | 60s | 13.3 Mbps | 8.7 Mbps | 17.3 Mbps |
| Low quality | 10 MB | 60s | 1.3 Mbps | 2.5 Mbps | 5.0 Mbps |
Configuration
Enable/Disable Hardware Acceleration
Enable hardware acceleration for video encoding
~/.media-converter.yaml
Force Software Encoding
Use cases for disabling hardware acceleration:- Maximum Quality - Software encoders offer finer quality control via CRF
- Archival - Bit-perfect reproduction with
--video-crf 18 - Compatibility - Some hardware encoders have platform-specific quirks
- Testing - Compare quality/performance between methods
FFmpeg Command Construction
When hardware acceleration is enabled, the converter builds specialized FFmpeg arguments (video.go:230-254):
Hardware Encoding Command
Software Encoding Command
Performance Comparison
Encoding Speed
Benchmark: 4K 60fps video (500 MB, 60 seconds) on M2 MacBook Pro:| Method | Encoder | Time | Speed | CPU Usage |
|---|---|---|---|---|
| Hardware | hevc_videotoolbox | 12s | 5.0x | 15-20% |
| Software | libx265 (medium) | 58s | 1.0x | 95-100% |
| Software | libx265 (fast) | 42s | 1.4x | 95-100% |
Quality Comparison
Based on visual inspection and VMAF scores:- Hardware (8.5 Mbps): VMAF 92-95, excellent for general use
- Software (CRF 28): VMAF 93-96, slightly better detail preservation
- Software (CRF 20): VMAF 96-98, near-lossless archival quality
For most use cases, hardware acceleration provides the best balance of speed and quality. Use software encoding for archival or when quality is paramount.
Logging and Monitoring
The converter logs encoding method decisions:Hardware Acceleration Available
Software Fallback
Acceleration Unavailable
Troubleshooting
Hardware Acceleration Not Detected
Check FFmpeg Support:hevc_videotoolbox is missing, reinstall FFmpeg with VideoToolbox support:
Poor Quality with Hardware Encoding
Problem: Output looks blocky or pixelated Solutions:- Source bitrate was very low (< 5 Mbps) - switch to software encoding
- Increase target bitrate by editing
estimateHardwareBitrate()factor:
Conversion Slower Than Expected
Check:- Verify hardware encoding is actually being used (check logs)
- Ensure
--adaptive-workersisnβt limiting concurrency - Monitor system resources - thermal throttling can reduce encoder speed
- Disable other GPU-intensive applications
Codec-Specific Behavior
H.265 (HEVC) - Default
Hardware:hevc_videotoolbox (macOS only)
Software: libx265 with CRF 28
Use Case: Best balance of compatibility and compression
H.264 (AVC)
Hardware: Not implemented (always uses software) Software:libx264 with CRF 23
Use Case: Maximum compatibility with older devices
AV1
Hardware: Not implemented (always uses software) Software:libaom-av1 with CRF 35
Use Case: Maximum compression for archival/streaming
AV1 encoding is extremely slow (5-10x slower than H.265 software encoding). Only recommended for final archival encodes where file size is critical.
Future Enhancements
Planned hardware acceleration support:- NVIDIA NVENC (Linux/Windows) - H.264/H.265/AV1
- Intel Quick Sync (Cross-platform) - H.264/H.265/AV1
- AMD VCE (Linux/Windows) - H.264/H.265
- Apple VideoToolbox AV1 (macOS 14+)
Contributions welcome! See
internal/converter/video.go for implementation patterns.Related Configuration
Adaptive Workers
Dynamic concurrency management for video conversions
Performance Tuning
Optimize conversion speed and resource usage