Files
VoelinClient/crates/voelin-media/src/codec/hw.rs
T
Claude 8b9ea9ca1d voelin-media: test FFmpeg encoders end to end, fix what that found
The self-test and a roundtrip through our own decoders (OpenH264 for
H.264, dav1d for AV1) run for every FFmpeg software encoder present:
x264, SVT-AV1, rav1e and libaom all decode above 28 dB PSNR with the
keyframes where they were asked for.

Fixes: SVT-AV1 takes CBR from rc=2 and rejects a maximum rate equal to
the target; rav1e refuses a keyframe interval of 2^30 and holds about 20
frames even in low-latency mode, so it is only used when named; a new
session flushes the old one so delayed frames are not lost; the first
packet of a session counts as a keyframe; FFmpeg's log lines go to the
encoder they are about when backends are tested in parallel.

Codecs::builtin() gives the compiled-in codecs alone, for tests that
check libvpx or OpenH264 specifically.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-28 19:30:29 +00:00

55 lines
1.8 KiB
Rust

//! Encoder factories found at runtime.
//!
//! - FFmpeg (feature `ffmpeg`, desktop): VA-API, NVENC, Quick Sync, AMF,
//! Media Foundation and VideoToolbox encoders, plus software ones FFmpeg
//! wraps (x264, OpenH264, SVT-AV1, rav1e, libaom); one factory per backend
//! that passed its self-test ([`crate::ffmpeg::probe`]).
//! - Android: MediaCodec ([`super::mediacodec`]).
use crate::Result;
use crate::codec::{Codec, EncoderBackend, EncoderConfig, VideoEncoder};
/// Creates encoders of one backend.
pub trait EncoderFactory: Send + Sync {
/// Short name for logs and settings (`"h264_vaapi"`, `"mediacodec"`).
fn name(&self) -> &'static str;
/// Codecs this backend encodes, best first.
fn codecs(&self) -> Vec<Codec>;
fn create(&self, codec: Codec, config: &EncoderConfig) -> Result<Box<dyn VideoEncoder>>;
/// A GPU / OS encoder (the default), as opposed to a software encoder
/// reached through the same API (FFmpeg's libx264, ...).
fn is_hardware(&self) -> bool {
true
}
/// Whether the automatic choice may use it (not for encoders with a long
/// delay; those are used only when named in the settings).
fn is_automatic(&self) -> bool {
true
}
/// The backend its encoders report.
fn backend(&self) -> EncoderBackend {
EncoderBackend::Hardware(self.name())
}
}
/// Encoder factories usable on this machine: FFmpeg's backends that passed
/// their self-test, then MediaCodec (Android).
pub fn probe() -> Vec<Box<dyn EncoderFactory>> {
#[allow(unused_mut)]
let mut found: Vec<Box<dyn EncoderFactory>> = Vec::new();
#[cfg(feature = "ffmpeg")]
for factory in crate::ffmpeg::FfmpegFactory::available() {
found.push(Box::new(factory));
}
#[cfg(target_os = "android")]
if let Some(f) = super::mediacodec::probe() {
found.push(Box::new(f));
}
found
}