From 906e7deef1fe39def009d5f4901660e3147a7b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 02:22:49 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(app):=20the=20export=20card?= =?UTF-8?q?=20tells=20the=20truth=20about=20a=20ranged=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The size estimate and the audio-codec label both ignored the marked range (a ranged export re-encodes; the card said copy and quoted the whole timeline's size). The RANGE duration is computed from the frame count instead of float seconds, and the speed card's row joins it — same truncation class. The range band gets 2px boundary ticks so it reads over the played fill. bench.rs learns export::start's fifth argument, closing the arity sweep over examples. --- crates/app/src/player/export.rs | 2 +- crates/app/src/ui/cards.rs | 13 +++++----- crates/app/src/ui/timeline.rs | 10 ++++++++ crates/app/src/viewport.rs | 21 +++++++++++++++++ crates/engine/examples/bench.rs | 2 +- crates/engine/src/export.rs | 42 +++++++++++++++++++++++---------- crates/engine/src/playback.rs | 12 ++++++---- crates/engine/tests/backends.rs | 12 +++++----- 8 files changed, 84 insertions(+), 30 deletions(-) diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 7a7fa83..299cb13 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -491,7 +491,7 @@ impl Player { /// sound: there is nothing to write either way. pub(crate) fn audio_rate_refusal(&self) -> Option<&'static str> { match &self.session { - Some(session) => session.audio_rate_refusal(self.format), + Some(session) => session.audio_rate_refusal(self.format, self.range.is_some()), None => Some("no sound to write"), } } diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index a8c6f84..0547183 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -519,7 +519,7 @@ impl Player { || { self.session .as_ref() - .map_or("", |s| s.planned_audio(self.format)) + .map_or("", |s| s.planned_audio(self.format, self.range.is_some())) }, |(_, audio)| audio, ); @@ -533,9 +533,10 @@ impl Player { ); let size = estimated_bytes( settings.bitrate.filter(|_| self.format.has_video()), - self.session - .as_ref() - .map_or(0., PlaybackSession::timeline_duration), + self.session.as_ref().map_or(0., |s| match self.range { + Some((start, end)) => f64::from(end - start) / s.meta().frame_rate, + None => s.timeline_duration(), + }), ); let head = summary_head(self.format, picture, audio); let tail = summary_tail( @@ -650,7 +651,7 @@ impl Player { "RANGE {}\u{2013}{} ({})", timecode(f64::from(start) / self.fps, self.fps), timecode(f64::from(end) / self.fps, self.fps), - timecode(f64::from(end - start) / self.fps, self.fps), + frames_timecode(end - start, self.fps), )) })) .child( @@ -1653,7 +1654,7 @@ impl Player { "{speed} — {} source frames over {} on the timeline ({})", clip.len(), clip.frames(), - timecode(f64::from(clip.frames()) / self.fps, self.fps) + frames_timecode(clip.frames(), self.fps) )), ), ), diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index a8dd011..f375619 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -241,6 +241,13 @@ impl Player { .children(self.range.map(|(start, end)| { let left = self.scale.px_at(f64::from(start) / self.fps); let right = self.scale.px_at(f64::from(end) / self.fps); + // The wash alone is the played fill's own + // color at lower alpha, so once the + // playhead has passed the whole band the + // two blend to one flat color and the mark + // vanishes. A tick at each boundary, in + // the theme's foreground rather than its + // accent, reads over either background. div() .absolute() .top_0() @@ -249,6 +256,9 @@ impl Player { .w(px((right - left).max(1.))) .rounded(px(3.)) .bg(rgba(ACCENT_WASH())) + .border_l(px(2.)) + .border_r(px(2.)) + .border_color(rgb(FG_PRIMARY())) })), ), ), diff --git a/crates/app/src/viewport.rs b/crates/app/src/viewport.rs index 6a887c5..effcf39 100644 --- a/crates/app/src/viewport.rs +++ b/crates/app/src/viewport.rs @@ -288,6 +288,27 @@ pub(crate) fn timecode(t: f64, fps: f64) -> String { ) } +/// NLE timecode for a *duration* given as a frame count: the same +/// `HH:MM:SS:FF` shape as [`timecode`], but built from the count directly +/// rather than a float number of seconds. `timecode` truncates `(t - secs) * +/// fps`, which loses a whole frame to float error on a duration derived from +/// dividing a frame count by `fps` first (346 frames at 30 fps printed +/// `00:00:11:15`, one short of the true `:16`); integer frame math has no +/// such rounding to lose. +pub(crate) fn frames_timecode(frames: u32, fps: f64) -> String { + let per_sec = (fps.ceil() as u64).max(1); + let frames = u64::from(frames); + let secs = frames / per_sec; + let frame = frames % per_sec; + format!( + "{:02}:{:02}:{:02}:{:02}", + secs / 3600, + secs / 60 % 60, + secs % 60, + frame + ) +} + /// Wall clock for a progress line: `M:SS`, minutes past the hour included /// rather than an hours field nobody reads on an export. pub(crate) fn clock(secs: f32) -> String { diff --git a/crates/engine/examples/bench.rs b/crates/engine/examples/bench.rs index 0959178..f472d25 100644 --- a/crates/engine/examples/bench.rs +++ b/crates/engine/examples/bench.rs @@ -904,7 +904,7 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) { let mut notes = Vec::new(); let budget = Instant::now(); for _ in 0..reps.max(1) { - let handle = engine::export::start(project.clone(), meta, &out, &settings); + let handle = engine::export::start(project.clone(), meta, &out, &settings, None); let t = Instant::now(); let mut capped = false; // The highest the bar was ever seen at, not wherever it happens to diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index efeeb60..e890c6a 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -720,13 +720,17 @@ fn video_label(format: Format, hw: bool) -> &'static str { /// copy; a speeded lane is resampled; an equalizer is sample math. The other /// half -- whether the sources can be copied out of at all -- costs a file open /// each and belongs to [`copy_audio`], which may re-encode where this says copy. -fn forces_encode(project: &Project) -> bool { +fn forces_encode(project: &Project, ranged: bool) -> bool { let lanes: Vec<_> = project .audio_lanes() .into_iter() .filter(|&lane| !project.lane(lane).is_empty()) .collect(); - lanes.len() > 1 + // A ranged export needs an exact offset and an exact length, which a copy + // of the source's own packets cannot give it ([`copy_audio`]) -- so a + // range marked at all always encodes, whatever the lanes look like. + ranged + || lanes.len() > 1 || lanes .iter() .any(|&lane| project.lane(lane).iter().any(|c| !c.speed.is_normal())) @@ -749,6 +753,7 @@ fn audio_label( format: Format, sound: bool, copied: Option, + ranged: bool, ) -> &'static str { if !sound { return "no sound to write"; @@ -758,7 +763,7 @@ fn audio_label( Format::Flac => "FLAC · SW (flacenc)", Format::Mp3 => "MP3 · SW (rusty_mp3)", Format::Ogg => "Vorbis · SW (rusty_vorbis)", - _ => match copied.unwrap_or(!forces_encode(project)) { + _ => match copied.unwrap_or(!forces_encode(project, ranged)) { true => "AAC copy", // A Matroska file gets Opus where the mix allows it -- 48 kHz and // stereo, which is every Opus source and most of everything else -- @@ -800,14 +805,19 @@ fn measured_audio_label( // Opus: the fidelity gate sent it to AAC ([`OPUS_MIN_FIDELITY`]), or the // mix was not the 48 kHz stereo that seat is measured in. (Some(false), false) if format.is_mkv() => "AAC · SW encode (rusty_aac)", - _ => audio_label(project, format, sound.is_some(), sound), + // `sound` is already what happened, not a prediction, so `copied` is + // filled in and `ranged` never reaches the branch that reads it. + _ => audio_label(project, format, sound.is_some(), sound, false), } } /// What [`start`] would write this timeline's sound with, before one is -/// started. Pure: no probe and no file opened, so a card may ask it per repaint. -pub fn planned_audio(project: &Project, format: Format) -> &'static str { - audio_label(project, format, has_sound(project), None) +/// started. Pure: no probe and no file opened, so a card may ask it per +/// repaint. `ranged` is whether the export a card is describing is bounded to +/// a marked range -- a copy needs the source's own packets to *be* the file, +/// which a range's exact offset and length rule out ([`copy_audio`]). +pub fn planned_audio(project: &Project, format: Format, ranged: bool) -> &'static str { + audio_label(project, format, has_sound(project), None, ranged) } /// Why the sound's rate is nothing this timeline can be asked about in this @@ -819,7 +829,7 @@ pub fn planned_audio(project: &Project, format: Format) -> &'static str { /// [`ExportSettings::audio_kbps`] like every other encode. So the value travels /// even where this refuses; what it cannot do is silently write a rate nobody /// picked. -pub fn audio_rate_refusal(project: &Project, format: Format) -> Option<&'static str> { +pub fn audio_rate_refusal(project: &Project, format: Format, ranged: bool) -> Option<&'static str> { match format { _ if !has_sound(project) => Some("no sound to write"), Format::Wav | Format::Flac => Some("lossless — the samples themselves, at no rate"), @@ -831,7 +841,7 @@ pub fn audio_rate_refusal(project: &Project, format: Format) -> Option<&'static // does not hold, which is the one thing this card is built not to do. Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"), Format::Mp3 => None, - _ if forces_encode(project) => None, + _ if forces_encode(project, ranged) => None, _ => Some("the source's own packets are copied — at the rate they hold"), } } @@ -1287,14 +1297,20 @@ pub fn planned_seats( // a Matroska file has none -- so every mkv source re-encodes, however // untouched its lane is. Extension only, which is what `is_matroska` // reads, so this costs nothing beyond what is already open. - let copyable = !forces_encode(project) + let copyable = !forces_encode(project, settings.range.is_some()) && !project .sources() .iter() .any(|source| crate::demux::is_matroska(&source.path)); ( video, - audio_label(project, settings.format, has_sound(project), Some(copyable)), + audio_label( + project, + settings.format, + has_sound(project), + Some(copyable), + settings.range.is_some(), + ), ) } @@ -2844,7 +2860,9 @@ fn run_audio( }; // The picture path's line, for a file that is sound alone: there is sound // by the line above, so this names the encoder writing it. - *shared.encoders.lock().unwrap() = Some(audio_label(project, format, true, None).to_string()); + *shared.encoders.lock().unwrap() = Some( + audio_label(project, format, true, None, settings.range.is_some()).to_string(), + ); let channels = usize::from(audio.channels); let out_frames = settings.range.map_or(project.media_frames(), |(s, e)| { e.min(project.media_frames()).saturating_sub(s) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index fa16859..d29140d 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -1099,8 +1099,8 @@ impl PlaybackSession { /// the format (or an equalized lane) forces. Pure -- no probe, no file /// opened -- so a card may ask it per repaint; the picture's half costs a /// plugin open and lives in [`crate::export::planned_video`]. - pub fn planned_audio(&self, format: crate::export::Format) -> &'static str { - crate::export::planned_audio(&self.project, format) + pub fn planned_audio(&self, format: crate::export::Format, ranged: bool) -> &'static str { + crate::export::planned_audio(&self.project, format, ranged) } /// The timeline an export started right now would be run against, owned: @@ -1150,8 +1150,12 @@ impl PlaybackSession { /// Why the sound's rate is not a choice for this timeline in this format -- /// [`crate::export::audio_rate_refusal`], asked of the project a front-end /// is holding, and pure for the same reason. - pub fn audio_rate_refusal(&self, format: crate::export::Format) -> Option<&'static str> { - crate::export::audio_rate_refusal(&self.project, format) + pub fn audio_rate_refusal( + &self, + format: crate::export::Format, + ranged: bool, + ) -> Option<&'static str> { + crate::export::audio_rate_refusal(&self.project, format, ranged) } /// Why this session plays silent although the file has sound -- an audio diff --git a/crates/engine/tests/backends.rs b/crates/engine/tests/backends.rs index 6eaec09..cdeda18 100644 --- a/crates/engine/tests/backends.rs +++ b/crates/engine/tests/backends.rs @@ -119,7 +119,7 @@ fn the_planned_encoders_are_the_ones_the_job_opens() { "{} · {}", engine::export::planned_video(session.meta(), &settings) .expect("these formats carry picture"), - session.planned_audio(format) + session.planned_audio(format, false) ); let out = out_path("planned", ext); let handle = session.export_to_with(&out, &settings); @@ -268,7 +268,7 @@ fn audio_only_job_names_its_encoder(format: Format) { "an audio-only format has no video seat to name" ); let session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); - let planned = session.planned_audio(format); + let planned = session.planned_audio(format, false); let out = out_path("audio", format.ext()); let handle = session.export_to_with(&out, &settings); let started = Instant::now(); @@ -299,24 +299,24 @@ fn audio_only_job_names_its_encoder(format: Format) { fn a_mixed_timeline_says_it_re_encodes_and_then_does() { let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); assert_eq!( - session.planned_audio(Format::Mp4), + session.planned_audio(Format::Mp4, false), "AAC copy", "a timeline nobody has mixed is still a copy" ); // A fader off unity... assert!(session.set_lane_gain_db(engine::project::Lane::A1, -3.0)); - let planned = session.planned_audio(Format::Mp4); + let planned = session.planned_audio(Format::Mp4, false); assert!(planned.contains("encode"), "a faded lane: {planned}"); // ...and back at unity it is a copy again: the answer follows the edit, it // is not a latch. assert!(session.set_lane_gain_db(engine::project::Lane::A1, 0.0)); - assert_eq!(session.planned_audio(Format::Mp4), "AAC copy"); + assert_eq!(session.planned_audio(Format::Mp4, false), "AAC copy"); // ...and the limiter alone does it too. assert!(session.set_limiter(engine::limiter::Limiter { ceiling_db: -1.0, on: true, })); - assert_eq!(session.planned_audio(Format::Mp4), planned); + assert_eq!(session.planned_audio(Format::Mp4, false), planned); // ...and the job opens exactly that, which is the pin the whole file is // about: the encoders line published by the running export.