add lib::video::inspect_async
This commit is contained in:
@@ -131,6 +131,36 @@ fn _inspect(file: &String) -> Result<Inspection, String> {
|
||||
|
||||
}
|
||||
|
||||
pub async fn inspect_async(file: &String) -> Result<Vec<ContentSpan>, String> {
|
||||
match _inspect_async(file).await {
|
||||
Ok(inspection) => Ok(inspection.content_spans()),
|
||||
Err(msg) => Err(msg)
|
||||
}
|
||||
}
|
||||
|
||||
async fn _inspect_async(file: &String) -> Result<Inspection, String> {
|
||||
match async_process::Command::new("ffmpeg")
|
||||
.args([
|
||||
"-i", file,
|
||||
"-vf", "mpdecimate,select='gt(scene,0.0)'",
|
||||
"-af", "silencedetect=n=-50dB:d=1",
|
||||
"-loglevel", "debug",
|
||||
"-f", "null",
|
||||
"-",
|
||||
])
|
||||
.output().await {
|
||||
Ok(output) => {
|
||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
let line_iter = stderr.split("\n").chain(stdout.split("\n"));
|
||||
Ok(Inspection{
|
||||
lines: line_iter.map(|x| x.to_string()).collect(),
|
||||
})
|
||||
},
|
||||
Err(msg) => Err(format!("failed to inspect with ffmpeg: {}", msg)),
|
||||
}
|
||||
}
|
||||
|
||||
struct Inspection {
|
||||
lines: Vec<String>,
|
||||
}
|
||||
@@ -352,8 +382,9 @@ mod test_inspection {
|
||||
|
||||
assert_eq!(28.14, inspection.duration());
|
||||
|
||||
assert_eq!(1, inspection.visual_transitions_scene_splits().len()); // TODO
|
||||
assert_eq!(0.65986, inspection.visual_transitions_scene_splits()[0]); // TODO
|
||||
assert_eq!(2, inspection.visual_transitions_scene_splits().len()); // TODO
|
||||
assert_eq!(0.307763, inspection.visual_transitions_scene_splits()[0]); // TODO
|
||||
assert_eq!(0.65986, inspection.visual_transitions_scene_splits()[1]); // TODO
|
||||
|
||||
assert_eq!(4, inspection.visual_transitions_unstuck_frames().len());
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user