Skip to content

node-av / lib / Stream

Class: Stream ​

Defined in: src/lib/stream.ts:55

Media stream within a format context.

Represents a single stream (video, audio, subtitle, etc.) within a media container. Contains stream-specific information including codec parameters, timing information, metadata, and disposition flags. Each stream in a file has a unique index and may contain packets of compressed data.

A stream belongs to its format context. Once that context is closed or freed, the stream and its codecpar read their defaults (e.g. index -1) and ignore writes; copy what must outlive the context first.

Direct mapping to FFmpeg's AVStream.

Example ​

typescript
import { FormatContext, FFmpegError } from 'node-av';
import { AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO } from 'node-av/constants';

// Access streams from format context
const formatContext = new FormatContext();
await formatContext.openInput('video.mp4');

// Iterate through streams
for (let i = 0; i < formatContext.nbStreams; i++) {
  const stream = formatContext.streams[i];
  const codecpar = stream.codecpar;

  if (codecpar.codecType === AVMEDIA_TYPE_VIDEO) {
    console.log(`Video stream ${stream.index}:`);
    console.log(`  Codec: ${codecpar.codecId}`);
    console.log(`  Resolution: ${codecpar.width}x${codecpar.height}`);
    console.log(`  Frame rate: ${stream.avgFrameRate.num}/${stream.avgFrameRate.den}`);
  } else if (codecpar.codecType === AVMEDIA_TYPE_AUDIO) {
    console.log(`Audio stream ${stream.index}:`);
    console.log(`  Sample rate: ${codecpar.sampleRate} Hz`);
    console.log(`  Channels: ${codecpar.channels}`);
  }
}

See ​

Implements ​

Constructors ​

Constructor ​

new Stream(native): Stream

Defined in: src/lib/stream.ts:64

Internal

Parameters ​

native ​

NativeStream

The native stream instance

Returns ​

Stream

Accessors ​

attachedPic ​

Get Signature ​

get attachedPic(): Packet | null

Defined in: src/lib/stream.ts:330

Attached picture.

For streams with AV_DISPOSITION_ATTACHED_PIC set, contains the attached picture (e.g., album art).

Direct mapping to AVStream->attached_pic.

Returns ​

Packet | null


avgFrameRate ​

Get Signature ​

get avgFrameRate(): Rational

Defined in: src/lib/stream.ts:248

Average frame rate.

Average framerate of the stream. 0/1 if unknown or variable frame rate.

Direct mapping to AVStream->avg_frame_rate.

Returns ​

Rational

Set Signature ​

set avgFrameRate(value): void

Defined in: src/lib/stream.ts:257

Parameters ​
value ​

Rational

Returns ​

void


codecpar ​

Get Signature ​

get codecpar(): CodecParameters

Defined in: src/lib/stream.ts:105

Codec parameters.

Contains essential codec configuration for this stream. Used to initialize decoders and describe stream properties. Reads defaults once the format context is closed or freed.

Direct mapping to AVStream->codecpar.

Returns ​

CodecParameters

Set Signature ​

set codecpar(value): void

Defined in: src/lib/stream.ts:118

Parameters ​
value ​

CodecParameters

Returns ​

void


discard ​

Get Signature ​

get discard(): AVDiscard

Defined in: src/lib/stream.ts:215

Discard setting.

Indicates which packets can be discarded during demuxing. Used to skip non-essential packets for performance.

Direct mapping to AVStream->discard.

Returns ​

AVDiscard

Set Signature ​

set discard(value): void

Defined in: src/lib/stream.ts:219

Parameters ​
value ​

AVDiscard

Returns ​

void


disposition ​

Get Signature ​

get disposition(): AVDisposition

Defined in: src/lib/stream.ts:199

Stream disposition flags.

Combination of AV_DISPOSITION_* flags indicating stream properties (e.g., default, forced subtitles, visual impaired, etc.).

Direct mapping to AVStream->disposition.

Returns ​

AVDisposition

Set Signature ​

set disposition(value): void

Defined in: src/lib/stream.ts:203

Parameters ​
value ​

AVDisposition

Returns ​

void


duration ​

Get Signature ​

get duration(): bigint

Defined in: src/lib/stream.ts:167

Stream duration.

Total duration in stream time base units. AV_NOPTS_VALUE if unknown.

Direct mapping to AVStream->duration.

Returns ​

bigint

Set Signature ​

set duration(value): void

Defined in: src/lib/stream.ts:171

Parameters ​
value ​

bigint

Returns ​

void


eventFlags ​

Get Signature ​

get eventFlags(): AVStreamEventFlag

Defined in: src/lib/stream.ts:351

Event flags.

Flags indicating events that happened to the stream. Used for signaling format changes.

Direct mapping to AVStream->event_flags.

Returns ​

AVStreamEventFlag

Set Signature ​

set eventFlags(value): void

Defined in: src/lib/stream.ts:355

Parameters ​
value ​

AVStreamEventFlag

Returns ​

void


id ​

Get Signature ​

get id(): number

Defined in: src/lib/stream.ts:88

Stream ID.

Format-specific stream identifier. May be used by some formats for internal stream identification.

Direct mapping to AVStream->id.

Returns ​

number

Set Signature ​

set id(value): void

Defined in: src/lib/stream.ts:92

Parameters ​
value ​

number

Returns ​

void


index ​

Get Signature ​

get index(): number

Defined in: src/lib/stream.ts:76

Stream index.

Zero-based index of this stream in the format context. Used to identify packets belonging to this stream.

Direct mapping to AVStream->index.

Returns ​

number


metadata ​

Get Signature ​

get metadata(): Dictionary | null

Defined in: src/lib/stream.ts:307

Stream metadata.

Dictionary containing stream-specific metadata (e.g., language, title, encoder settings).

Returns a copy of AVStream->metadata - mutating the returned Dictionary does not affect the stream. Assign it back to apply changes.

Returns ​

Dictionary | null

Set Signature ​

set metadata(value): void

Defined in: src/lib/stream.ts:318

Parameters ​
value ​

Dictionary | null

Returns ​

void


nbFrames ​

Get Signature ​

get nbFrames(): bigint

Defined in: src/lib/stream.ts:183

Number of frames.

Total number of frames in this stream. 0 if unknown.

Direct mapping to AVStream->nb_frames.

Returns ​

bigint

Set Signature ​

set nbFrames(value): void

Defined in: src/lib/stream.ts:187

Parameters ​
value ​

bigint

Returns ​

void


parser ​

Get Signature ​

get parser(): CodecParser | null

Defined in: src/lib/stream.ts:381

Get the codec parser attached to this stream.

Returns the parser context if the stream has an active parser, null otherwise. Parsers are automatically created by FFmpeg for certain formats and codecs. Useful for accessing parser state like repeat_pict for interlaced video.

Direct mapping to av_stream_get_parser().

Example ​
typescript
const parser = stream.parser;
if (parser) {
  const fields = 1 + parser.repeatPict;
  console.log(`Frame uses ${fields} fields`);
}
See ​

CodecParser For parser details

Returns ​

CodecParser | null

Parser context or null if no parser attached


ptsWrapBits ​

Get Signature ​

get ptsWrapBits(): number

Defined in: src/lib/stream.ts:290

Number of bits for PTS wrap-around detection.

Used for timestamp wrap-around correction in formats with limited timestamp bits. Common values: 33 (MPEG-TS), 31 (DVB), 64 (no wrapping).

Direct mapping to AVStream->pts_wrap_bits.

Returns ​

number

Set Signature ​

set ptsWrapBits(value): void

Defined in: src/lib/stream.ts:294

Parameters ​
value ​

number

Returns ​

void


rFrameRate ​

Get Signature ​

get rFrameRate(): Rational

Defined in: src/lib/stream.ts:269

Real frame rate.

Real base frame rate of the stream. This is the lowest common multiple of all frame rates in the stream.

Direct mapping to AVStream->r_frame_rate.

Returns ​

Rational

Set Signature ​

set rFrameRate(value): void

Defined in: src/lib/stream.ts:278

Parameters ​
value ​

Rational

Returns ​

void


sampleAspectRatio ​

Get Signature ​

get sampleAspectRatio(): Rational

Defined in: src/lib/stream.ts:231

Sample aspect ratio.

Pixel aspect ratio for video streams. 0/1 if unknown or not applicable.

Direct mapping to AVStream->sample_aspect_ratio.

Returns ​

Rational

Set Signature ​

set sampleAspectRatio(value): void

Defined in: src/lib/stream.ts:236

Parameters ​
value ​

Rational

Returns ​

void


startTime ​

Get Signature ​

get startTime(): bigint

Defined in: src/lib/stream.ts:151

Start time.

First timestamp of the stream in stream time base units. AV_NOPTS_VALUE if unknown.

Direct mapping to AVStream->start_time.

Returns ​

bigint

Set Signature ​

set startTime(value): void

Defined in: src/lib/stream.ts:155

Parameters ​
value ​

bigint

Returns ​

void


timeBase ​

Get Signature ​

get timeBase(): Rational

Defined in: src/lib/stream.ts:134

Stream time base.

Unit of time for timestamps in this stream. All timestamps (PTS/DTS) are in units of this time base.

Direct mapping to AVStream->time_base.

Returns ​

Rational

Set Signature ​

set timeBase(value): void

Defined in: src/lib/stream.ts:139

Parameters ​
value ​

Rational

Returns ​

void

Methods ​

clearDisposition() ​

clearDisposition(...flags): void

Defined in: src/lib/stream.ts:523

Clear stream disposition flags.

Clears one or more disposition flags using bitwise AND NOT. Allows clearing multiple flags without manually performing bitwise operations.

Parameters ​

flags ​

...AVDisposition[]

One or more disposition flag values to clear

Returns ​

void

Example ​

typescript
import { AV_DISPOSITION_FORCED } from 'node-av/constants';

// Clear specific disposition flag
stream.clearDisposition(AV_DISPOSITION_FORCED);

See ​


clearEventFlags() ​

clearEventFlags(...flags): void

Defined in: src/lib/stream.ts:440

Clear stream event flags.

Clears one or more event flags using bitwise AND NOT. Allows clearing multiple flags without manually performing bitwise operations.

Parameters ​

flags ​

...AVStreamEventFlag[]

One or more event flag values to clear

Returns ​

void

Example ​

typescript
import { AVSTREAM_EVENT_FLAG_METADATA_UPDATED } from 'node-av/constants';

// Clear specific event flag
stream.clearEventFlags(AVSTREAM_EVENT_FLAG_METADATA_UPDATED);

See ​


getNative() ​

getNative(): NativeStream

Defined in: src/lib/stream.ts:567

Internal

Get the underlying native Stream object.

Returns ​

NativeStream

The native Stream binding object

Implementation of ​

NativeWrapper.getNative


hasDisposition() ​

hasDisposition(...flags): boolean

Defined in: src/lib/stream.ts:551

Check if stream has specific disposition flags.

Tests whether all specified disposition flags are set using bitwise AND.

Parameters ​

flags ​

...AVDisposition[]

One or more disposition flag values to check

Returns ​

boolean

true if all specified disposition flags are set, false otherwise

Example ​

typescript
import { AV_DISPOSITION_DEFAULT } from 'node-av/constants';

if (stream.hasDisposition(AV_DISPOSITION_DEFAULT)) {
  console.log('Stream is marked as default');
}

See ​


hasEventFlags() ​

hasEventFlags(...flags): boolean

Defined in: src/lib/stream.ts:468

Check if stream has specific event flags.

Tests whether all specified event flags are set using bitwise AND.

Parameters ​

flags ​

...AVStreamEventFlag[]

One or more event flag values to check

Returns ​

boolean

true if all specified event flags are set, false otherwise

Example ​

typescript
import { AVSTREAM_EVENT_FLAG_METADATA_UPDATED } from 'node-av/constants';

if (stream.hasEventFlags(AVSTREAM_EVENT_FLAG_METADATA_UPDATED)) {
  console.log('Stream metadata was updated');
}

See ​


setDisposition() ​

setDisposition(...flags): void

Defined in: src/lib/stream.ts:497

Set stream disposition flags.

Sets one or more disposition flags using bitwise OR. Allows setting multiple flags without manually performing bitwise operations.

Parameters ​

flags ​

...AVDisposition[]

One or more disposition flag values to set

Returns ​

void

Example ​

typescript
import { AV_DISPOSITION_DEFAULT, AV_DISPOSITION_FORCED } from 'node-av/constants';

// Set multiple disposition flags at once
stream.setDisposition(AV_DISPOSITION_DEFAULT, AV_DISPOSITION_FORCED);

See ​


setEventFlags() ​

setEventFlags(...flags): void

Defined in: src/lib/stream.ts:414

Set stream event flags.

Sets one or more event flags using bitwise OR. Allows setting multiple flags without manually performing bitwise operations.

Parameters ​

flags ​

...AVStreamEventFlag[]

One or more event flag values to set

Returns ​

void

Example ​

typescript
import { AVSTREAM_EVENT_FLAG_METADATA_UPDATED, AVSTREAM_EVENT_FLAG_NEW_PACKETS } from 'node-av/constants';

// Set multiple event flags at once
stream.setEventFlags(AVSTREAM_EVENT_FLAG_METADATA_UPDATED, AVSTREAM_EVENT_FLAG_NEW_PACKETS);

See ​