diff options
Diffstat (limited to '')
| -rw-r--r-- | src/ffmpeg.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ffmpeg.rs b/src/ffmpeg.rs index fbfdc94..3c385c4 100644 --- a/src/ffmpeg.rs +++ b/src/ffmpeg.rs @@ -90,6 +90,7 @@ fn filter_probe_args(ff_args: &[String]) -> Vec<String> { out } +#[derive(Debug)] pub struct VideoInfo { pub width: u32, pub height: u32, @@ -106,7 +107,7 @@ pub fn probe_video(ff_args: &[String], max_frames: Option<u32>) -> VideoInfo { .args(["-select_streams", "v:0"]) .args([ "-show_entries", - "stream=codec_tag_string,width,height,pix_fmt,r_frame_rate,nb_frames", + "stream=codec_tag_string,width,height,pix_fmt,r_frame_rate,nb_frames:format=duration", ]) .args(["-of", "csv=p=0"]) .args(&probe_args) @@ -120,8 +121,8 @@ pub fn probe_video(ff_args: &[String], max_frames: Option<u32>) -> VideoInfo { let stdout = String::from_utf8_lossy(&output.stdout); let line = stdout.trim(); - let parts: Vec<&str> = line.split(',').collect(); - if parts.len() != 6 { + let parts: Vec<&str> = line.split(&[',', '\n']).collect(); + if parts.len() != 7 { panic!("unexpected ffprobe output: {line}"); } @@ -137,7 +138,10 @@ pub fn probe_video(ff_args: &[String], max_frames: Option<u32>) -> VideoInfo { } else { parts[4].parse().expect("parse fps") }; - let num_frames = parts[5].parse().ok().or(max_frames); + let num_frames = parts[5].parse::<u32>().ok().or(max_frames).or_else(|| { + let duration: f64 = parts[6].parse().ok()?; + Some((duration * fps) as u32) + }); VideoInfo { width, |
