forge
Explore
Log in

Don't you dare go Hollow

Exact quality derives its own format from the source codec

Browse files at this commit

233e118caaf49f13b9f41601e3852251b93d4497Ahmet Kaan GümüşParent: 49dbed8
  • fix
    • Exact quality derives its own format from the source codec
Show full message
🐛 fix(app): Exact quality derives its own format from the source codec

Picking Exact used to leave the format on whatever preset was active,
so Export refused it with the container-mismatch message minutes
later. pick_quality() now sets the container from the source's own
codec (HEVC/AV1 -> the matching Matroska format) via the new
exact_format() helper, and the Exact row shows exact_refusal()'s
reason inline the moment it's picked (or a source manually changed
away from it) rather than only at Export time.
crates/app/src/export_ui.rsmodified+16 -0
@@ -947,6 +947,22 @@ pub(crate) fn exact_refusal(session: &PlaybackSession, format: Format, quality:
947 engine::export::exact_refusal(&project, &meta, &settings)947 engine::export::exact_refusal(&project, &meta, &settings)
948 }948 }
949 949
950+/// Which format picking Exact should set, from the source's own codec --
951+/// "the input's own quality" means the input's own codec, so this is what
952+/// `Player::pick_quality` derives the format from rather than leaving
953+/// whatever format a previous pick left behind. `None` for a codec Exact has
954+/// no copy path for at all (h264); the row itself still refuses through
955+/// [`exact_refusal`] in that case, since a mixed-source project can fail the
956+/// same way after the format is set.
957+pub(crate) fn exact_format(session: &PlaybackSession) -> Option<Format> {
958+ let (_, meta) = session.export_snapshot();
959+ match meta.codec {
960+ engine::demux::Codec::Hevc => Some(Format::Hevc),
961+ engine::demux::Codec::Av1 => Some(Format::Av1),
962+ _ => None,
963+ }
964+}
965+
950 pub(crate) fn format_refusal(session: &PlaybackSession, format: Format) -> Option<String> {966 pub(crate) fn format_refusal(session: &PlaybackSession, format: Format) -> Option<String> {
951 if !format.has_video() {967 if !format.has_video() {
952 return None;968 return None;
crates/app/src/player/export.rsmodified+19 -0
@@ -502,6 +502,25 @@ impl Player {
502 }502 }
503 }503 }
504 504
505+ /// A quality row, by click or by its own key (`Custom` goes through
506+ /// [`Self::edit_mbps`] instead). Exact is the one row that is also a
507+ /// format decision -- "the input's own quality" means the input's own
508+ /// codec, so picking it derives the container from the source rather
509+ /// than leaving whatever format a previous pick left behind for
510+ /// [`exact_refusal`] to refuse minutes later. A source this cannot copy
511+ /// (h264, mixed sources) leaves the format alone; the row itself
512+ /// ([`crate::ui::cards`]'s quality list) already says why.
513+ pub(crate) fn pick_quality(&mut self, quality: Quality) {
514+ self.quality = quality;
515+ if quality != Quality::Exact {
516+ return;
517+ }
518+ let Some(format) = self.session.as_ref().and_then(exact_format) else {
519+ return;
520+ };
521+ self.set_format(format);
522+ }
523+
505 /// The container row: the same codec in the other box, which retargets the524 /// The container row: the same codec in the other box, which retargets the
506 /// destination exactly as picking a codec does -- and does nothing at all525 /// destination exactly as picking a codec does -- and does nothing at all
507 /// for a codec with only one box, so the stroke cannot invent a choice the526 /// for a codec with only one box, so the stroke cannot invent a choice the
crates/app/src/tests/cards.rsmodified+24 -0
@@ -1714,6 +1714,30 @@ fn a_preset_over_a_picture_this_timeline_has_none_of_carries_the_codec_refusal()
1714 assert_eq!(format_refusal(&session, audio_format), None);1714 assert_eq!(format_refusal(&session, audio_format), None);
1715 }1715 }
1716 1716
1717+/// Picking Exact must derive the container from the source's own codec
1718+/// rather than leave whatever format was already picked -- an HEVC or AV1
1719+/// source lands on its own copy-capable Matroska format, and a source Exact
1720+/// has no copy path for at all (h264) leaves `exact_format` with nothing to
1721+/// set, so the row's own [`exact_refusal`] is what a click on it would see.
1722+#[test]
1723+fn exact_derives_its_format_from_the_source_codec() {
1724+ let hevc = PlaybackSession::open(asset("test_hevc.mkv")).expect("an hevc fixture");
1725+ assert_eq!(crate::exact_format(&hevc), Some(Format::Hevc));
1726+
1727+ let av1 = PlaybackSession::open(asset("test_av1.mkv")).expect("an av1 fixture");
1728+ assert_eq!(crate::exact_format(&av1), Some(Format::Av1));
1729+
1730+ let h264 = PlaybackSession::open(asset("test_h264.mkv")).expect("an h264 fixture");
1731+ assert_eq!(h264.export_snapshot().1.codec, engine::demux::Codec::H264);
1732+ assert_eq!(crate::exact_format(&h264), None);
1733+ // No copy path for h264 at any format -- the row's own refusal is what a
1734+ // click on Exact would still show, since `exact_format` sets nothing and
1735+ // the format is left at whatever it already was (Mp4's own refusal, or
1736+ // Hevc's if the pane was left there from an earlier pick).
1737+ assert!(crate::exact_refusal(&h264, Format::Mp4, Quality::Exact).is_some());
1738+ assert!(crate::exact_refusal(&h264, Format::Hevc, Quality::Exact).is_some());
1739+}
1740+
1717 /// The stacking-scrims bug: opening the speed card while the colour card was1741 /// The stacking-scrims bug: opening the speed card while the colour card was
1718 /// up left both up at once, because each `open_*` cleared a different1742 /// up left both up at once, because each `open_*` cleared a different
1719 /// hand-picked subset of the other flags rather than all of them. The fix is1743 /// hand-picked subset of the other flags rather than all of them. The fix is
crates/app/src/ui/cards.rsmodified+13 -4
@@ -604,6 +604,14 @@ impl Player {
604 .mbps_edit604 .mbps_edit
605 .as_ref()605 .as_ref()
606 .filter(|_| quality == Quality::Custom);606 .filter(|_| quality == Quality::Custom);
607+ // Exact's own row carries whatever [`exact_refusal`] says of
608+ // the format currently picked, whether or not Exact is the
609+ // row in force -- the same reason `start_export` would give,
610+ // said here instead of only after the button is pressed.
611+ let exact_why = (quality == Quality::Exact)
612+ .then(|| self.session.as_ref())
613+ .flatten()
614+ .and_then(|s| exact_refusal(s, self.format, quality));
607 let mut r = entry(615 let mut r = entry(
608 ("quality", i),616 ("quality", i),
609 match quality {617 match quality {
@@ -611,9 +619,10 @@ impl Player {
611 _ => "q",619 _ => "q",
612 },620 },
613 quality.label().into(),621 quality.label().into(),
614- match field {622+ match (&exact_why, field) {
615- Some(edit) => edit.detail().into(),623+ (Some(why), _) => why.clone().into(),
616- None => quality.detail(self.custom_mbps).into(),624+ (None, Some(edit)) => edit.detail().into(),
625+ (None, None) => quality.detail(self.custom_mbps).into(),
617 },626 },
618 self.quality == quality,627 self.quality == quality,
619 true,628 true,
@@ -622,7 +631,7 @@ impl Player {
622 move |this, _: &ClickEvent, _, cx| {631 move |this, _: &ClickEvent, _, cx| {
623 match quality {632 match quality {
624 Quality::Custom => this.edit_mbps(),633 Quality::Custom => this.edit_mbps(),
625- _ => this.quality = quality,634+ _ => this.pick_quality(quality),
626 }635 }
627 cx.notify();636 cx.notify();
628 },637 },