clipped k
parent
75534a383c
commit
e0ababb7b6
|
|
@ -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<Inspection, String> {
|
||||
match std::process::Command::new("ffmpeg")
|
||||
.args([
|
||||
|
|
@ -20,7 +35,7 @@ fn inspect(file: &String) -> Result<Inspection, String> {
|
|||
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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue