forge
Explore
Log in

Don't you dare go Hollow

The export card tells the truth about a ranged export

Browse files at this commit

906e7deef1fe39def009d5f4901660e3147a7b20Ahmet Kaan GümüşParent: c6b5eb7
  • fix
    • the export card tells the truth about a ranged export
Show full message
🐛 fix(app): the export card tells the truth about a ranged export

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.rsmodified+1 -1
@@ -491,7 +491,7 @@ impl Player {
491 /// sound: there is nothing to write either way.491 /// sound: there is nothing to write either way.
492 pub(crate) fn audio_rate_refusal(&self) -> Option<&'static str> {492 pub(crate) fn audio_rate_refusal(&self) -> Option<&'static str> {
493 match &self.session {493 match &self.session {
494- Some(session) => session.audio_rate_refusal(self.format),494+ Some(session) => session.audio_rate_refusal(self.format, self.range.is_some()),
495 None => Some("no sound to write"),495 None => Some("no sound to write"),
496 }496 }
497 }497 }
crates/app/src/ui/cards.rsmodified+7 -6
@@ -519,7 +519,7 @@ impl Player {
519 || {519 || {
520 self.session520 self.session
521 .as_ref()521 .as_ref()
522- .map_or("", |s| s.planned_audio(self.format))522+ .map_or("", |s| s.planned_audio(self.format, self.range.is_some()))
523 },523 },
524 |(_, audio)| audio,524 |(_, audio)| audio,
525 );525 );
@@ -533,9 +533,10 @@ impl Player {
533 );533 );
534 let size = estimated_bytes(534 let size = estimated_bytes(
535 settings.bitrate.filter(|_| self.format.has_video()),535 settings.bitrate.filter(|_| self.format.has_video()),
536- self.session536+ self.session.as_ref().map_or(0., |s| match self.range {
537- .as_ref()537+ Some((start, end)) => f64::from(end - start) / s.meta().frame_rate,
538- .map_or(0., PlaybackSession::timeline_duration),538+ None => s.timeline_duration(),
539+ }),
539 );540 );
540 let head = summary_head(self.format, picture, audio);541 let head = summary_head(self.format, picture, audio);
541 let tail = summary_tail(542 let tail = summary_tail(
@@ -650,7 +651,7 @@ impl Player {
650 "RANGE {}\u{2013}{} ({})",651 "RANGE {}\u{2013}{} ({})",
651 timecode(f64::from(start) / self.fps, self.fps),652 timecode(f64::from(start) / self.fps, self.fps),
652 timecode(f64::from(end) / self.fps, self.fps),653 timecode(f64::from(end) / self.fps, self.fps),
653- timecode(f64::from(end - start) / self.fps, self.fps),654+ frames_timecode(end - start, self.fps),
654 ))655 ))
655 }))656 }))
656 .child(657 .child(
@@ -1653,7 +1654,7 @@ impl Player {
1653 "{speed} — {} source frames over {} on the timeline ({})",1654 "{speed} — {} source frames over {} on the timeline ({})",
1654 clip.len(),1655 clip.len(),
1655 clip.frames(),1656 clip.frames(),
1656- timecode(f64::from(clip.frames()) / self.fps, self.fps)1657+ frames_timecode(clip.frames(), self.fps)
1657 )),1658 )),
1658 ),1659 ),
1659 ),1660 ),
crates/app/src/ui/timeline.rsmodified+10 -0
@@ -241,6 +241,13 @@ impl Player {
241 .children(self.range.map(|(start, end)| {241 .children(self.range.map(|(start, end)| {
242 let left = self.scale.px_at(f64::from(start) / self.fps);242 let left = self.scale.px_at(f64::from(start) / self.fps);
243 let right = self.scale.px_at(f64::from(end) / self.fps);243 let right = self.scale.px_at(f64::from(end) / self.fps);
244+ // The wash alone is the played fill's own
245+ // color at lower alpha, so once the
246+ // playhead has passed the whole band the
247+ // two blend to one flat color and the mark
248+ // vanishes. A tick at each boundary, in
249+ // the theme's foreground rather than its
250+ // accent, reads over either background.
244 div()251 div()
245 .absolute()252 .absolute()
246 .top_0()253 .top_0()
@@ -249,6 +256,9 @@ impl Player {
249 .w(px((right - left).max(1.)))256 .w(px((right - left).max(1.)))
250 .rounded(px(3.))257 .rounded(px(3.))
251 .bg(rgba(ACCENT_WASH()))258 .bg(rgba(ACCENT_WASH()))
259+ .border_l(px(2.))
260+ .border_r(px(2.))
261+ .border_color(rgb(FG_PRIMARY()))
252 })),262 })),
253 ),263 ),
254 ),264 ),
crates/app/src/viewport.rsmodified+21 -0
@@ -288,6 +288,27 @@ pub(crate) fn timecode(t: f64, fps: f64) -> String {
288 )288 )
289 }289 }
290 290
291+/// NLE timecode for a *duration* given as a frame count: the same
292+/// `HH:MM:SS:FF` shape as [`timecode`], but built from the count directly
293+/// rather than a float number of seconds. `timecode` truncates `(t - secs) *
294+/// fps`, which loses a whole frame to float error on a duration derived from
295+/// dividing a frame count by `fps` first (346 frames at 30 fps printed
296+/// `00:00:11:15`, one short of the true `:16`); integer frame math has no
297+/// such rounding to lose.
298+pub(crate) fn frames_timecode(frames: u32, fps: f64) -> String {
299+ let per_sec = (fps.ceil() as u64).max(1);
300+ let frames = u64::from(frames);
301+ let secs = frames / per_sec;
302+ let frame = frames % per_sec;
303+ format!(
304+ "{:02}:{:02}:{:02}:{:02}",
305+ secs / 3600,
306+ secs / 60 % 60,
307+ secs % 60,
308+ frame
309+ )
310+}
311+
291 /// Wall clock for a progress line: `M:SS`, minutes past the hour included312 /// Wall clock for a progress line: `M:SS`, minutes past the hour included
292 /// rather than an hours field nobody reads on an export.313 /// rather than an hours field nobody reads on an export.
293 pub(crate) fn clock(secs: f32) -> String {314 pub(crate) fn clock(secs: f32) -> String {
crates/engine/examples/bench.rsmodified+1 -1
@@ -904,7 +904,7 @@ fn export_bench(path: &Path, seat: &str, out_dir: &Path) {
904 let mut notes = Vec::new();904 let mut notes = Vec::new();
905 let budget = Instant::now();905 let budget = Instant::now();
906 for _ in 0..reps.max(1) {906 for _ in 0..reps.max(1) {
907- let handle = engine::export::start(project.clone(), meta, &out, &settings);907+ let handle = engine::export::start(project.clone(), meta, &out, &settings, None);
908 let t = Instant::now();908 let t = Instant::now();
909 let mut capped = false;909 let mut capped = false;
910 // The highest the bar was ever seen at, not wherever it happens to910 // The highest the bar was ever seen at, not wherever it happens to
crates/engine/src/export.rsmodified+30 -12
@@ -720,13 +720,17 @@ fn video_label(format: Format, hw: bool) -> &'static str {
720 /// copy; a speeded lane is resampled; an equalizer is sample math. The other720 /// copy; a speeded lane is resampled; an equalizer is sample math. The other
721 /// half -- whether the sources can be copied out of at all -- costs a file open721 /// half -- whether the sources can be copied out of at all -- costs a file open
722 /// each and belongs to [`copy_audio`], which may re-encode where this says copy.722 /// each and belongs to [`copy_audio`], which may re-encode where this says copy.
723-fn forces_encode(project: &Project) -> bool {723+fn forces_encode(project: &Project, ranged: bool) -> bool {
724 let lanes: Vec<_> = project724 let lanes: Vec<_> = project
725 .audio_lanes()725 .audio_lanes()
726 .into_iter()726 .into_iter()
727 .filter(|&lane| !project.lane(lane).is_empty())727 .filter(|&lane| !project.lane(lane).is_empty())
728 .collect();728 .collect();
729- lanes.len() > 1729+ // A ranged export needs an exact offset and an exact length, which a copy
730+ // of the source's own packets cannot give it ([`copy_audio`]) -- so a
731+ // range marked at all always encodes, whatever the lanes look like.
732+ ranged
733+ || lanes.len() > 1
730 || lanes734 || lanes
731 .iter()735 .iter()
732 .any(|&lane| project.lane(lane).iter().any(|c| !c.speed.is_normal()))736 .any(|&lane| project.lane(lane).iter().any(|c| !c.speed.is_normal()))
@@ -749,6 +753,7 @@ fn audio_label(
749 format: Format,753 format: Format,
750 sound: bool,754 sound: bool,
751 copied: Option<bool>,755 copied: Option<bool>,
756+ ranged: bool,
752 ) -> &'static str {757 ) -> &'static str {
753 if !sound {758 if !sound {
754 return "no sound to write";759 return "no sound to write";
@@ -758,7 +763,7 @@ fn audio_label(
758 Format::Flac => "FLAC · SW (flacenc)",763 Format::Flac => "FLAC · SW (flacenc)",
759 Format::Mp3 => "MP3 · SW (rusty_mp3)",764 Format::Mp3 => "MP3 · SW (rusty_mp3)",
760 Format::Ogg => "Vorbis · SW (rusty_vorbis)",765 Format::Ogg => "Vorbis · SW (rusty_vorbis)",
761- _ => match copied.unwrap_or(!forces_encode(project)) {766+ _ => match copied.unwrap_or(!forces_encode(project, ranged)) {
762 true => "AAC copy",767 true => "AAC copy",
763 // A Matroska file gets Opus where the mix allows it -- 48 kHz and768 // A Matroska file gets Opus where the mix allows it -- 48 kHz and
764 // stereo, which is every Opus source and most of everything else --769 // stereo, which is every Opus source and most of everything else --
@@ -800,14 +805,19 @@ fn measured_audio_label(
800 // Opus: the fidelity gate sent it to AAC ([`OPUS_MIN_FIDELITY`]), or the805 // Opus: the fidelity gate sent it to AAC ([`OPUS_MIN_FIDELITY`]), or the
801 // mix was not the 48 kHz stereo that seat is measured in.806 // mix was not the 48 kHz stereo that seat is measured in.
802 (Some(false), false) if format.is_mkv() => "AAC · SW encode (rusty_aac)",807 (Some(false), false) if format.is_mkv() => "AAC · SW encode (rusty_aac)",
803- _ => audio_label(project, format, sound.is_some(), sound),808+ // `sound` is already what happened, not a prediction, so `copied` is
809+ // filled in and `ranged` never reaches the branch that reads it.
810+ _ => audio_label(project, format, sound.is_some(), sound, false),
804 }811 }
805 }812 }
806 813
807 /// What [`start`] would write this timeline's sound with, before one is814 /// What [`start`] would write this timeline's sound with, before one is
808-/// started. Pure: no probe and no file opened, so a card may ask it per repaint.815+/// started. Pure: no probe and no file opened, so a card may ask it per
809-pub fn planned_audio(project: &Project, format: Format) -> &'static str {816+/// repaint. `ranged` is whether the export a card is describing is bounded to
810- audio_label(project, format, has_sound(project), None)817+/// a marked range -- a copy needs the source's own packets to *be* the file,
818+/// which a range's exact offset and length rule out ([`copy_audio`]).
819+pub fn planned_audio(project: &Project, format: Format, ranged: bool) -> &'static str {
820+ audio_label(project, format, has_sound(project), None, ranged)
811 }821 }
812 822
813 /// Why the sound's rate is nothing this timeline can be asked about in this823 /// 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 {
819 /// [`ExportSettings::audio_kbps`] like every other encode. So the value travels829 /// [`ExportSettings::audio_kbps`] like every other encode. So the value travels
820 /// even where this refuses; what it cannot do is silently write a rate nobody830 /// even where this refuses; what it cannot do is silently write a rate nobody
821 /// picked.831 /// picked.
822-pub fn audio_rate_refusal(project: &Project, format: Format) -> Option<&'static str> {832+pub fn audio_rate_refusal(project: &Project, format: Format, ranged: bool) -> Option<&'static str> {
823 match format {833 match format {
824 _ if !has_sound(project) => Some("no sound to write"),834 _ if !has_sound(project) => Some("no sound to write"),
825 Format::Wav | Format::Flac => Some("lossless — the samples themselves, at no rate"),835 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
831 // does not hold, which is the one thing this card is built not to do.841 // does not hold, which is the one thing this card is built not to do.
832 Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"),842 Format::Ogg => Some("quality-coded — Vorbis holds no rate to pick"),
833 Format::Mp3 => None,843 Format::Mp3 => None,
834- _ if forces_encode(project) => None,844+ _ if forces_encode(project, ranged) => None,
835 _ => Some("the source's own packets are copied — at the rate they hold"),845 _ => Some("the source's own packets are copied — at the rate they hold"),
836 }846 }
837 }847 }
@@ -1287,14 +1297,20 @@ pub fn planned_seats(
1287 // a Matroska file has none -- so every mkv source re-encodes, however1297 // a Matroska file has none -- so every mkv source re-encodes, however
1288 // untouched its lane is. Extension only, which is what `is_matroska`1298 // untouched its lane is. Extension only, which is what `is_matroska`
1289 // reads, so this costs nothing beyond what is already open.1299 // reads, so this costs nothing beyond what is already open.
1290- let copyable = !forces_encode(project)1300+ let copyable = !forces_encode(project, settings.range.is_some())
1291 && !project1301 && !project
1292 .sources()1302 .sources()
1293 .iter()1303 .iter()
1294 .any(|source| crate::demux::is_matroska(&source.path));1304 .any(|source| crate::demux::is_matroska(&source.path));
1295 (1305 (
1296 video,1306 video,
1297- audio_label(project, settings.format, has_sound(project), Some(copyable)),1307+ audio_label(
1308+ project,
1309+ settings.format,
1310+ has_sound(project),
1311+ Some(copyable),
1312+ settings.range.is_some(),
1313+ ),
1298 )1314 )
1299 }1315 }
1300 1316
@@ -2844,7 +2860,9 @@ fn run_audio(
2844 };2860 };
2845 // The picture path's line, for a file that is sound alone: there is sound2861 // The picture path's line, for a file that is sound alone: there is sound
2846 // by the line above, so this names the encoder writing it.2862 // by the line above, so this names the encoder writing it.
2847- *shared.encoders.lock().unwrap() = Some(audio_label(project, format, true, None).to_string());2863+ *shared.encoders.lock().unwrap() = Some(
2864+ audio_label(project, format, true, None, settings.range.is_some()).to_string(),
2865+ );
2848 let channels = usize::from(audio.channels);2866 let channels = usize::from(audio.channels);
2849 let out_frames = settings.range.map_or(project.media_frames(), |(s, e)| {2867 let out_frames = settings.range.map_or(project.media_frames(), |(s, e)| {
2850 e.min(project.media_frames()).saturating_sub(s)2868 e.min(project.media_frames()).saturating_sub(s)
crates/engine/src/playback.rsmodified+8 -4
@@ -1099,8 +1099,8 @@ impl PlaybackSession {
1099 /// the format (or an equalized lane) forces. Pure -- no probe, no file1099 /// the format (or an equalized lane) forces. Pure -- no probe, no file
1100 /// opened -- so a card may ask it per repaint; the picture's half costs a1100 /// opened -- so a card may ask it per repaint; the picture's half costs a
1101 /// plugin open and lives in [`crate::export::planned_video`].1101 /// plugin open and lives in [`crate::export::planned_video`].
1102- pub fn planned_audio(&self, format: crate::export::Format) -> &'static str {1102+ pub fn planned_audio(&self, format: crate::export::Format, ranged: bool) -> &'static str {
1103- crate::export::planned_audio(&self.project, format)1103+ crate::export::planned_audio(&self.project, format, ranged)
1104 }1104 }
1105 1105
1106 /// The timeline an export started right now would be run against, owned:1106 /// The timeline an export started right now would be run against, owned:
@@ -1150,8 +1150,12 @@ impl PlaybackSession {
1150 /// Why the sound's rate is not a choice for this timeline in this format --1150 /// Why the sound's rate is not a choice for this timeline in this format --
1151 /// [`crate::export::audio_rate_refusal`], asked of the project a front-end1151 /// [`crate::export::audio_rate_refusal`], asked of the project a front-end
1152 /// is holding, and pure for the same reason.1152 /// is holding, and pure for the same reason.
1153- pub fn audio_rate_refusal(&self, format: crate::export::Format) -> Option<&'static str> {1153+ pub fn audio_rate_refusal(
1154- crate::export::audio_rate_refusal(&self.project, format)1154+ &self,
1155+ format: crate::export::Format,
1156+ ranged: bool,
1157+ ) -> Option<&'static str> {
1158+ crate::export::audio_rate_refusal(&self.project, format, ranged)
1155 }1159 }
1156 1160
1157 /// Why this session plays silent although the file has sound -- an audio1161 /// Why this session plays silent although the file has sound -- an audio
crates/engine/tests/backends.rsmodified+6 -6
@@ -119,7 +119,7 @@ fn the_planned_encoders_are_the_ones_the_job_opens() {
119 "{} · {}",119 "{} · {}",
120 engine::export::planned_video(session.meta(), &settings)120 engine::export::planned_video(session.meta(), &settings)
121 .expect("these formats carry picture"),121 .expect("these formats carry picture"),
122- session.planned_audio(format)122+ session.planned_audio(format, false)
123 );123 );
124 let out = out_path("planned", ext);124 let out = out_path("planned", ext);
125 let handle = session.export_to_with(&out, &settings);125 let handle = session.export_to_with(&out, &settings);
@@ -268,7 +268,7 @@ fn audio_only_job_names_its_encoder(format: Format) {
268 "an audio-only format has no video seat to name"268 "an audio-only format has no video seat to name"
269 );269 );
270 let session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");270 let session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
271- let planned = session.planned_audio(format);271+ let planned = session.planned_audio(format, false);
272 let out = out_path("audio", format.ext());272 let out = out_path("audio", format.ext());
273 let handle = session.export_to_with(&out, &settings);273 let handle = session.export_to_with(&out, &settings);
274 let started = Instant::now();274 let started = Instant::now();
@@ -299,24 +299,24 @@ fn audio_only_job_names_its_encoder(format: Format) {
299 fn a_mixed_timeline_says_it_re_encodes_and_then_does() {299 fn a_mixed_timeline_says_it_re_encodes_and_then_does() {
300 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");300 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture");
301 assert_eq!(301 assert_eq!(
302- session.planned_audio(Format::Mp4),302+ session.planned_audio(Format::Mp4, false),
303 "AAC copy",303 "AAC copy",
304 "a timeline nobody has mixed is still a copy"304 "a timeline nobody has mixed is still a copy"
305 );305 );
306 // A fader off unity...306 // A fader off unity...
307 assert!(session.set_lane_gain_db(engine::project::Lane::A1, -3.0));307 assert!(session.set_lane_gain_db(engine::project::Lane::A1, -3.0));
308- let planned = session.planned_audio(Format::Mp4);308+ let planned = session.planned_audio(Format::Mp4, false);
309 assert!(planned.contains("encode"), "a faded lane: {planned}");309 assert!(planned.contains("encode"), "a faded lane: {planned}");
310 // ...and back at unity it is a copy again: the answer follows the edit, it310 // ...and back at unity it is a copy again: the answer follows the edit, it
311 // is not a latch.311 // is not a latch.
312 assert!(session.set_lane_gain_db(engine::project::Lane::A1, 0.0));312 assert!(session.set_lane_gain_db(engine::project::Lane::A1, 0.0));
313- assert_eq!(session.planned_audio(Format::Mp4), "AAC copy");313+ assert_eq!(session.planned_audio(Format::Mp4, false), "AAC copy");
314 // ...and the limiter alone does it too.314 // ...and the limiter alone does it too.
315 assert!(session.set_limiter(engine::limiter::Limiter {315 assert!(session.set_limiter(engine::limiter::Limiter {
316 ceiling_db: -1.0,316 ceiling_db: -1.0,
317 on: true,317 on: true,
318 }));318 }));
319- assert_eq!(session.planned_audio(Format::Mp4), planned);319+ assert_eq!(session.planned_audio(Format::Mp4, false), planned);
320 320
321 // ...and the job opens exactly that, which is the pin the whole file is321 // ...and the job opens exactly that, which is the pin the whole file is
322 // about: the encoders line published by the running export.322 // about: the encoders line published by the running export.