From 29285958123f0e8b99e479bb82427f9ea0eff242 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 26 Dec 2023 21:28:53 -0500 Subject: [PATCH] impl ffmpeg.screenshot too --- src-lib/src/ffmpeg.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src-lib/src/ffmpeg.rs b/src-lib/src/ffmpeg.rs index 7bdf6ef..659e413 100644 --- a/src-lib/src/ffmpeg.rs +++ b/src-lib/src/ffmpeg.rs @@ -16,6 +16,22 @@ fn clip(output: &String, input: &String, start: f32, stop: f32) -> Result<(), St } } +fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> { + match std::process::Command::new("ffmpeg") + .args([ + "-y", + "-ss", &ts.to_string(), + "-i", input, + "-frames:v", "1", + "-q:v", "2", + output, + ]) + .output() { + Ok(_) => Ok(()), + Err(msg) => Err(format!("failed to ffmpeg screenshot {}: {}", input, msg)), + } +} + fn inspect(file: &String) -> Result { match std::process::Command::new("ffmpeg") .args([ @@ -178,6 +194,21 @@ mod test_inspection { use super::*; const FILE: &str = "/Users/breel/Movies/bel_1_1.mp4"; + #[test] + fn test_screenshot() { + let output = format!("{}.clipped.jpg", FILE); + screenshot( + &output, + &FILE.to_string(), + 3.0, + ).unwrap(); + + let inspection = inspect(&output); + assert_eq!(true, inspection.is_ok()); + let inspection = inspection.unwrap(); + assert_eq!(0.04, inspection.duration()); + } + #[test] fn test_clip() { let output = format!("{}.clipped.mp4", FILE);