ff-encode
Safe, high-level video and audio encoding — no unsafe code required, LGPL-compliant by default.
Overview
All APIs are safe — FFmpeg internals are fully encapsulated so you never need to write unsafe code.
⚖️ License & Commercial Use
This crate is designed for commercial use without licensing fees.
Default Behavior (LGPL-Compatible) ✅
By default, ff-encode only uses LGPL-compatible encoders, making it safe for commercial use:
- ✅ Free for commercial use - No licensing fees
- ✅ No royalty payments required
- ✅ Safe for proprietary software
- ✅ No GPL contamination
How It Works
When you request H.264 or H.265 encoding, the crate automatically selects encoders in this priority:
-
Hardware encoders (LGPL-compatible):
- NVIDIA NVENC (
h264_nvenc,hevc_nvenc) - Intel Quick Sync Video (
h264_qsv,hevc_qsv) - AMD AMF/VCE (
h264_amf,hevc_amf) - Apple VideoToolbox (
h264_videotoolbox,hevc_videotoolbox) - VA-API (
h264_vaapi,hevc_vaapi) - Linux
- NVIDIA NVENC (
-
Fallback to royalty-free codecs:
- H.264 → VP9 (libvpx-vp9)
- H.265 → AV1 (libaom-av1)
GPL Feature ⚠️
The gpl feature enables libx264/libx265 software encoders, which require licensing fees for commercial distribution:
# WARNING: Requires GPL compliance and MPEG LA licensing for commercial use
= { = "0.1", = ["gpl"] }
Only enable gpl if:
- ✅ You have appropriate licenses from MPEG LA, or
- ✅ Your software is GPL-licensed (open source), or
- ✅ For non-commercial/educational use only
📦 Installation
[]
# Default: LGPL-compatible (commercial use OK)
= "0.1"
# With GPU acceleration (recommended)
= { = "0.1", = ["hwaccel"] }
# With GPL codecs (requires licensing)
= { = "0.1", = ["gpl"] }
🚀 Quick Start
use ;
// Create encoder - will automatically use LGPL-compatible encoder
let mut encoder = create?
.video
.video_codec // Will use hardware or VP9
.audio
.audio_codec
.build?;
// Verify LGPL compliance
println!;
println!;
// Encode frames
for frame in video_frames
encoder.finish?;
🔍 Checking Compliance at Runtime
let encoder = create?
.video
.video_codec
.build?;
if encoder.is_lgpl_compliant else
Example outputs:
✓ Safe for commercial use: h264_nvenc- NVIDIA hardware encoder✓ Safe for commercial use: libvpx-vp9- VP9 fallback⚠ GPL encoder: libx264- Requires licensing (only withgplfeature)
📚 Features
Video Codecs
- H.264/AVC - Most compatible (auto-selects hardware or VP9 fallback)
- H.265/HEVC - High compression (auto-selects hardware or AV1 fallback)
- VP9 - Google's royalty-free codec (LGPL-compatible)
- AV1 - Next-gen royalty-free codec (LGPL-compatible)
- ProRes - Apple's professional codec
- DNxHD - Avid's professional codec
Audio Codecs
- AAC - Most compatible
- Opus - High quality, low latency
- MP3 - Universal compatibility
- FLAC - Lossless
- PCM - Uncompressed
Hardware Acceleration
All hardware encoders are LGPL-compatible:
use HardwareEncoder;
let encoder = create?
.video
.hardware_encoder // Force NVIDIA
.build?;
// Check available hardware
for hw in available
⚡ Performance
Encoding Presets
use Preset;
let encoder = create?
.video
.preset // Faster encoding, larger file
.build?;
Available presets:
Ultrafast- Fastest, lowest qualityFast/Faster- Good for real-timeMedium- Default, balancedSlow/Slower/Veryslow- Best quality
Quality Control
// Constant bitrate
let encoder = create?
.video
.video_bitrate // 8 Mbps
.build?;
// Constant quality (CRF)
let encoder = create?
.video
.video_quality // 0-51, lower = better
.build?;
📊 Progress Tracking
use Progress;
let encoder = create?
.video
.on_progress
.build?;
🛡️ Safety & Error Handling
All operations use proper error types:
use EncodeError;
match create
🔧 Advanced Usage
Force VP9 (Always LGPL-Compatible)
let encoder = create?
.video
.video_codec // Explicit VP9
.build?;
Disable Hardware Acceleration
let encoder = create?
.video
.hardware_encoder // Software only
.build?;
// Will use VP9 or AV1 (LGPL-compatible)
📜 License
This crate: MIT OR Apache-2.0
FFmpeg: LGPL 2.1+ (or GPL 2+ with gpl feature)
Important: The default configuration (without gpl feature) is LGPL-compliant and safe for commercial use without licensing fees.
❓ FAQ
Q: Can I use this in my commercial product?
A: Yes! By default (without the gpl feature), all encoders are LGPL-compatible and free for commercial use.
Q: What if I need libx264/libx265?
A: Enable the gpl feature, but be aware:
- You must comply with GPL license terms, or
- Obtain commercial licenses from MPEG LA for H.264/H.265
Q: What's the quality difference between hardware and software encoding?
A: Modern hardware encoders (NVENC, QSV) have excellent quality, often comparable to software encoders at similar bitrates. VP9 and AV1 provide better compression than H.264 but require more CPU time.
Q: Which hardware encoder should I use?
A: Use HardwareEncoder::Auto (default) to automatically select the best available hardware encoder. The encoder will try NVENC → QSV → AMF → VideoToolbox in order.