diff --git a/src-lib/src/video.rs b/src-lib/src/video.rs index c9c245e..6ca64f9 100644 --- a/src-lib/src/video.rs +++ b/src-lib/src/video.rs @@ -1,5 +1,24 @@ use std::str::FromStr; use core::cmp::Ordering; +use std::fs; + +pub fn clipify(input: &String) -> Result, String> { + match inspect(input) { + Ok(inspection) => { + let output_d = format!("{}.d", input); + fs::create_dir_all(&output_d).unwrap(); + let ext = input.split(".").last().unwrap(); + let mut result = vec![]; + for i in 0..inspection.len() { + let output = format!("{}/{}.{}", output_d, i, ext); + let _ = clip(&output, input, inspection[i])?; + result.push(output); + } + Ok(result) + }, + Err(msg) => Err(msg), + } +} pub fn clip(output: &String, input: &String, content_span: ContentSpan) -> Result<(), String> { match std::process::Command::new("ffmpeg") @@ -11,7 +30,10 @@ pub fn clip(output: &String, input: &String, content_span: ContentSpan) -> Resul output, ]) .output() { - Ok(_) => Ok(()), + Ok(output) => match output.status.success() { + true => Ok(()), + false => Err(format!("failed to ffmpeg clip {}: {}", input, String::from_utf8(output.stderr).unwrap())), + }, Err(msg) => Err(format!("failed to ffmpeg clip {}: {}", input, msg)), } } @@ -201,6 +223,14 @@ mod test_inspection { use super::*; const FILE: &str = "/Users/breel/Movies/bel_1_1.mp4"; + #[test] + fn test_clipify() { + let result = clipify(&FILE.to_string()).unwrap(); + for i in result.iter() { + eprintln!("{}", i); + } + } + #[test] fn test_screenshot() { let output = format!("{}.clipped.jpg", FILE);