async clipify
This commit is contained in:
@@ -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> {
|
pub fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String> {
|
||||||
match screenshot_png(input, ts) {
|
match screenshot_png(input, ts) {
|
||||||
Ok(png) => {
|
Ok(png) => {
|
||||||
|
|||||||
@@ -207,18 +207,16 @@ async fn analyze(file: String) -> Analysis {
|
|||||||
|
|
||||||
async fn clipify(file: String, content_spans: Vec<lib::video::ContentSpan>) -> String {
|
async fn clipify(file: String, content_spans: Vec<lib::video::ContentSpan>) -> String {
|
||||||
let d = format!("{}.d", &file);
|
let d = format!("{}.d", &file);
|
||||||
match content_spans.iter()
|
let mut last_err = None;
|
||||||
.map(|content_span| {
|
for content_span in content_spans.iter() {
|
||||||
lib::video::clip(
|
let output = format!("{}/{}.mp4", &d, content_span.start);
|
||||||
&format!("{}/{}.mp4", &d, content_span.start),
|
let cur = lib::video::clip_async(&output, &file, *content_span).await;
|
||||||
&file,
|
if cur.is_err() {
|
||||||
*content_span,
|
last_err = Some(format!("failed to clipify {} at {}..{}: {}", &file, &content_span.start, &content_span.stop, cur.err().unwrap()));
|
||||||
)
|
}
|
||||||
})
|
}
|
||||||
.filter(|x| x.is_err())
|
match last_err {
|
||||||
.map(|x| x.err().unwrap())
|
Some(msg) => msg,
|
||||||
.nth(0) {
|
|
||||||
Some(err_msg) => err_msg,
|
|
||||||
None => {
|
None => {
|
||||||
match opener::open(d.clone()) {
|
match opener::open(d.clone()) {
|
||||||
Ok(_) => d,
|
Ok(_) => d,
|
||||||
|
|||||||
Reference in New Issue
Block a user