Class: Mp4Frag

Mp4Frag(optionsopt)

new Mp4Frag(optionsopt)

Parameters:
Name Type Attributes Description
options object <optional>
Configuration options.
Properties
Name Type Attributes Default Description
readableObjectMode boolean <optional>
false If true, segments will be piped out as an object instead of a Buffer.
hlsPlaylistBase string <optional>
Base name of files in m3u8 playlist. Must only contain letters and underscores. Must be set to generate m3u8 playlist. e.g. 'front_door'.
hlsPlaylistSize number <optional>
4 Number of segments to use in m3u8 playlist. Must be an integer ranging from 2 to 20.
hlsPlaylistExtra number <optional>
0 Number of extra segments to keep in memory. Must be an integer ranging from 0 to 10.
hlsPlaylistInit boolean <optional>
true Indicates that m3u8 playlist should be generated after initialization is created and before media segments are created.
segmentCount number <optional>
2 Number of segments to keep in memory. If using hlsPlaylistBase, value will be calculated from hlsPlaylistSize + hlsPlaylistExtra. Must be an integer ranging from 2 to 30.
pool number <optional>
0 Reuse pooled ArrayBuffer allocations to reduce garbage collection. Set to 1 to activate. Experimental.
Source:
Throws:
Will throw an error if options.hlsPlaylistBase contains characters other than letters(a-zA-Z) and underscores(_).

Members

(readonly) allKeyframes

Properties:
Name Type Description
allKeyframes boolean - Returns a boolean indicating if all segments contain a keyframe.
- Returns false if any segments do not contain a keyframe.
Source:

(readonly) audioCodec

Properties:
Name Type Description
audioCodec string | null - Returns the audio codec information as a string.
- Returns null if requested before initialized event.
Source:

(readonly) duration

Properties:
Name Type Description
duration number - Returns the duration of latest Mp4 segment as a Float(seconds).
- Returns -1 if requested before first segment event.
Source:

(readonly) initialization

Properties:
Name Type Description
initialization Buffer | null - Returns the Mp4 initialization fragment as a Buffer.
- Returns null if requested before initialized event.
Source:

(readonly) keyframe

Properties:
Name Type Description
keyframe boolean - Returns a boolean indicating if the current segment contains a keyframe.
- Returns false if the current segment does not contain a keyframe.
- Returns true if segment only contains audio.
Source:

(readonly) m3u8

Properties:
Name Type Description
m3u8 string | null - Returns the fmp4 HLS m3u8 playlist as a string.
- Returns null if requested before initialized event.
Source:

(readonly) mime

Properties:
Name Type Description
mime string | null - Returns the mime type information as a string.
- Returns null if requested before initialized event.
Source:

(readonly) poolLength

Properties:
Name Type Description
poolLength number - Returns the number of array buffers in pool
- Returns -1 if pool not in use.
Source:

(readonly) segment

Properties:
Name Type Description
segment Buffer | null - Returns the latest Mp4 segment as a Buffer.
- Returns null if requested before first segment event.
Source:

(readonly) segmentObject

Properties:
Name Type Description
segmentObject object - Returns the latest Mp4 segment as an object.
- {segment, sequence, duration, timestamp, keyframe}
- Returns {segment: null, sequence: -1, duration: -1; timestamp: -1, keyframe: true} if requested before first segment event.
Source:

(readonly) segmentObjects

Properties:
Name Type Description
segmentObjects Array | null - Returns the Mp4 segments as an Array of objects
- [{segment, sequence, duration, timestamp, keyframe},...]
- Returns null if requested before first segment event.
Source:

(readonly) sequence

Properties:
Name Type Description
sequence number - Returns the sequence of the latest Mp4 segment as an Integer.
- Returns -1 if requested before first segment event.
Source:

(readonly) timescale

Properties:
Name Type Description
timescale number - Returns the timescale information as a number.
- Returns -1 if requested before initialized event.
Source:

(readonly) timestamp

Properties:
Name Type Description
timestamp number - Returns the timestamp of the latest Mp4 segment as an Integer(milliseconds).
- Returns -1 if requested before first segment event.
Source:

(readonly) totalByteLength

Properties:
Name Type Description
totalByteLength number - Returns the total byte length of the Mp4 initialization and all Mp4 segments as an Integer(bytes).
- Returns -1 if requested before initialized event.
Source:

(readonly) totalDuration

Properties:
Name Type Description
totalDuration number - Returns the total duration of all Mp4 segments as a Float(seconds).
- Returns -1 if requested before first segment event.
Source:

(readonly) videoCodec

Properties:
Name Type Description
videoCodec string | null - Returns the video codec information as a string.
- Returns null if requested before initialized event.
Source:

Methods

getSegmentObject(sequence) → {object|null}

Parameters:
Name Type Description
sequence number | string sequence number - Returns the Mp4 segment that corresponds to the numbered sequence as an object.
- {segment, sequence, duration, timestamp, keyframe}
- Returns null if there is no segment that corresponds to sequence number.
Source:
Returns:
Type
object | null

reset()

Clear cached values
Source:

resetCache()

Clear cached values
Source:

toJSON() → {object}

Source:
Returns:
Type
object

Events

initialized

Fires when the initialization of the Mp4 is parsed from the piped data.
Type:
  • Event
Properties:
Name Type Description
object object
Properties
Name Type Description
mime string Mp4Frag.mime
initialization Buffer Mp4Frag.initialization
m3u8 string Mp4Frag.m3u8
Source:

reset

Fires when reset() is called.
Type:
  • Event
Source:

segment

Fires when the latest Mp4 segment is parsed from the piped data.
Type:
  • Event
Properties:
Name Type Description
object object Mp4Frag.segmentObject
Properties
Name Type Description
segment Buffer Mp4Frag.segment
sequence number Mp4Frag.sequence
duration number Mp4Frag.duration
timestamp number Mp4Frag.timestamp
keyframe number Mp4Frag.keyframe
Source: