Members
HEAD_MAGIC_ :Uint8Array
The 8 ASCII bytes 'OpusHead' that start the identification header.
Type:
- Uint8Array
- Source:
HEAD_MAPPING_FAMILY_ :number
Offset of the channel mapping family byte in OpusHead (after the 8-byte
magic, the version, the channel count, the pre-skip, the input rate and the
gain) and in dOps (which lacks the magic). Everything from there on is the
same in both.
Type:
- number
- Source:
HEAD_SIZE_ :number
The size of an OpusHead without a channel mapping table.
Type:
- number
- Source:
OPUS_AUDIO_SAMPLE_PER_FRAME :number
Retained for backward compatibility. Prefer getPacketSampleCount(), which
handles multi-frame opus packets correctly.
Type:
- number
- Source:
SAMPLE_RATE :number
Opus always decodes at 48 kHz (RFC 6716); the input rate an OpusHead
announces is informational.
Type:
- number
- Source:
SAMPLES_PER_FRAME_BY_CONFIG_ :Array<number>
Samples per opus frame at 48 kHz, indexed by the 5-bit config field from
the TOC byte. See RFC 6716 §3.1, Table 2.
Type:
- Array<number>
- Source:
Methods
getAudioConfig(metadatanon-null) → {Uint8Array}
Parameters:
| Name | Type | Description |
|---|---|---|
metadata |
shaka.util.TsParser.OpusMetadata |
- Source:
Returns:
- Type
- Uint8Array
getDops(headnon-null) → {Uint8Array}
Converts an OpusHead (Ogg and Matroska) to the payload of the dOps box
(MP4). Both carry the same fields, but OpusHead is little endian and dOps
is big endian.
Parameters:
| Name | Type | Description |
|---|---|---|
head |
Uint8Array |
- Source:
Returns:
- Type
- Uint8Array
getPacketSampleCount(packetnon-null) → {number}
Returns the number of 48 kHz samples represented by an opus packet,
derived from its TOC byte and (for code 3) the frame-count byte.
See RFC 6716 §3.1.
One PES packet in an MPEG-TS opus stream can carry a multi-frame opus
packet (e.g. browser MediaRecorder emits code-3 packets with 3x 20ms
CELT frames = 60ms per packet). Treating one PES packet as one frame's
worth of samples under-counts duration and breaks timeline alignment
in the resulting mp4.
Returned counts are at 48 kHz. This assumes the caller writes the opus
track with a 48 kHz mp4 timescale, which TsParser hardcodes for opus
(RFC 6716: opus always decodes internally at 48 kHz; OpusHead's input
sample rate is informational). If that hardcode ever becomes variable,
scale the return value by (timescale / 48000).
Parameters:
| Name | Type | Description |
|---|---|---|
packet |
Uint8Array | Opus packet starting at the TOC byte. |
- Source:
Returns:
Sample count at 48 kHz.
- Type
- number
makeHead(channelCount, preSkip) → {Uint8Array}
Makes the OpusHead of a plain mono or stereo stream.
Parameters:
| Name | Type | Description |
|---|---|---|
channelCount |
number | |
preSkip |
number | In samples at 48 kHz. |
- Source:
Returns:
- Type
- Uint8Array