use std::path::Path;
use std::process::Command;
pub fn has_encoder(ffmpeg: &Path, name: &str) -> bool {
Command::new(ffmpeg)
.args(["-hide_banner", "-encoders"])
.output()
.map(|o| {
let text = String::from_utf8_lossy(&o.stdout);
encoder_listed(&text, name)
})
.unwrap_or(false)
}
pub(crate) fn encoder_listed(listing: &str, name: &str) -> bool {
listing.lines().any(|line| {
let mut cols = line.split_whitespace();
let flags = cols.next().unwrap_or("");
flags.len() == 6 && cols.next() == Some(name)
})
}
#[cfg(test)]
mod tests {
use super::*;
const LISTING: &str = "Encoders:
V..... libx264 libx264 H.264 / AVC (codec h264)
V..... libsvtav1 SVT-AV1 encoder (codec av1)
A....D aac AAC (Advanced Audio Coding)
";
#[test]
fn finds_a_listed_encoder() {
assert!(encoder_listed(LISTING, "libsvtav1"));
assert!(encoder_listed(LISTING, "libx264"));
assert!(encoder_listed(LISTING, "aac"));
}
#[test]
fn rejects_absent_and_description_only_matches() {
assert!(!encoder_listed(LISTING, "libaom-av1"));
assert!(!encoder_listed(LISTING, "av1"));
assert!(!encoder_listed(LISTING, "Encoders:"));
}
}