From e0ababb7b636ef627f1c3db2d15319ad8e5c169c Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 26 Dec 2023 21:26:48 -0500 Subject: [PATCH] clipped k --- src-lib/src/ffmpeg.rs | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src-lib/src/ffmpeg.rs b/src-lib/src/ffmpeg.rs index 0db4fd9..7bdf6ef 100644 --- a/src-lib/src/ffmpeg.rs +++ b/src-lib/src/ffmpeg.rs @@ -1,6 +1,21 @@ use std::str::FromStr; use core::cmp::Ordering; +fn clip(output: &String, input: &String, start: f32, stop: f32) -> Result<(), String> { + match std::process::Command::new("ffmpeg") + .args([ + "-y", + "-ss", &start.to_string(), + "-i", input, + "-t", &(stop - start).to_string(), + output, + ]) + .output() { + Ok(_) => Ok(()), + Err(msg) => Err(format!("failed to ffmpeg clip {}: {}", input, msg)), + } +} + fn inspect(file: &String) -> Result { match std::process::Command::new("ffmpeg") .args([ @@ -20,7 +35,7 @@ fn inspect(file: &String) -> Result { lines: line_iter.map(|x| x.to_string()).collect(), }) }, - Err(msg) => Err(format!("failed to ffmpeg {}: {}", file, msg)), + Err(msg) => Err(format!("failed to ffmpeg inspect {}: {}", file, msg)), } } @@ -161,11 +176,27 @@ impl Inspection { #[cfg(test)] mod test_inspection { use super::*; + const FILE: &str = "/Users/breel/Movies/bel_1_1.mp4"; + + #[test] + fn test_clip() { + let output = format!("{}.clipped.mp4", FILE); + clip( + &output, + &FILE.to_string(), + 3.0, + 5.0, + ).unwrap(); + + let inspection = inspect(&output); + assert_eq!(true, inspection.is_ok()); + let inspection = inspection.unwrap(); + assert_eq!(2.0, inspection.duration()); + } #[test] fn test_inspect() { - let file = "/Users/breel/Movies/bel_1_1.mp4".to_string(); - let inspection = inspect(&file); + let inspection = inspect(&FILE.to_string()); assert_eq!(true, inspection.is_ok()); let inspection = inspection.unwrap();