pub fn open_software_decoder(codec: Codec) -> Result<Box<dyn VideoDecoder>>Expand description
Opens the software decoder for codec (dav1d for AV1, libvpx for VP9).
Examples found in repository?
examples/encode_decode.rs (line 53)
51fn round_trip(name: &str, codec: Codec, config: &EncoderConfig) -> AnyResult<()> {
52 let (_, mut encoder) = open_best_encoder(codec, config, Some(&[EncoderKind::Software]))?;
53 let mut decoder = open_software_decoder(codec)?;
54 let mut bytes = 0;
55 let mut decoded_frames = 0;
56 let mut worst_psnr = f64::INFINITY;
57 for index in 0..FRAMES {
58 let bgra = screen_like_bgra(WIDTH, HEIGHT, index);
59 let frame = convert::bgra_to_i420(&bgra, WIDTH, HEIGHT, WIDTH, HEIGHT)
60 .ok_or("the picture does not fit the encoder size")?;
61 let pts = i64::from(index * 1000 / FPS);
62 for packet in encoder.encode(&frame, pts, false)? {
63 bytes += packet.data.len();
64 let Some(decoded) = decoder.decode(&packet.data)? else {
65 continue;
66 };
67 if (decoded.width(), decoded.height()) != (frame.width(), frame.height()) {
68 return Err(format!(
69 "{name}: decoded {}x{} instead of {}x{}",
70 decoded.width(),
71 decoded.height(),
72 frame.width(),
73 frame.height()
74 )
75 .into());
76 }
77 decoded_frames += 1;
78 // The first pictures are still sharpening while the rate control settles.
79 if index >= FRAMES / 2 {
80 worst_psnr = worst_psnr.min(luma_psnr(&frame, &decoded));
81 }
82 }
83 }
84 if decoded_frames != FRAMES {
85 return Err(format!("{name}: {decoded_frames} of {FRAMES} pictures came back").into());
86 }
87 if worst_psnr < MIN_PSNR_DB {
88 return Err(format!("{name}: picture quality too low ({worst_psnr:.1} dB)").into());
89 }
90 println!(
91 "{name}: {FRAMES} pictures {WIDTH}x{HEIGHT} encoded to {} kB and decoded again, \
92 luma PSNR at least {worst_psnr:.1} dB – ok",
93 bytes / 1000
94 );
95 Ok(())
96}