From 64cb44f9d7ca78477352ab624dc09ff37737bc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 12 Aug 2026 23:04:18 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80=20fix(export):=20a=20copied=20pict?= =?UTF-8?q?ure=20names=20the=20sound=20it=20was=20really=20written=20with?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The copy path and the Opus seat landed in the same function from two lanes and published two different sentences. The encoder path already names the codec the mix was *measured* to have taken; the copy path was still handing the card the same prediction the card shows before an export starts -- so an mkv whose mix fell back to AAC would have run under a line saying Opus, on precisely the exports that are over in a few seconds. Both branches now read the one flag `copy_audio` came back with. The check is the seam itself: an untouched HEVC timeline (copied block for block) with a 5.1 Opus source folded onto its audio lane (encoded), asserting the published line is "copy · Opus · SW encode (opus-rs)" and that the file carries A_OPUS and no A_AAC. --- crates/engine/src/export.rs | 9 +++- crates/engine/tests/opus_export.rs | 71 ++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 7a73702..ebda6d0 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -1484,7 +1484,14 @@ fn run( eprintln!("export video: copy (source packets)"); *shared.encoders.lock().unwrap() = Some(format!( "copy · {}", - audio_label(project, settings.format, sound.is_some(), sound) + // The measured codec, exactly as the encoder path below publishes + // it: the mix has been opened by now, so a line that fell back to + // AAC says AAC. Naming the prediction here would make the fallback + // invisible on precisely the exports that are over in seconds. + match opus { + true => "Opus · SW encode (opus-rs)", + false => audio_label(project, settings.format, sound.is_some(), sound), + } )); return plan.run( out, diff --git a/crates/engine/tests/opus_export.rs b/crates/engine/tests/opus_export.rs index fda8cfc..5be6726 100644 --- a/crates/engine/tests/opus_export.rs +++ b/crates/engine/tests/opus_export.rs @@ -399,3 +399,74 @@ fn ffmpeg_decode(path: &Path) -> Option> { .collect(), ) } + +/// The one line the card shows while an export runs, where the picture is +/// copied and the sound is not. Two lanes of work meet in that sentence -- the +/// video copy path writes it, the Opus seat decides its second half -- and the +/// half that matters is *measured*: the copy branch used to publish the +/// prediction the card already shows, which would have named Opus on an export +/// that quietly fell back to AAC. +/// +/// The picture is `test_hevc.mkv` untouched, so it is copied block for block; +/// the sound is the 5.1 Opus source folded to the stereo mix Opus is reachable +/// at, so it is encoded. Nothing in the file is decoded to prove this -- the +/// container is read back for the track ids, which is what the two paths +/// actually wrote. +#[test] +fn a_copied_picture_names_the_sound_it_was_written_with() { + pin_software(); + let video = asset("test_hevc.mkv"); + let sound = asset(OPUS); + let (meta, _) = engine::demux::Demuxer::open(&video).expect("probe the picture"); + let frames = meta.frame_count; + let clip = |source, out_frame| Clip { + start: 0, + in_frame: 0, + out_frame, + source, + link: None, + eq: None, + color: None, + fit: FitPolicy::default(), + speed: Speed::NORMAL, + }; + // The sound is source 0, for the reason [`project`] gives: the timeline + // takes its rate and its width from the first source that has any. + let project = Project::from_parts( + vec![Source::new(&sound, 0), Source::new(&video, 0)], + vec![ + (LaneKind::Video, vec![clip(1, frames)]), + (LaneKind::Audio, vec![clip(0, frames)]), + ], + Vec::new(), + Vec::new(), + ) + .expect("a picture lane and an audio lane"); + let out = out_path("copy_line"); + let handle = engine::export::start( + project, + meta, + &out, + &ExportSettings { + format: Format::Hevc, + ..Default::default() + }, + ); + let line = { + wait(&handle, Duration::from_secs(600)).expect("the export finishes"); + handle.encoders().unwrap_or_default() + }; + println!("the card's line: {line}"); + assert!( + line.starts_with("copy · "), + "the untouched picture was not copied: {line}" + ); + assert!( + line.contains("Opus"), + "the copied picture's line does not name the sound it was written with: {line}" + ); + // ...and the file agrees with the line, on both halves. + let bytes = std::fs::read(&*out).expect("read the export back"); + assert!(find(&bytes, b"A_OPUS").is_some(), "the track says A_OPUS"); + assert!(find(&bytes, b"A_AAC").is_none(), "and nothing says A_AAC"); +}