cloudflare / cloudflare/moq-rs
moq-pub: Opus-in-CMAF audio tracks fail with 'unknown codec for track' (mp4 crate has no Opus sample entry)
- Dominant language
- Rust
- Stars
- 166
- Forks
- 59
- Avg merge
- 18h 21m
- Merged PRs (30d)
- 22
Description
### Summary
`moq-pub` bails with `unknown codec for track: N` when the input fMP4/CMAF contains an Opus audio track (`dOps` sample entry, RFC 7845-in-ISOBMFF). Root cause: the mp4 crate (0.14) has no typed Opus sample entry, so the codec-detection chain in `moq-pub/src/media.rs` falls through every recognized branch and hits the final bail — there is no audio-handler fallback.
### Reproduction
- moq-pub at `69302d3` (v0.8.15, branch `draft-ietf-moq-transport-14`)
- Input: CMAF with `avc1` video + Opus audio (`dOps`), e.g. from a LiveKit/WebRTC → CMAF packager (Opus is the WebRTC audio codec, so this is the natural pairing for live ingest)
- `ffmpeg`-generated AAC works; the same stream with Opus audio fails at catalog build.
### Workaround we run in production
```rust
} else if trak.mdia.hdlr.handler_type.to_string() == "soun" {
// Opus-in-CMAF (dOps). mp4-rust 0.14 has no typed Opus sample
// entry, so an audio track with no recognized entry is treated
// as Opus (48k stereo).
selection_params.codec = Some("opus".to_string());
selection_params.channel_config = Some("2".to_string());
selection_params.samplerate = Some(48000);
}
```
Placed in the detection chain after the VP9 branch, before the final bail. Limitation acknowledged: it treats *any* unrecognized `soun` entry as Opus 48k stereo. It has run in production for a month publishing live Opus through `draft-14.cloudflare.mediaoverquic.com` (and, as of this week, a provisioned tokened relay) with no issues, but a proper fix would parse the `dOps` box for channel count/sample rate instead of assuming.
Happy to send this as a PR (either the pragmatic fallback with a comment, or with a minimal hand-rolled `dOps` parse) — whichever you'd take.
*(Issue drafted with AI assistance — Claude Fable 5; the patch and its production validation are ours.)*
Contributor guide
Research direction
Start in moq-pub/src/media.rs at the codec-detection chain and inspect how mp4 crate 0.14 exposes sample entries and audio-handler metadata. Trace the dOps case and determine whether a minimal parse or a documented fallback fits the project. Done means an Opus CMAF track builds its catalog instead of returning the unknown-codec error, with audio parameters handled as agreed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100