src-lib/video.rs pub is naisu

main
Bel LaPointe 2023-12-26 21:34:28 -05:00
parent 2928595812
commit 90569967c7
2 changed files with 20 additions and 14 deletions

View File

@ -1,4 +1,4 @@
mod ffmpeg; pub mod video;
pub fn add(left: usize, right: usize) -> usize { pub fn add(left: usize, right: usize) -> usize {
left + right left + right

View File

@ -1,13 +1,13 @@
use std::str::FromStr; use std::str::FromStr;
use core::cmp::Ordering; 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") match std::process::Command::new("ffmpeg")
.args([ .args([
"-y", "-y",
"-ss", &start.to_string(), "-ss", &content_span.start.to_string(),
"-i", input, "-i", input,
"-t", &(stop - start).to_string(), "-t", &(content_span.stop - content_span.start).to_string(),
output, output,
]) ])
.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") match std::process::Command::new("ffmpeg")
.args([ .args([
"-y", "-y",
@ -32,7 +32,14 @@ fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> {
} }
} }
fn inspect(file: &String) -> Result<Inspection, String> { pub fn inspect(file: &String) -> Result<Vec<ContentSpan>, String> {
match _inspect(file) {
Ok(inspection) => Ok(inspection.content_spans()),
Err(msg) => Err(msg)
}
}
fn _inspect(file: &String) -> Result<Inspection, String> {
match std::process::Command::new("ffmpeg") match std::process::Command::new("ffmpeg")
.args([ .args([
"-i", file, "-i", file,
@ -60,7 +67,7 @@ struct Inspection {
} }
impl Inspection { impl Inspection {
pub fn content_spans(&self) -> Vec<ContentSpan> { fn content_spans(&self) -> Vec<ContentSpan> {
self.overlap_spans( self.overlap_spans(
&self.visual_spans(), &self.visual_spans(),
&self.audible_spans(), &self.audible_spans(),
@ -203,7 +210,7 @@ mod test_inspection {
3.0, 3.0,
).unwrap(); ).unwrap();
let inspection = inspect(&output); let inspection = _inspect(&output);
assert_eq!(true, inspection.is_ok()); assert_eq!(true, inspection.is_ok());
let inspection = inspection.unwrap(); let inspection = inspection.unwrap();
assert_eq!(0.04, inspection.duration()); assert_eq!(0.04, inspection.duration());
@ -215,11 +222,10 @@ mod test_inspection {
clip( clip(
&output, &output,
&FILE.to_string(), &FILE.to_string(),
3.0, ContentSpan{start: 3.0, stop: 5.0},
5.0,
).unwrap(); ).unwrap();
let inspection = inspect(&output); let inspection = _inspect(&output);
assert_eq!(true, inspection.is_ok()); assert_eq!(true, inspection.is_ok());
let inspection = inspection.unwrap(); let inspection = inspection.unwrap();
assert_eq!(2.0, inspection.duration()); assert_eq!(2.0, inspection.duration());
@ -227,7 +233,7 @@ mod test_inspection {
#[test] #[test]
fn test_inspect() { fn test_inspect() {
let inspection = inspect(&FILE.to_string()); let inspection = _inspect(&FILE.to_string());
assert_eq!(true, inspection.is_ok()); assert_eq!(true, inspection.is_ok());
let inspection = inspection.unwrap(); let inspection = inspection.unwrap();
@ -261,8 +267,8 @@ mod test_inspection {
#[derive(Debug, PartialEq, Clone, Copy, PartialOrd)] #[derive(Debug, PartialEq, Clone, Copy, PartialOrd)]
pub struct ContentSpan { pub struct ContentSpan {
start: f32, pub start: f32,
stop: f32, pub stop: f32,
} }
impl ContentSpan { impl ContentSpan {