The AAC encode seat is ec-aac -- export.rs's encode_audio and the muxer's tone harness speak ec_aac::AacEncoder on the seat's old contract (interleaved f32 push_pcm, raw raw_data_block packets one frame long, the sf_index_for_rate refusal the export turns into a user-facing message, ASC rebuilt from AacTrackParams), the caps row and both SW-encode labels read ec-aac, and a new mux witness round-trips seat-encoded mono, stereo and 5.1 through the project's own decode door (symphonia's reader for the pair, the family decoder for 5.1, folded to stereo as the door's contract states). A/B on identical synthetic program -- mono 44.1k 128k, stereo 44.1/48k 256k, stereo 48k 96k, 5.1 48k 512k, every output ADTS-framed and ffmpeg-decoded, alignment by envelope correlation with an ffmpeg-native control column: ec-aac correlates at or above the incumbent on every row (mono 0.9674 vs 0.9564, stereo 96k 0.9445 vs 0.8458, 5.1 0.6050 vs 0.6007) and matches or beats ffmpeg's own encoder at matched actual rate
Browse files at this commit7ed056a6992a03fe021df58900b2e1b754fe75c3Parent: 6421f59- refactor
- the AAC encode seat is ec-aac -- export.rs's encode_audio and the muxer's tone harness speak ec_aac::AacEncoder on the seat's old contract (interleaved f32 push_pcm, raw raw_data_block packets one frame long, the sf_index_for_rate refusal the export turns into a user-facing message, ASC rebuilt from AacTrackParams), the caps row and both SW-encode labels read ec-aac, and a new mux witness round-trips seat-encoded mono, stereo and 5.1 through the project's own decode door (symphonia's reader for the pair, the family decoder for 5.1, folded to stereo as the door's contract states). A/B on identical synthetic program -- mono 44.1k 128k, stereo 44.1/48k 256k, stereo 48k 96k, 5.1 48k 512k, every output ADTS-framed and ffmpeg-decoded, alignment by envelope correlation with an ffmpeg-native control column: ec-aac correlates at or above the incumbent on every row (mono 0.9674 vs 0.9564, stereo 96k 0.9445 vs 0.8458, 5.1 0.6050 vs 0.6007) and matches or beats ffmpeg's own encoder at matched actual rate
- cost is +4-6% actual bits at the same target and a slower encode wall (single-threaded vs rusty_aac's frame-parallel finish: 2.0-3.7x on one core, 5.9-10.2x as-shipped on this box) -- named here per the perf bar. rusty_aac itself leaves in the next commit. Export and capability suites green, -p engine --all-targets 0 warnings
3 changed files +102 -13
- crates/engine/src/caps.rs +3 -3
- crates/engine/src/export.rs +10 -9
- crates/engine/src/mux.rs +89 -1
crates/engine/src/caps.rsmodified+3 -3
| @@ -37,8 +37,8 @@ const SW_CODECS: [(&str, &str, bool, bool); 10] = [ | ||
| 37 | 37 | ("HEVC", "oxideav-h265 intra", false, true), |
| 38 | 38 | ("AV1", "rav1e", false, true), |
| 39 | 39 | // Decode is split by width: symphonia carries stereo and narrower, `ec-aac` |
| 40 | - // everything wider; the encoder is `rusty_aac`. | |
| 41 | - ("AAC", "symphonia / ec-aac / rusty_aac", true, true), | |
| 40 | + // everything wider; the encoder is `ec-aac` as well. | |
| 41 | + ("AAC", "symphonia / ec-aac / ec-aac", true, true), | |
| 42 | 42 | ("MP3", "symphonia / rusty_mp3", true, true), |
| 43 | 43 | ("FLAC", "symphonia / flacenc", true, true), |
| 44 | 44 | ("PCM", "symphonia / hound", true, true), |
| @@ -159,7 +159,7 @@ mod tests { | ||
| 159 | 159 | #[test] |
| 160 | 160 | fn the_software_line_names_every_encoder_this_build_carries() { |
| 161 | 161 | let line = software(); |
| 162 | - for name in ["ec-h264", "oxideav-h265 intra", "rav1e", "rusty_aac"] { | |
| 162 | + for name in ["ec-h264", "oxideav-h265 intra", "rav1e", "ec-aac"] { | |
| 163 | 163 | assert!(line.contains(name), "{name} missing from {line}"); |
| 164 | 164 | } |
| 165 | 165 | // Decode-only crates must not read as encoders, and the seat words are |
crates/engine/src/export.rsmodified+10 -9
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | //! through the encoder exactly as it always did. Where the *sound* cannot be |
| 22 | 22 | //! copied — a second audio lane to mix in, a speeded clip, an |
| 23 | 23 | //! equalized one, a source that is not AAC inside an mp4's own sample table — |
| 24 | -//! the sound is decoded, mixed and encoded again with `rusty_aac` | |
| 24 | +//! the sound is decoded, mixed and encoded again with `ec-aac` | |
| 25 | 25 | //! ([`encode_audio`]). The audio-only formats have no such split: `hound` writes |
| 26 | 26 | //! PCM, `flacenc` encodes FLAC, `rusty_mp3` encodes MP3 and `rusty_vorbis` |
| 27 | 27 | //! encodes Vorbis, so those are always *decoded* out of the timeline. The worker owns everything: the caller gets an |
| @@ -159,7 +159,7 @@ const HEVC_QP_MAX: i32 = 40; | ||
| 159 | 159 | /// WAV, FLAC, MP3 and Ogg Vorbis are the standalone audio formats with a |
| 160 | 160 | /// pure-Rust encoder: `hound`, `flacenc`, `rusty_mp3` and `rusty_vorbis`. Opus |
| 161 | 161 | /// still has none -- `oxideav-opus` encodes CELT alone, which is half a codec. |
| 162 | -/// (AAC has one too -- `rusty_aac`, which is what a re-encoded video track's | |
| 162 | +/// (AAC has one too -- `ec-aac`, which is what a re-encoded video track's | |
| 163 | 163 | /// sound leaves through -- but AAC is a container's own audio, never a file of |
| 164 | 164 | /// its own here.) VP9 and VP8 are the |
| 165 | 165 | /// codecs that come in through the plugin and stop there, HEVC having |
| @@ -864,7 +864,7 @@ fn audio_label( | ||
| 864 | 864 | // has the test), which is why the condition is in this comment |
| 865 | 865 | // instead of in the string. |
| 866 | 866 | false if format.is_mkv() => "Opus · SW encode (ec-opus)", |
| 867 | - false => "AAC · SW encode (rusty_aac)", | |
| 867 | + false => "AAC · SW encode (ec-aac)", | |
| 868 | 868 | }, |
| 869 | 869 | } |
| 870 | 870 | } |
| @@ -889,7 +889,7 @@ fn measured_audio_label( | ||
| 889 | 889 | // Encoded, into a container that would have carried Opus, and it is not |
| 890 | 890 | // Opus: the fidelity gate sent it to AAC ([`OPUS_MIN_FIDELITY`]), or |
| 891 | 891 | // the mix was not 48 kHz at a width the seat is measured in. |
| 892 | - (Some(false), false) if format.is_mkv() => "AAC · SW encode (rusty_aac)", | |
| 892 | + (Some(false), false) if format.is_mkv() => "AAC · SW encode (ec-aac)", | |
| 893 | 893 | // `sound` is already what happened, not a prediction, so `copied` is |
| 894 | 894 | // filled in and `ranged` never reaches the branch that reads it. |
| 895 | 895 | _ => audio_label(project, format, sound.is_some(), sound, false), |
| @@ -1940,9 +1940,10 @@ impl CopyPlan { | ||
| 1940 | 1940 | /// the sound starts at timeline frame 0 as a copied track's does. |
| 1941 | 1941 | /// |
| 1942 | 1942 | /// corner-cut: the mix sits in memory as f32 before it is encoded (~46 MB a |
| 1943 | -/// minute of 48 kHz stereo), for [`run_audio`]'s reason -- `rusty_aac` buffers | |
| 1944 | -/// the whole stream anyway, since it encodes its frames in parallel. Upgrade | |
| 1945 | -/// path is a chunked push once that encoder streams. | |
| 1943 | +/// minute of 48 kHz stereo), for [`run_audio`]'s reason -- sizing the track | |
| 1944 | +/// against the timeline, publishing the mix third of the bar as it goes and | |
| 1945 | +/// answering a cancel before the encode are whole-mix concerns here. The | |
| 1946 | +/// upgrade path is a chunked push: `ec_aac`'s encoder itself streams. | |
| 1946 | 1947 | fn encode_audio( |
| 1947 | 1948 | project: &Project, |
| 1948 | 1949 | meta: &VideoMeta, |
| @@ -1977,7 +1978,7 @@ fn encode_audio( | ||
| 1977 | 1978 | else { |
| 1978 | 1979 | return Ok(None); // no audio to write, exactly as a copy of nothing is |
| 1979 | 1980 | }; |
| 1980 | - let freq_index = rusty_aac::sf_index_for_rate(audio.sample_rate).ok_or_else(|| { | |
| 1981 | + let freq_index = ec_aac::sf_index_for_rate(audio.sample_rate).ok_or_else(|| { | |
| 1981 | 1982 | format!( |
| 1982 | 1983 | "{} Hz is not an AAC sample rate: export WAV, FLAC, MP3 or OGG, which write it as \ |
| 1983 | 1984 | it is", |
| @@ -2058,7 +2059,7 @@ fn encode_audio( | ||
| 2058 | 2059 | |
| 2059 | 2060 | // The caller's rate, never the encoder's own 128 default -- see |
| 2060 | 2061 | // [`DEFAULT_AUDIO_KBPS`] for why the untouched figure is 256. |
| 2061 | - let mut encoder = rusty_aac::AacEncoder::new(rusty_aac::AacEncoderConfig { | |
| 2062 | + let mut encoder = ec_aac::AacEncoder::new(ec_aac::AacEncoderConfig { | |
| 2062 | 2063 | bitrate_bps: kbps * 1_000, |
| 2063 | 2064 | ..Default::default() |
| 2064 | 2065 | }); |
crates/engine/src/mux.rsmodified+89 -1
| @@ -2258,7 +2258,7 @@ mod tests { | ||
| 2258 | 2258 | pcm.push(s); |
| 2259 | 2259 | } |
| 2260 | 2260 | } |
| 2261 | - let mut encoder = rusty_aac::AacEncoder::new(rusty_aac::AacEncoderConfig::default()); | |
| 2261 | + let mut encoder = ec_aac::AacEncoder::new(ec_aac::AacEncoderConfig::default()); | |
| 2262 | 2262 | encoder.push_pcm(&pcm, channels, rate).unwrap(); |
| 2263 | 2263 | encoder.finish(); |
| 2264 | 2264 | let mut packets = Vec::new(); |
| @@ -2348,6 +2348,94 @@ mod tests { | ||
| 2348 | 2348 | std::fs::remove_file(&out).unwrap(); |
| 2349 | 2349 | } |
| 2350 | 2350 | |
| 2351 | + /// The seat an export encodes with, at every width the Matroska muxer can | |
| 2352 | + /// carry: a track it encoded comes back through the project's own decode | |
| 2353 | + /// door -- symphonia's reader for mono and stereo, the family's own | |
| 2354 | + /// `ec-aac` decoder for 5.1, which is where the decode splits -- with its | |
| 2355 | + /// rate and loudness intact, no delivered channel silent. A width wider | |
| 2356 | + /// than a pair arrives folded to stereo ([`crate::audio::downmix`] at the | |
| 2357 | + /// decoder's door), so the 5.1 leg asserts the pair, not the six. | |
| 2358 | + #[test] | |
| 2359 | + fn a_seat_encoded_track_round_trips_at_mono_stereo_and_five_one_widths() { | |
| 2360 | + let sequence = obu(1, &[0x11, 0x22, 0x33]); | |
| 2361 | + let mut key = sequence.clone(); | |
| 2362 | + key.extend_from_slice(&obu(6, &[0xAA; 8])); | |
| 2363 | + let inter = obu(6, &[0xBB; 5]); | |
| 2364 | + for (channels, name) in [(1u16, "mono"), (2, "stereo"), (6, "5.1")] { | |
| 2365 | + let packets = tone_packets(48_000, channels); | |
| 2366 | + let heard: usize = packets.iter().map(|p| p.samples as usize).sum(); | |
| 2367 | + | |
| 2368 | + let out = Scratch::file("ve_mkv_seat_widths", "mkv"); | |
| 2369 | + let mut muxer = MkvMuxer::create( | |
| 2370 | + &out, | |
| 2371 | + &Av1Params { | |
| 2372 | + width: 640, | |
| 2373 | + height: 360, | |
| 2374 | + frame_rate: 30.0, | |
| 2375 | + config: av1_sequence_header(&key).unwrap(), | |
| 2376 | + }, | |
| 2377 | + Some(( | |
| 2378 | + &AudioParams { | |
| 2379 | + freq_index: 3, // 48000 | |
| 2380 | + chan_conf: channels as u8, | |
| 2381 | + sample_rate: 48_000, | |
| 2382 | + opus_pre_skip: None, | |
| 2383 | + }, | |
| 2384 | + packets, | |
| 2385 | + )), | |
| 2386 | + Vec::new(), | |
| 2387 | + ) | |
| 2388 | + .unwrap(); | |
| 2389 | + muxer.write_frame(&key, true).unwrap(); | |
| 2390 | + for _ in 0..14 { | |
| 2391 | + muxer.write_frame(&inter, false).unwrap(); | |
| 2392 | + } | |
| 2393 | + muxer.finish().unwrap(); | |
| 2394 | + | |
| 2395 | + // What the door reports: the file's own width, folded to a pair | |
| 2396 | + // for anything wider -- the door's contract, not a defect. | |
| 2397 | + let want = channels.min(2); | |
| 2398 | + let probe = crate::audio::AudioSession::probe(&out, 0) | |
| 2399 | + .unwrap() | |
| 2400 | + .expect("the file has an audio track"); | |
| 2401 | + assert_eq!( | |
| 2402 | + (probe.sample_rate, probe.channels), | |
| 2403 | + (48_000, want), | |
| 2404 | + "{name}: probed with the wrong shape" | |
| 2405 | + ); | |
| 2406 | + let (audio, chunks) = crate::audio::AudioSession::open(&out) | |
| 2407 | + .unwrap() | |
| 2408 | + .unwrap_or_else(|| panic!("{name}: track decodes through the project's own reader")); | |
| 2409 | + assert_eq!( | |
| 2410 | + (audio.sample_rate, audio.channels), | |
| 2411 | + (48_000, want), | |
| 2412 | + "{name}: opened with the wrong shape" | |
| 2413 | + ); | |
| 2414 | + let samples: Vec<f32> = chunks.into_iter().flat_map(|c| c.samples).collect(); | |
| 2415 | + let frames = samples.len() / usize::from(want); | |
| 2416 | + assert!( | |
| 2417 | + frames + 1024 >= heard && frames <= heard + 2048, | |
| 2418 | + "{name}: {frames} frames read back of {heard} written" | |
| 2419 | + ); | |
| 2420 | + // Every delivered channel carries the tone -- a fold that lost a | |
| 2421 | + // side or a dead decoder would starve one of these. | |
| 2422 | + for c in 0..usize::from(want) { | |
| 2423 | + let n = samples.len() / usize::from(want); | |
| 2424 | + let rms = (samples | |
| 2425 | + .iter() | |
| 2426 | + .skip(c) | |
| 2427 | + .step_by(usize::from(want)) | |
| 2428 | + .take(n) | |
| 2429 | + .map(|s| s * s) | |
| 2430 | + .sum::<f32>() | |
| 2431 | + / n as f32) | |
| 2432 | + .sqrt(); | |
| 2433 | + assert!(rms > 0.05, "{name}: channel {c} came back silent (rms {rms})"); | |
| 2434 | + } | |
| 2435 | + std::fs::remove_file(&out).unwrap(); | |
| 2436 | + } | |
| 2437 | + } | |
| 2438 | + | |
| 2351 | 2439 | /// The same stream in the other container: AV1 into an mp4, whose `av01` |
| 2352 | 2440 | /// sample entry is written by hand, read back through our own demuxer -- |
| 2353 | 2441 | /// which is the only test that the patched box tree is still an mp4. |