Skip to content
Class

InputAudioTrack

Represents an audio track in an input file.

Extends: InputTrack

Used by

Properties

id

ts
get id(): number;

The unique ID of this track in the input file.

input

ts
readonly input: Input;

The input file this track belongs to.

See Input.

number

ts
get number(): number;

The 1-based index of this track among all tracks of the same type in the input file. For example, the first video track has number 1, the second video track has number 2, and so on. The index refers to the order in which the tracks are returned by Input.getTracks.

type

ts
get type(): TrackType;

The type of the track.

See TrackType.

Methods

canBePairedWith()

ts
canBePairedWith(
	other: InputTrack,
): boolean;

Returns true if this track can be paired with the given track. Two tracks being pairable means they can be presented (displayed) together.

Returns false if other equals this.

See InputTrack.

canDecode()

ts
canDecode(): Promise<boolean>;

Checks if this track's packets can be decoded by the browser.

computeDuration()

ts
computeDuration(
	options?: PacketRetrievalOptions,
): Promise<number>;

Returns the end timestamp of the last packet of this track, in seconds.

By default, when the underlying media is live, this method will only resolve once the live stream ends. If you want to query the current end timestamp of the stream, set PacketRetrievalOptions.skipLiveWait to true in the options.

computePacketStats()

ts
computePacketStats(
	targetPacketCount: number = Infinity,
	options?: PacketRetrievalOptions,
): Promise<PacketStats>;

Computes aggregate packet statistics for this track, such as average packet rate or bitrate.

See PacketRetrievalOptions and PacketStats.

determinePacketType()

ts
determinePacketType(
	packet: EncodedPacket,
): Promise<PacketType | null>;

For a given packet of this track, this method determines the actual type of this packet (key/delta) by looking into its bitstream. Returns null if the type couldn't be determined.

See EncodedPacket and PacketType.

getAverageBitrate()

ts
getAverageBitrate(): Promise<number | null>;

Returns the average bitrate of the track in bits per second, as specified in the track's metadata. This might not match the actual media data's bitrate.

getBitrate()

ts
getBitrate(): Promise<number | null>;

Returns the peak bitrate of the track in bits per second, as specified in the track's metadata. This might not match the actual media data's bitrate.

getCodec()

ts
getCodec(): Promise<"aac" | "opus" | "mp3" | "vorbis" | "flac" | "ac3" | "eac3" | "pcm-s16" | "pcm-s16be" | "pcm-s24" | "pcm-s24be" | "pcm-s32" | "pcm-s32be" | "pcm-f32" | "pcm-f32be" | "pcm-f64" | ... 5 more ... | null>;

The codec of the track's packets.

getCodecParameterString()

ts
getCodecParameterString(): Promise<string | null>;

Returns the full codec parameter string for this track.

getDecoderConfig()

ts
getDecoderConfig(): Promise<AudioDecoderConfig | null>;

Returns the decoder configuration for decoding the track's packets using an AudioDecoder. Returns null if the track's codec is unknown.

getDisposition()

ts
getDisposition(): Promise<TrackDisposition>;

Returns the track's disposition, i.e. information about its intended usage.

See TrackDisposition.

getDurationFromMetadata()

ts
getDurationFromMetadata(
	options: DurationMetadataRequestOptions = {},
): Promise<number | null>;

Gets the duration (end timestamp) in seconds of this track from metadata stored in the file. This value may be approximate or diverge from the actual, precise duration returned by .computeDuration(), but compared to that method, this method is cheaper. When the duration cannot be determined from the file metadata, null is returned.

By default, when the underlying media is live, this method will only resolve once the live stream ends. If you want to query the current duration of the media, set DurationMetadataRequestOptions.skipLiveWait to true in the options.

getFirstTimestamp()

ts
getFirstTimestamp(): Promise<number>;

Returns the start timestamp of the first packet of this track, in seconds. While often near zero, this value may be positive or even negative. A negative starting timestamp means the track's timing has been offset. Samples with a negative timestamp should not be presented.

getInternalCodecId()

ts
getInternalCodecId(): Promise<string | number | Uint8Array<ArrayBufferLike> | null>;

Returns the identifier of the codec used internally by the container. It is not homogenized by Mediabunny and depends entirely on the container format.

This method can be used to determine the codec of a track in case Mediabunny doesn't know that codec.

  • For ISOBMFF files, this resolves to the name of the Sample Description Box (e.g. 'avc1').
  • For Matroska files, this resolves to the value of the CodecID element.
  • For WAVE files, this resolves to the value of the format tag in the 'fmt ' chunk.
  • For ADTS files, this resolves to the MPEG-4 Audio Object Type.
  • For MPEG-TS files, this resolves to the streamType value from the Program Map Table.
  • In all other cases, this resolves to null.

getLanguageCode()

ts
getLanguageCode(): Promise<string>;

Returns the ISO 639-2/T language code for this track. If the language is unknown, this resolves to 'und' (undetermined).

getLiveRefreshInterval()

ts
getLiveRefreshInterval(): Promise<number | null>;

Returns the track's live refresh interval in seconds, or null if the track is not live. This interval describes the time it takes, on average, for new live media data to become available.

getName()

ts
getName(): Promise<string | null>;

Returns the user-defined name for this track.

getNumberOfChannels()

ts
getNumberOfChannels(): Promise<number>;

Returns the number of audio channels in the track.

getPairableAudioTracks()

ts
getPairableAudioTracks(
	query?: InputTrackQuery<InputAudioTrack>,
): Promise<InputAudioTrack[]>;

Gets the list of other audio tracks that can be paired with this track. An optional query can be provided to narrow down the results.

See InputTrackQuery.

getPairableTracks()

ts
getPairableTracks(
	query?: InputTrackQuery<InputTrack>,
): Promise<InputTrack[]>;

Gets the list of other tracks that can be paired with this track. An optional query can be provided to narrow down the results.

See InputTrackQuery and InputTrack.

getPairableVideoTracks()

ts
getPairableVideoTracks(
	query?: InputTrackQuery<InputVideoTrack>,
): Promise<InputVideoTrack[]>;

Gets the list of other video tracks that can be paired with this track. An optional query can be provided to narrow down the results.

See InputTrackQuery and InputVideoTrack.

getPrimaryPairableAudioTrack()

ts
getPrimaryPairableAudioTrack(
	query?: InputTrackQuery<InputAudioTrack>,
): Promise<InputAudioTrack | null>;

Returns the primary track that can be paired with this track, optionally steered by the provided query.

See InputTrackQuery.

getPrimaryPairableVideoTrack()

ts
getPrimaryPairableVideoTrack(
	query?: InputTrackQuery<InputVideoTrack>,
): Promise<InputVideoTrack | null>;

Returns the primary track that can be paired with this track, optionally steered by the provided query.

See InputTrackQuery and InputVideoTrack.

getSampleRate()

ts
getSampleRate(): Promise<number>;

Returns the track's audio sample rate in hertz.

getTimeResolution()

ts
getTimeResolution(): Promise<number>;

Returns a positive number x such that all timestamps and durations of all packets of this track are integer multiples of 1/x.

hasOnlyKeyPackets()

ts
hasOnlyKeyPackets(): Promise<boolean>;

Returns whether the track metadata says that this track only contains key packets. The actual packets may differ.

hasPairableAudioTrack()

ts
hasPairableAudioTrack(
	predicate?: (track: InputAudioTrack) => MaybePromise<boolean>,
): Promise<boolean>;

Returns true if there is an audio track that can be paired with this track.

See MaybePromise.

hasPairableTrack()

ts
hasPairableTrack(
	predicate?: (track: InputTrack) => MaybePromise<boolean>,
): Promise<boolean>;

Returns true if there is another track that can be paired with this track.

See InputTrack and MaybePromise.

hasPairableVideoTrack()

ts
hasPairableVideoTrack(
	predicate?: (track: InputVideoTrack) => MaybePromise<boolean>,
): Promise<boolean>;

Returns true if there is a video track that can be paired with this track.

See InputVideoTrack and MaybePromise.

isAudioTrack()

ts
isAudioTrack(): boolean;

Returns true if and only if this track is an audio track.

isLive()

ts
isLive(): Promise<boolean>;

Whether or not this track is currently live, meaning the media's end is still unknown.

The value returned by this method may change over time as the track stops being live. To keep track of the track's live status, poll this method at the track's refresh interval via InputTrack.getLiveRefreshInterval.

isRelativeToUnixEpoch()

ts
isRelativeToUnixEpoch(): Promise<boolean>;

Returns whether the timestamps of this track are relative to the Unix epoch (January 1, 1970 00:00:00 UTC). When true, each timestamp maps to a definitive point in time.

isVideoTrack()

ts
isVideoTrack(): boolean;

Returns true if and only if this track is a video track.

Deprecated

codec

Deprecated. Use getCodec instead.

ts
get codec(): AudioCodec | null;

The codec of the track's packets.

See AudioCodec.

disposition

Deprecated. Use InputTrack.getDisposition instead.

ts
get disposition(): TrackDisposition;

The track's disposition, i.e. information about its intended usage.

See TrackDisposition.

internalCodecId

Deprecated. Use InputTrack.getInternalCodecId instead.

ts
get internalCodecId(): string | number | Uint8Array<ArrayBufferLike> | null;

See InputTrack.getInternalCodecId.

languageCode

Deprecated. Use InputTrack.getLanguageCode instead.

ts
get languageCode(): string;

The ISO 639-2/T language code for this track. If the language is unknown, this field is 'und' (undetermined).

name

Deprecated. Use InputTrack.getName instead.

ts
get name(): string | null;

A user-defined name for this track.

numberOfChannels

Deprecated. Use getNumberOfChannels instead.

ts
get numberOfChannels(): number;

The number of audio channels in the track.

sampleRate

Deprecated. Use getSampleRate instead.

ts
get sampleRate(): number;

The track's audio sample rate in hertz.

timeResolution

Deprecated. Use InputTrack.getTimeResolution instead.

ts
get timeResolution(): number;

A positive number x such that all timestamps and durations of all packets of this track are integer multiples of 1/x.

Released under the Mozilla Public License 2.0.