diff --git a/crates/app/src/export_ui.rs b/crates/app/src/export_ui.rs index 46a045b..c78a287 100644 --- a/crates/app/src/export_ui.rs +++ b/crates/app/src/export_ui.rs @@ -947,6 +947,22 @@ pub(crate) fn exact_refusal(session: &PlaybackSession, format: Format, quality: engine::export::exact_refusal(&project, &meta, &settings) } +/// Which format picking Exact should set, from the source's own codec -- +/// "the input's own quality" means the input's own codec, so this is what +/// `Player::pick_quality` derives the format from rather than leaving +/// whatever format a previous pick left behind. `None` for a codec Exact has +/// no copy path for at all (h264); the row itself still refuses through +/// [`exact_refusal`] in that case, since a mixed-source project can fail the +/// same way after the format is set. +pub(crate) fn exact_format(session: &PlaybackSession) -> Option { + let (_, meta) = session.export_snapshot(); + match meta.codec { + engine::demux::Codec::Hevc => Some(Format::Hevc), + engine::demux::Codec::Av1 => Some(Format::Av1), + _ => None, + } +} + pub(crate) fn format_refusal(session: &PlaybackSession, format: Format) -> Option { if !format.has_video() { return None; diff --git a/crates/app/src/player/export.rs b/crates/app/src/player/export.rs index 8a73598..ae1ed39 100644 --- a/crates/app/src/player/export.rs +++ b/crates/app/src/player/export.rs @@ -502,6 +502,25 @@ impl Player { } } + /// A quality row, by click or by its own key (`Custom` goes through + /// [`Self::edit_mbps`] instead). Exact is the one row that is also a + /// format decision -- "the input's own quality" means the input's own + /// codec, so picking it derives the container from the source rather + /// than leaving whatever format a previous pick left behind for + /// [`exact_refusal`] to refuse minutes later. A source this cannot copy + /// (h264, mixed sources) leaves the format alone; the row itself + /// ([`crate::ui::cards`]'s quality list) already says why. + pub(crate) fn pick_quality(&mut self, quality: Quality) { + self.quality = quality; + if quality != Quality::Exact { + return; + } + let Some(format) = self.session.as_ref().and_then(exact_format) else { + return; + }; + self.set_format(format); + } + /// The container row: the same codec in the other box, which retargets the /// destination exactly as picking a codec does -- and does nothing at all /// for a codec with only one box, so the stroke cannot invent a choice the diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 21a3b9f..bed6df7 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -1714,6 +1714,30 @@ fn a_preset_over_a_picture_this_timeline_has_none_of_carries_the_codec_refusal() assert_eq!(format_refusal(&session, audio_format), None); } +/// Picking Exact must derive the container from the source's own codec +/// rather than leave whatever format was already picked -- an HEVC or AV1 +/// source lands on its own copy-capable Matroska format, and a source Exact +/// has no copy path for at all (h264) leaves `exact_format` with nothing to +/// set, so the row's own [`exact_refusal`] is what a click on it would see. +#[test] +fn exact_derives_its_format_from_the_source_codec() { + let hevc = PlaybackSession::open(asset("test_hevc.mkv")).expect("an hevc fixture"); + assert_eq!(crate::exact_format(&hevc), Some(Format::Hevc)); + + let av1 = PlaybackSession::open(asset("test_av1.mkv")).expect("an av1 fixture"); + assert_eq!(crate::exact_format(&av1), Some(Format::Av1)); + + let h264 = PlaybackSession::open(asset("test_h264.mkv")).expect("an h264 fixture"); + assert_eq!(h264.export_snapshot().1.codec, engine::demux::Codec::H264); + assert_eq!(crate::exact_format(&h264), None); + // No copy path for h264 at any format -- the row's own refusal is what a + // click on Exact would still show, since `exact_format` sets nothing and + // the format is left at whatever it already was (Mp4's own refusal, or + // Hevc's if the pane was left there from an earlier pick). + assert!(crate::exact_refusal(&h264, Format::Mp4, Quality::Exact).is_some()); + assert!(crate::exact_refusal(&h264, Format::Hevc, Quality::Exact).is_some()); +} + /// The stacking-scrims bug: opening the speed card while the colour card was /// up left both up at once, because each `open_*` cleared a different /// hand-picked subset of the other flags rather than all of them. The fix is diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 7e7873b..e91a18f 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -604,6 +604,14 @@ impl Player { .mbps_edit .as_ref() .filter(|_| quality == Quality::Custom); + // Exact's own row carries whatever [`exact_refusal`] says of + // the format currently picked, whether or not Exact is the + // row in force -- the same reason `start_export` would give, + // said here instead of only after the button is pressed. + let exact_why = (quality == Quality::Exact) + .then(|| self.session.as_ref()) + .flatten() + .and_then(|s| exact_refusal(s, self.format, quality)); let mut r = entry( ("quality", i), match quality { @@ -611,9 +619,10 @@ impl Player { _ => "q", }, quality.label().into(), - match field { - Some(edit) => edit.detail().into(), - None => quality.detail(self.custom_mbps).into(), + match (&exact_why, field) { + (Some(why), _) => why.clone().into(), + (None, Some(edit)) => edit.detail().into(), + (None, None) => quality.detail(self.custom_mbps).into(), }, self.quality == quality, true, @@ -622,7 +631,7 @@ impl Player { move |this, _: &ClickEvent, _, cx| { match quality { Quality::Custom => this.edit_mbps(), - _ => this.quality = quality, + _ => this.pick_quality(quality), } cx.notify(); },