deepshrink_ffmpeg/
caps.rs1use std::path::Path;
9use std::process::Command;
10
11pub fn has_encoder(ffmpeg: &Path, name: &str) -> bool {
16 Command::new(ffmpeg)
17 .args(["-hide_banner", "-encoders"])
18 .output()
19 .map(|o| {
20 let text = String::from_utf8_lossy(&o.stdout);
21 encoder_listed(&text, name)
22 })
23 .unwrap_or(false)
24}
25
26pub(crate) fn encoder_listed(listing: &str, name: &str) -> bool {
29 listing.lines().any(|line| {
30 let mut cols = line.split_whitespace();
32 let flags = cols.next().unwrap_or("");
33 flags.len() == 6 && cols.next() == Some(name)
35 })
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 const LISTING: &str = "Encoders:
43 V..... libx264 libx264 H.264 / AVC (codec h264)
44 V..... libsvtav1 SVT-AV1 encoder (codec av1)
45 A....D aac AAC (Advanced Audio Coding)
46";
47
48 #[test]
49 fn finds_a_listed_encoder() {
50 assert!(encoder_listed(LISTING, "libsvtav1"));
51 assert!(encoder_listed(LISTING, "libx264"));
52 assert!(encoder_listed(LISTING, "aac"));
53 }
54
55 #[test]
56 fn rejects_absent_and_description_only_matches() {
57 assert!(!encoder_listed(LISTING, "libaom-av1"));
58 assert!(!encoder_listed(LISTING, "av1"));
60 assert!(!encoder_listed(LISTING, "Encoders:"));
61 }
62}