impl ffmpeg.screenshot too

This commit is contained in:
Bel LaPointe
2023-12-26 21:28:53 -05:00
parent e0ababb7b6
commit 2928595812

View File

@@ -16,6 +16,22 @@ fn clip(output: &String, input: &String, start: f32, stop: f32) -> Result<(), St
}
}
fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> {
match std::process::Command::new("ffmpeg")
.args([
"-y",
"-ss", &ts.to_string(),
"-i", input,
"-frames:v", "1",
"-q:v", "2",
output,
])
.output() {
Ok(_) => Ok(()),
Err(msg) => Err(format!("failed to ffmpeg screenshot {}: {}", input, msg)),
}
}
fn inspect(file: &String) -> Result<Inspection, String> {
match std::process::Command::new("ffmpeg")
.args([
@@ -178,6 +194,21 @@ mod test_inspection {
use super::*;
const FILE: &str = "/Users/breel/Movies/bel_1_1.mp4";
#[test]
fn test_screenshot() {
let output = format!("{}.clipped.jpg", FILE);
screenshot(
&output,
&FILE.to_string(),
3.0,
).unwrap();
let inspection = inspect(&output);
assert_eq!(true, inspection.is_ok());
let inspection = inspection.unwrap();
assert_eq!(0.04, inspection.duration());
}
#[test]
fn test_clip() {
let output = format!("{}.clipped.mp4", FILE);