Constructor
new TsParser()
Members
CRC_TABLE_ :shaka.util.Lazy<!Uint32Array>
The lookup table of the MPEG-2 CRC-32, built on first use.
Type:
- shaka.util.Lazy<!Uint32Array>
- Source:
MAX_SCTE35_SECTION_LENGTH_ :number
The section_length is 12 bits, but SCTE 35 limits the whole section to
4096 bytes.
Type:
- number
- Source:
MAX_TS_ :number
2^33, where 33-bit MPEG-2 timestamps wrap.
Type:
- number
- Source:
PROFILES_WITH_OPTIONAL_SPS_DATA_ :Array<number>
Values of profile_idc that indicate additional fields are included in the
SPS.
see Recommendation ITU-T H.264 (4/2013)
7.3.2.1.1 Sequence parameter set data syntax
Type:
- Array<number>
- Source:
audioData_ :Array<!Uint8Array>
Flat list of all audio TS packets.
Type:
- Array<!Uint8Array>
- Source:
audioDataPesIndices_ :Array<number>
Index into audioData_ where each audio PES unit starts.
Type:
- Array<number>
- Source:
av1Metadata_ :Uint8Array
The first three bytes of the AV1_video_descriptor, which the AV1 in
MPEG-2 TS spec requires to describe the whole stream.
Type:
- Uint8Array
- Source:
id3Data_ :Array<!Uint8Array>
Flat list of all ID3 TS packets.
Type:
- Array<!Uint8Array>
- Source:
id3DataPesIndices_ :Array<number>
Index into id3Data_ where each ID3 PES unit starts.
Type:
- Array<number>
- Source:
scte35Partials_ :Map<number, !Uint8Array>
The bytes received so far of a section that spans several TS packets,
by PID.
Type:
- Map<number, !Uint8Array>
- Source:
scte35Pids_ :Set<number>
The PIDs the PMT lists as carrying SCTE-35 splice_info_sections.
Type:
- Set<number>
- Source:
videoData_ :Array<!Uint8Array>
Flat list of all video TS packets.
Type:
- Array<!Uint8Array>
- Source:
videoDataPesIndices_ :Array<number>
Index into videoData_ where each video PES unit starts.
Type:
- Array<number>
- Source:
Methods
crc32(datanon-null) → {number}
The CRC-32 of MPEG-2 PSI sections. Over a whole section, including its
CRC_32 field, it is 0.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array |
- Source:
Returns:
- Type
- number
probe(data) → {boolean}
Check if the passed data corresponds to an MPEG2-TS
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array |
- Source:
Returns:
- Type
- boolean
syncOffset(data) → {number}
Returns the synchronization offset
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array |
- Source:
Returns:
- Type
- number
addScte35Bytes_(pid, bytesnon-null) → {number}
Add bytes to the section being reassembled on a SCTE-35 PID, or start a
new one, and keep the section once it is complete.
Parameters:
| Name | Type | Description |
|---|---|---|
pid |
number | |
bytes |
Uint8Array |
- Source:
Returns:
How many of the bytes belong to the section.
- Type
- number
byteToHex_(x) → {string}
Convert a byte to 2 digits of hex. (Only handles values 0-255.)
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number |
- Source:
Returns:
- Type
- string
concatPesPacketRange_(packetsnon-null, range) → {Uint8Array}
Parameters:
| Name | Type | Description |
|---|---|---|
packets |
Array<!Uint8Array> | Flat list of all TS packets for a PID. |
range |
{first: number, end: number} | Packet range to concatenate. |
- Source:
Returns:
- Type
- Uint8Array
concatPesPackets_(packetsnon-null, pesIndicesnon-null, pesIdx) → {Uint8Array}
Concatenate all TS packets that belong to a single PES unit.
Parameters:
| Name | Type | Description |
|---|---|---|
packets |
Array<!Uint8Array> | Flat list of all TS packets for a PID. |
pesIndices |
Array<number> | Start index in `packets` for each PES. |
pesIdx |
number | Index into `pesIndices` for the desired PES. |
- Source:
Returns:
- Type
- Uint8Array
getAudioData() → {Array<shaka.extern.MPEG_PES>}
Return the audio data
- Source:
Returns:
- Type
- Array<shaka.extern.MPEG_PES>
getAv1Info_() → {{height: ?string, width: ?string, codec: ?string, frameRate: ?number}}
Return the video information for AV1
The dimensions live in the sequence header, inside the elementary stream,
and reading them means parsing OBUs, which is the transmuxer's job. What
is available here is the AV1 video descriptor, which the spec requires to
signal the profile, tier and highest level of the whole stream.
- Source:
Returns:
- Type
- {height: ?string, width: ?string, codec: ?string, frameRate: ?number}
getAvcInfo_() → {{height: ?string, width: ?string, codec: ?string, frameRate: ?number}}
Return the video information for AVC
- Source:
Returns:
- Type
- {height: ?string, width: ?string, codec: ?string, frameRate: ?number}
getCodecs() → {{audio: ?string, video: ?string}}
Return the audio and video codecs
- Source:
Returns:
- Type
- {audio: ?string, video: ?string}
getHvcInfo_() → {{height: ?string, width: ?string, codec: ?string, frameRate: ?number}}
Return the video information for HVC
- Source:
Returns:
- Type
- {height: ?string, width: ?string, codec: ?string, frameRate: ?number}
getMetadata() → {Array<shaka.extern.ID3Metadata>}
Return the ID3 metadata
- Source:
Returns:
- Type
- Array<shaka.extern.ID3Metadata>
getPesPacketRange_(packetsnon-null, pesIndicesnon-null, pesIdx) → {{first: number, end: number}}
Parameters:
| Name | Type | Description |
|---|---|---|
packets |
Array<!Uint8Array> | Flat list of all TS packets for a PID. |
pesIndices |
Array<number> | Start index in `packets` for each PES. |
pesIdx |
number | Index into `pesIndices` for the desired PES. |
- Source:
Returns:
- Type
- {first: number, end: number}
getPmtId_(data, offset) → {number}
Get the PMT ID of the first program the PAT lists, keeping the current
one when it lists none.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array | |
offset |
number |
- Source:
Returns:
- Type
- number
getRequiredPesHeaderLength_(datanon-null) → {number}
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array | PES data with at least `MIN_PES_HEADER_LENGTH_` bytes. |
- Source:
Returns:
- Type
- number
getScte35Sections() → {Array<shaka.util.TsParser.Scte35Section>}
Return the SCTE-35 splice_info_sections found by the last call to
parse(). The sections are retransmitted, so the same one may be found
again in later data.
- Source:
Returns:
- Type
- Array<shaka.util.TsParser.Scte35Section>
getStartTime(contentType) → {number}
Return the start time for the audio and video
Parameters:
| Name | Type | Description |
|---|---|---|
contentType |
string |
- Source:
Returns:
- Type
- number
getStartTimeFromPes_(pes) → {number}
Parameters:
| Name | Type | Description |
|---|---|---|
pes |
{pts: ?number, dts: ?number} |
- Source:
Returns:
- Type
- number
getStartTimeFromPesHeaders(contentType) → {number}
Return the start time for the audio or video by parsing only PES headers.
This is intended for append-time timestamp offset calculation, where
callers do not need the parsed PES payloads.
Parameters:
| Name | Type | Description |
|---|---|---|
contentType |
string |
- Source:
Returns:
- Type
- number
getVideoData(naluProcessingopt) → {Array<shaka.extern.MPEG_PES>}
Return the video data
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
naluProcessing |
boolean |
<optional> |
true |
- Source:
Returns:
- Type
- Array<shaka.extern.MPEG_PES>
getVideoInfo() → {{height: ?string, width: ?string, codec: ?string, frameRate: ?number}}
Return the video information
- Source:
Returns:
- Type
- {height: ?string, width: ?string, codec: ?string, frameRate: ?number}
getVideoNalus() → {Array<shaka.extern.VideoNalu>}
Return the video data
- Source:
Returns:
- Type
- Array<shaka.extern.VideoNalu>
handleRollover_(value, reference) → {number}
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | |
reference |
number |
- Source:
Returns:
- Type
- number
parse(data) → {shaka.util.TsParser}
Parse the given data
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array |
- Source:
Returns:
- Type
- shaka.util.TsParser
parseNalus(pes, lastInfo) → {Array<shaka.extern.VideoNalu>}
Parse AVC and HVC Nalus
The code is based on hls.js
Credit to https://github.com/video-dev/hls.js/blob/master/src/demux/tsdemuxer.ts
Parameters:
| Name | Type | Description |
|---|---|---|
pes |
shaka.extern.MPEG_PES | |
lastInfo |
{nalu: ?shaka.extern.VideoNalu, state: ?number} |
- Source:
Returns:
- Type
- Array<shaka.extern.VideoNalu>
parsePES_(datanon-null) → {shaka.extern.MPEG_PES}
Parse PES
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array |
- Source:
Returns:
parsePESHeader_(datanon-null, fullPesByteLength) → {?{packetLength: number, payloadStartOffset: number, pts: ?number, dts: ?number}}
Parse the PES header without requiring the full payload.
This updates PTS/DTS rollover reference state, so callers that depend on
rollover-corrected timestamps across multiple PES packets must parse
headers in PES order.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array | PES bytes available to read from. May contain only the first TS packet payload, so this can be smaller than the full PES. Use `data.byteLength` for bounds checks on readable bytes. |
fullPesByteLength |
number | Total byte length of the complete PES (sum of all its TS packet payloads), which may be larger than `data.byteLength`. Use this only for reasoning about the full PES, never for indexing into `data`. |
- Source:
Returns:
- Type
- ?{packetLength: number, payloadStartOffset: number, pts: ?number, dts: ?number}
parsePMT_(data, offset) → {shaka.util.TsParser.PMT}
Parse PMT
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array | |
offset |
number |
- Source:
Returns:
parseScte35Payload_(pid, payloadnon-null, payloadUnitStartIndicator)
Reassemble the splice_info_sections carried in the payload of one TS
packet of a SCTE-35 PID. A section may start in one packet and end in
later ones, and a packet may hold several sections.
Parameters:
| Name | Type | Description |
|---|---|---|
pid |
number | |
payload |
Uint8Array | |
payloadUnitStartIndicator |
boolean |
- Source:
parseScte35Section_(pid, sectionnon-null) → {shaka.util.TsParser.Scte35Section}
Parameters:
| Name | Type | Description |
|---|---|---|
pid |
number | |
section |
Uint8Array | A complete splice_info_section, CRC checked. |
- Source:
Returns:
read33Bits_(datanon-null, position) → {number}
Read a 33-bit field whose most significant bit is the lowest bit of the
byte at the given position.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Uint8Array | |
position |
number |
- Source:
Returns:
- Type
- number
setDiscontinuitySequence(discontinuitySequence)
Set the current discontinuity sequence number.
Parameters:
| Name | Type | Description |
|---|---|---|
discontinuitySequence |
number |
- Source:
startsWithVideoKeyframe() → {boolean}
Tells whether the video starts with a key frame, by parsing only as far
as its first slice. Key frames are told apart the same way the
transmuxer does. Video that does not start with one carries on a GOP
started earlier, in the segment before.
- Source:
Returns:
Null when there is no H.264 or H.265 video to tell.
- Type
- boolean
Type Definitions
OpusMetadata
PMT.
Type:
- {channelCount: number, channelConfigCode: number, sampleRate: number}
Properties:
| Name | Type | Description |
|---|---|---|
channelCount |
number | |
channelConfigCode |
number | |
sampleRate |
number |
- Source:
PMT
PMT.
Type:
- {audio: number, video: number, id3: number, scte35: !Array<number>, audioCodec: string, videoCodec: string}
Properties:
| Name | Type | Description |
|---|---|---|
audio |
number | Audio PID |
video |
number | Video PID |
id3 |
number | ID3 PID |
scte35 |
Array<number> | SCTE-35 PIDs |
audioCodec |
string | Audio codec |
videoCodec |
string | Video codec |
- Source:
Scte35Section
A SCTE-35 splice_info_section found in a transport stream.
Type:
- {pid: number, section: !Uint8Array, pts: ?number, commandType: number, crc: number}
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
pid |
number | The PID that carried it. | |
section |
Uint8Array | The complete section, CRC_32 included. | |
pts |
number |
<nullable> |
The splice time, in 90 kHz units, with pts_adjustment applied and wrapped to 33 bits. Null for immediate, cancelled or encrypted commands, and for commands that carry no time. |
commandType |
number | The splice_command_type. | |
crc |
number | The section's CRC_32, which tells retransmissions apart from new sections. |
- Source: