revert
parent
96369424b3
commit
89142d69b1
|
|
@ -52,8 +52,6 @@ fn ify(input: &String, mut cb: impl FnMut(ContentSpan) -> Result<(), String>) ->
|
||||||
pub fn clip(output: &String, input: &String, content_span: ContentSpan) -> Result<(), String> {
|
pub fn clip(output: &String, input: &String, content_span: ContentSpan) -> Result<(), String> {
|
||||||
fs::create_dir_all(Path::new(output).parent().unwrap()).unwrap();
|
fs::create_dir_all(Path::new(output).parent().unwrap()).unwrap();
|
||||||
match std::process::Command::new("ffmpeg")
|
match std::process::Command::new("ffmpeg")
|
||||||
.stdin(std::process::Stdio::null())
|
|
||||||
.stdout(std::process::Stdio::inherit())
|
|
||||||
.args([
|
.args([
|
||||||
"-y",
|
"-y",
|
||||||
"-ss", &content_span.start.to_string(),
|
"-ss", &content_span.start.to_string(),
|
||||||
|
|
@ -87,8 +85,6 @@ pub fn screenshot(output: &String, input: &String, ts: f32) -> Result<(), String
|
||||||
|
|
||||||
pub fn screenshot_png(input: &String, ts: f32) -> Result<Vec<u8>, String> {
|
pub fn screenshot_png(input: &String, ts: f32) -> Result<Vec<u8>, String> {
|
||||||
match std::process::Command::new("ffmpeg")
|
match std::process::Command::new("ffmpeg")
|
||||||
.stdin(std::process::Stdio::null())
|
|
||||||
.stdout(std::process::Stdio::inherit())
|
|
||||||
.args([
|
.args([
|
||||||
"-y",
|
"-y",
|
||||||
"-ss", &ts.to_string(),
|
"-ss", &ts.to_string(),
|
||||||
|
|
@ -113,11 +109,7 @@ pub fn inspect(file: &String) -> Result<Vec<ContentSpan>, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _inspect(file: &String) -> Result<Inspection, String> {
|
fn _inspect(file: &String) -> Result<Inspection, String> {
|
||||||
let mut bind = std::process::Command::new("ffmpeg");
|
match std::process::Command::new("ffmpeg")
|
||||||
let cmd = bind
|
|
||||||
.stdin(std::process::Stdio::null())
|
|
||||||
.stdout(std::process::Stdio::piped())
|
|
||||||
.stderr(std::process::Stdio::piped())
|
|
||||||
.args([
|
.args([
|
||||||
"-i", file,
|
"-i", file,
|
||||||
"-vf", "mpdecimate",
|
"-vf", "mpdecimate",
|
||||||
|
|
@ -125,42 +117,19 @@ fn _inspect(file: &String) -> Result<Inspection, String> {
|
||||||
"-loglevel", "debug",
|
"-loglevel", "debug",
|
||||||
"-f", "null",
|
"-f", "null",
|
||||||
"-",
|
"-",
|
||||||
]);
|
])
|
||||||
|
.output() {
|
||||||
let mut child = cmd.spawn().expect("failed to inspect with ffmpeg");
|
Ok(output) => {
|
||||||
let mut bind = vec![0; 10];
|
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||||
let mut buff: &mut [u8] = bind.as_mut();
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||||
let mut _stdout = child.stdout.take().unwrap();
|
|
||||||
let mut _stderr = child.stderr.take().unwrap();
|
|
||||||
let mut stdout: Vec<u8> = vec![];
|
|
||||||
let mut stderr: Vec<u8> = vec![];
|
|
||||||
let mut delay = 100;
|
|
||||||
while let Ok(None) = child.try_wait() {
|
|
||||||
eprintln!("ffmpeg still inspecting...");
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(delay));
|
|
||||||
delay = (2 * delay).clamp(0, 5000);
|
|
||||||
eprintln!("ffmpeg stdout...");
|
|
||||||
match _stdout.read(buff.as_mut()) {
|
|
||||||
Ok(n) => { buff[..n].iter().for_each(|c| stdout.push(*c)); },
|
|
||||||
Err(_) => {},
|
|
||||||
};
|
|
||||||
eprintln!("ffmpeg stderr...");
|
|
||||||
match _stderr.read(buff.as_mut()) {
|
|
||||||
Ok(n) => { buff[..n].iter().for_each(|c| stderr.push(*c)); },
|
|
||||||
Err(_) => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
child.wait().expect("failed to wait for inspect with ffmpeg");
|
|
||||||
|
|
||||||
child.stderr.as_mut().unwrap().read_to_end(&mut stderr).unwrap();
|
|
||||||
child.stdout.as_mut().unwrap().read_to_end(&mut stdout).unwrap();
|
|
||||||
|
|
||||||
let stderr = String::from_utf8(stderr).unwrap();
|
|
||||||
let stdout = String::from_utf8(stdout).unwrap();
|
|
||||||
let line_iter = stderr.split("\n").chain(stdout.split("\n"));
|
let line_iter = stderr.split("\n").chain(stdout.split("\n"));
|
||||||
Ok(Inspection{
|
Ok(Inspection{
|
||||||
lines: line_iter.map(|x| x.to_string()).collect(),
|
lines: line_iter.map(|x| x.to_string()).collect(),
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
Err(msg) => Err(format!("failed to inspect with ffmpeg: {}", msg)),
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Inspection {
|
struct Inspection {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue