Skip to main content

default_order

Function default_order 

Source
pub fn default_order(codec: Codec) -> Vec<EncoderKind>
Expand description

The order open_best_encoder tries by default for codec on this operating system: the hardware encoders that exist here, best first, then software.

Examples found in repository?
examples/encode_decode.rs (line 31)
22fn main() -> AnyResult<()> {
23    let config = EncoderConfig::new(WIDTH, HEIGHT, FPS, BITRATE_KBPS);
24    for (name, codec) in [("AV1", Codec::Av1), ("VP9", Codec::Vp9)] {
25        round_trip(name, codec, &config)?;
26    }
27
28    println!();
29    for (name, codec) in [("AV1", Codec::Av1), ("VP9", Codec::Vp9)] {
30        // The default order: the hardware encoders of this operating system, then software.
31        let order: Vec<String> = default_order(codec)
32            .iter()
33            .map(ToString::to_string)
34            .collect();
35        let (kind, _encoder) = open_best_encoder(codec, &config, None)?;
36        println!("{name} default order [{}] opened: {kind}", order.join(", "));
37
38        // A custom order: software first, so hardware is never tried.
39        let software_first = [
40            EncoderKind::Software,
41            EncoderKind::Hardware(HardwareEncoder::Vaapi),
42            EncoderKind::Hardware(HardwareEncoder::Nvenc),
43        ];
44        let (kind, _encoder) = open_best_encoder(codec, &config, Some(&software_first))?;
45        println!("{name} software-first order opened: {kind}");
46    }
47    Ok(())
48}