From 2496539fded05bbf450fa31fc8004a8295c21d3a Mon Sep 17 00:00:00 2001 From: accuwau <84167166+accuwau@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:34:31 -0400 Subject: [PATCH] fix non-mp4 file support --- Cargo.lock | 2 +- src/encoder.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f673fa..e059254 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,7 +252,7 @@ dependencies = [ [[package]] name = "n-mb" -version = "1.1.0" +version = "1.1.1" dependencies = [ "anyhow", "clap", diff --git a/src/encoder.rs b/src/encoder.rs index bd24a2f..bad08ca 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -367,12 +367,39 @@ async fn parse_ffprobe(path: &PathBuf) -> anyhow::Result { let width = mem.first().and_then(|v| v.parse::().ok()); let height = mem.get(1).and_then(|v| v.parse::().ok()); + + let ffprobe = Command::new("ffprobe") + .args([ + "-v", + "error", + "-select_streams", + "v:0", + "-show_entries", + "format=duration,bit_rate", + "-of", + "csv=s=,:p=0", + ]) + .arg(path) + .stderr(Stdio::piped()) + .output() + .await?; + ffprobe + .status + .exit_ok() + .context("Failed to run ffprobe. Make sure ffprobe is installed and file exists")?; + + + + let text = std::str::from_utf8(&ffprobe.stdout)?; + + let mem = text.split(',').collect::>(); + let duration = mem - .get(2) + .get(0) .and_then(|v| v.parse::().ok()) .context("missing duration")?; let old_kbit_rate = mem - .get(3) + .get(1) .and_then(|v| v.parse::().ok().map(|v| v / 1000)); let resolution = width.zip(height);