fix non-mp4 file support

This commit is contained in:
accuwau 2024-06-24 21:34:31 -04:00
parent 39ec9a5372
commit 2496539fde
2 changed files with 30 additions and 3 deletions

2
Cargo.lock generated
View file

@ -252,7 +252,7 @@ dependencies = [
[[package]] [[package]]
name = "n-mb" name = "n-mb"
version = "1.1.0" version = "1.1.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View file

@ -367,12 +367,39 @@ async fn parse_ffprobe(path: &PathBuf) -> anyhow::Result<MediaData> {
let width = mem.first().and_then(|v| v.parse::<u16>().ok()); let width = mem.first().and_then(|v| v.parse::<u16>().ok());
let height = mem.get(1).and_then(|v| v.parse::<u16>().ok()); let height = mem.get(1).and_then(|v| v.parse::<u16>().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::<Vec<_>>();
let duration = mem let duration = mem
.get(2) .get(0)
.and_then(|v| v.parse::<f32>().ok()) .and_then(|v| v.parse::<f32>().ok())
.context("missing duration")?; .context("missing duration")?;
let old_kbit_rate = mem let old_kbit_rate = mem
.get(3) .get(1)
.and_then(|v| v.parse::<u32>().ok().map(|v| v / 1000)); .and_then(|v| v.parse::<u32>().ok().map(|v| v / 1000));
let resolution = width.zip(height); let resolution = width.zip(height);