summaryrefslogtreecommitdiffstats
path: root/src/ffmpeg.rs
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2026-05-22 13:11:04 +0000
committers-ol <s+removethis@s-ol.nu>2026-05-22 13:40:26 +0000
commit0f55c2011032a6ada8a66d2743efc88e229ff5a6 (patch)
tree45be24a59cd798ca57d3c9f23a02720f1ad75030 /src/ffmpeg.rs
parentfix SRGB fail (diff)
downloadwgsl-view-main.tar.gz
wgsl-view-main.zip
tsv-video-*: detect video length using format durationHEADmain
Diffstat (limited to '')
-rw-r--r--src/ffmpeg.rs12
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,