From 90569967c74c1ef687453d6c08f0a071e017b83d Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 26 Dec 2023 21:34:28 -0500 Subject: [PATCH] src-lib/video.rs pub is naisu --- src-lib/src/lib.rs | 2 +- src-lib/src/{ffmpeg.rs => video.rs} | 32 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 14 deletions(-) rename src-lib/src/{ffmpeg.rs => video.rs} (90%) diff --git a/src-lib/src/lib.rs b/src-lib/src/lib.rs index 2ce735b..a31391f 100644 --- a/src-lib/src/lib.rs +++ b/src-lib/src/lib.rs @@ -1,4 +1,4 @@ -mod ffmpeg; +pub mod video; pub fn add(left: usize, right: usize) -> usize { left + right diff --git a/src-lib/src/ffmpeg.rs b/src-lib/src/video.rs similarity index 90% rename from src-lib/src/ffmpeg.rs rename to src-lib/src/video.rs index 659e413..c9c245e 100644 --- a/src-lib/src/ffmpeg.rs +++ b/src-lib/src/video.rs @@ -1,13 +1,13 @@ use std::str::FromStr; use core::cmp::Ordering; -fn clip(output: &String, input: &String, start: f32, stop: f32) -> Result<(), String> { +pub fn clip(output: &String, input: &String, content_span: ContentSpan) -> Result<(), String> { match std::process::Command::new("ffmpeg") .args([ "-y", - "-ss", &start.to_string(), + "-ss", &content_span.start.to_string(), "-i", input, - "-t", &(stop - start).to_string(), + "-t", &(content_span.stop - content_span.start).to_string(), output, ]) .output() { @@ -16,7 +16,7 @@ fn clip(output: &String, input: &String, start: f32, stop: f32) -> Result<(), St } } -fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> { +pub fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> { match std::process::Command::new("ffmpeg") .args([ "-y", @@ -32,7 +32,14 @@ fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> { } } -fn inspect(file: &String) -> Result { +pub fn inspect(file: &String) -> Result, String> { + match _inspect(file) { + Ok(inspection) => Ok(inspection.content_spans()), + Err(msg) => Err(msg) + } +} + +fn _inspect(file: &String) -> Result { match std::process::Command::new("ffmpeg") .args([ "-i", file, @@ -60,7 +67,7 @@ struct Inspection { } impl Inspection { - pub fn content_spans(&self) -> Vec { + fn content_spans(&self) -> Vec { self.overlap_spans( &self.visual_spans(), &self.audible_spans(), @@ -203,7 +210,7 @@ mod test_inspection { 3.0, ).unwrap(); - let inspection = inspect(&output); + let inspection = _inspect(&output); assert_eq!(true, inspection.is_ok()); let inspection = inspection.unwrap(); assert_eq!(0.04, inspection.duration()); @@ -215,11 +222,10 @@ mod test_inspection { clip( &output, &FILE.to_string(), - 3.0, - 5.0, + ContentSpan{start: 3.0, stop: 5.0}, ).unwrap(); - let inspection = inspect(&output); + let inspection = _inspect(&output); assert_eq!(true, inspection.is_ok()); let inspection = inspection.unwrap(); assert_eq!(2.0, inspection.duration()); @@ -227,7 +233,7 @@ mod test_inspection { #[test] fn test_inspect() { - let inspection = inspect(&FILE.to_string()); + let inspection = _inspect(&FILE.to_string()); assert_eq!(true, inspection.is_ok()); let inspection = inspection.unwrap(); @@ -261,8 +267,8 @@ mod test_inspection { #[derive(Debug, PartialEq, Clone, Copy, PartialOrd)] pub struct ContentSpan { - start: f32, - stop: f32, + pub start: f32, + pub stop: f32, } impl ContentSpan {