-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Description
Describe the feature
Context
When muxing Opus into MPEG-TS with GStreamer and using more than stereo channels, the PMT contains an extension descriptor (tag 0x80) carrying channel/mapping information.
Example pipeline (custom channel count):
audiotestsrc is-live=true wave=ticks \
! audio/x-raw,channels=CHANNEL_COUNT,rate=48000,format=S16LE,layout=interleaved \
! audiomixmatrix mode=first-channels out-channels=CHANNEL_COUNT \
! audio/x-raw,channels=CHANNEL_COUNT,rate=48000,format=S16LE,layout=interleaved \
! capssetter caps="audio/x-raw,channel-mask=(bitmask)0" \
! opusenc bitrate=510000 bitrate-type=cbr inband-fec=true frame-size=10 \
! capsfilter caps="audio/x-opus,channel-mapping-family=(int)255"
Stereo (standard mapping):
audiomixmatrix mode=first-channels out-channels=2 \
! audio/x-raw,channels=2,rate=48000,format=S16LE,layout=interleaved \
! capssetter caps="audio/x-raw,channel-mask=(bitmask)0" \
! opusenc bitrate=510000 bitrate-type=cbr inband-fec=true frame-size=10
Observed Behavior
- For stereo or family 0, the descriptor is short, and
astits.Descriptor.Extension.Unknown
contains just the channel count.
Example:[2]
- For custom mapping (family=255), the payload is longer:
- 6 channels →
[129, 6, 255, 160, 20, 229]
- 8 channels →
[129, 8, 255, 112, 1, 35, 69, 103]
- 6 channels →
Currently, in mediacommon/pkg/formats/mpegts/track.go
, findOpusChannelCount
only inspects the first element, so it fails to extract the correct channel count in the custom mapping case.
Expected Behavior
findOpusChannelCount
should:
- Skip a leading sub-tag byte (≥0x80, e.g.
129
). - Correctly read the channel count (the following byte).
- Optionally expose the channel-mapping-family (e.g.
255
). - Safely ignore or parse trailing bytes if present.
So in the above examples, the function should return:
- 6 channels, family=255 for
[129, 6, 255, 160, 20, 229]
- 8 channels, family=255 for
[129, 8, 255, 112, 1, 35, 69, 103]
Request
Please update findOpusChannelCount
to correctly handle custom mapping families (at least to extract the proper channel count when channel-mapping-family=255
).
If you agree, I’m happy to contribute a PR with a parser that:
- Detects and skips a sub-tag byte,
- Reads channel count and family,
- Falls back gracefully when only a single byte is present (stereo/mono case).
Metadata
Metadata
Assignees
Labels
No labels