async clipify

This commit is contained in:
Bel LaPointe
2023-12-28 17:30:09 -05:00
parent 68dd89ffc9
commit 6513dc09b4
2 changed files with 29 additions and 12 deletions

View File

@@ -67,6 +67,25 @@ pub fn clip(output: &String, input: &String, content_span: ContentSpan) -> Resul
}
}
pub async fn clip_async(output: &String, input: &String, content_span: ContentSpan) -> Result<(), String> {
fs::create_dir_all(Path::new(output).parent().unwrap()).unwrap();
match async_process::Command::new("ffmpeg")
.args([
"-y",
"-ss", &content_span.start.to_string(),
"-i", input,
"-t", &(content_span.stop - content_span.start).to_string(),
output,
])
.output().await {
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)),
}
}
pub fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> {
match screenshot_png(input, ts) {
Ok(png) => {