A copied picture names the sound it was really written with
Browse files at this commit64cb44f9d7ca78477352ab624dc09ff37737bc9bParent: cb2833f- fix
- a copied picture names the sound it was really written with
2 changed files +79 -1
crates/engine/src/export.rsmodified+8 -1
| @@ -1484,7 +1484,14 @@ fn run( | ||
| 1484 | 1484 | eprintln!("export video: copy (source packets)"); |
| 1485 | 1485 | *shared.encoders.lock().unwrap() = Some(format!( |
| 1486 | 1486 | "copy · {}", |
| 1487 | - audio_label(project, settings.format, sound.is_some(), sound) | |
| 1487 | + // The measured codec, exactly as the encoder path below publishes | |
| 1488 | + // it: the mix has been opened by now, so a line that fell back to | |
| 1489 | + // AAC says AAC. Naming the prediction here would make the fallback | |
| 1490 | + // invisible on precisely the exports that are over in seconds. | |
| 1491 | + match opus { | |
| 1492 | + true => "Opus · SW encode (opus-rs)", | |
| 1493 | + false => audio_label(project, settings.format, sound.is_some(), sound), | |
| 1494 | + } | |
| 1488 | 1495 | )); |
| 1489 | 1496 | return plan.run( |
| 1490 | 1497 | out, |
crates/engine/tests/opus_export.rsmodified+71 -0
| @@ -399,3 +399,74 @@ fn ffmpeg_decode(path: &Path) -> Option<Vec<f32>> { | ||
| 399 | 399 | .collect(), |
| 400 | 400 | ) |
| 401 | 401 | } |
| 402 | + | |
| 403 | +/// The one line the card shows while an export runs, where the picture is | |
| 404 | +/// copied and the sound is not. Two lanes of work meet in that sentence -- the | |
| 405 | +/// video copy path writes it, the Opus seat decides its second half -- and the | |
| 406 | +/// half that matters is *measured*: the copy branch used to publish the | |
| 407 | +/// prediction the card already shows, which would have named Opus on an export | |
| 408 | +/// that quietly fell back to AAC. | |
| 409 | +/// | |
| 410 | +/// The picture is `test_hevc.mkv` untouched, so it is copied block for block; | |
| 411 | +/// the sound is the 5.1 Opus source folded to the stereo mix Opus is reachable | |
| 412 | +/// at, so it is encoded. Nothing in the file is decoded to prove this -- the | |
| 413 | +/// container is read back for the track ids, which is what the two paths | |
| 414 | +/// actually wrote. | |
| 415 | +#[test] | |
| 416 | +fn a_copied_picture_names_the_sound_it_was_written_with() { | |
| 417 | + pin_software(); | |
| 418 | + let video = asset("test_hevc.mkv"); | |
| 419 | + let sound = asset(OPUS); | |
| 420 | + let (meta, _) = engine::demux::Demuxer::open(&video).expect("probe the picture"); | |
| 421 | + let frames = meta.frame_count; | |
| 422 | + let clip = |source, out_frame| Clip { | |
| 423 | + start: 0, | |
| 424 | + in_frame: 0, | |
| 425 | + out_frame, | |
| 426 | + source, | |
| 427 | + link: None, | |
| 428 | + eq: None, | |
| 429 | + color: None, | |
| 430 | + fit: FitPolicy::default(), | |
| 431 | + speed: Speed::NORMAL, | |
| 432 | + }; | |
| 433 | + // The sound is source 0, for the reason [`project`] gives: the timeline | |
| 434 | + // takes its rate and its width from the first source that has any. | |
| 435 | + let project = Project::from_parts( | |
| 436 | + vec![Source::new(&sound, 0), Source::new(&video, 0)], | |
| 437 | + vec![ | |
| 438 | + (LaneKind::Video, vec![clip(1, frames)]), | |
| 439 | + (LaneKind::Audio, vec![clip(0, frames)]), | |
| 440 | + ], | |
| 441 | + Vec::new(), | |
| 442 | + Vec::new(), | |
| 443 | + ) | |
| 444 | + .expect("a picture lane and an audio lane"); | |
| 445 | + let out = out_path("copy_line"); | |
| 446 | + let handle = engine::export::start( | |
| 447 | + project, | |
| 448 | + meta, | |
| 449 | + &out, | |
| 450 | + &ExportSettings { | |
| 451 | + format: Format::Hevc, | |
| 452 | + ..Default::default() | |
| 453 | + }, | |
| 454 | + ); | |
| 455 | + let line = { | |
| 456 | + wait(&handle, Duration::from_secs(600)).expect("the export finishes"); | |
| 457 | + handle.encoders().unwrap_or_default() | |
| 458 | + }; | |
| 459 | + println!("the card's line: {line}"); | |
| 460 | + assert!( | |
| 461 | + line.starts_with("copy · "), | |
| 462 | + "the untouched picture was not copied: {line}" | |
| 463 | + ); | |
| 464 | + assert!( | |
| 465 | + line.contains("Opus"), | |
| 466 | + "the copied picture's line does not name the sound it was written with: {line}" | |
| 467 | + ); | |
| 468 | + // ...and the file agrees with the line, on both halves. | |
| 469 | + let bytes = std::fs::read(&*out).expect("read the export back"); | |
| 470 | + assert!(find(&bytes, b"A_OPUS").is_some(), "the track says A_OPUS"); | |
| 471 | + assert!(find(&bytes, b"A_AAC").is_none(), "and nothing says A_AAC"); | |
| 472 | +} |