Skip to content

node-av / lib / Stream

Class: Stream

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

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.

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:59

Internal

Parameters

native

NativeStream

The native stream instance

Returns

Stream

Accessors

attachedPic

Get Signature

get attachedPic(): null | Packet

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

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

null | Packet


avgFrameRate

Get Signature

get avgFrameRate(): Rational

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

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:251

Parameters
value

Rational

Returns

void


codecpar

Get Signature

get codecpar(): CodecParameters

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

Codec parameters.

Contains essential codec configuration for this stream. Used to initialize decoders and describe stream properties.

Direct mapping to AVStream->codecpar.

Returns

CodecParameters

Set Signature

set codecpar(value): void

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

Parameters
value

CodecParameters

Returns

void


discard

Get Signature

get discard(): AVDiscard

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

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:213

Parameters
value

AVDiscard

Returns

void


disposition

Get Signature

get disposition(): AVDisposition

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

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:197

Parameters
value

AVDisposition

Returns

void


duration

Get Signature

get duration(): bigint

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

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:165

Parameters
value

bigint

Returns

void


eventFlags

Get Signature

get eventFlags(): AVStreamEventFlag

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

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:320

Parameters
value

AVStreamEventFlag

Returns

void


id

Get Signature

get id(): number

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

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:87

Parameters
value

number

Returns

void


index

Get Signature

get index(): number

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

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(): null | Dictionary

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

Stream metadata.

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

Direct mapping to AVStream->metadata.

Returns

null | Dictionary

Set Signature

set metadata(value): void

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

Parameters
value

null | Dictionary

Returns

void


nbFrames

Get Signature

get nbFrames(): bigint

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

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:181

Parameters
value

bigint

Returns

void


rFrameRate

Get Signature

get rFrameRate(): Rational

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

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:272

Parameters
value

Rational

Returns

void


sampleAspectRatio

Get Signature

get sampleAspectRatio(): Rational

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

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:230

Parameters
value

Rational

Returns

void


startTime

Get Signature

get startTime(): bigint

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

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:149

Parameters
value

bigint

Returns

void


timeBase

Get Signature

get timeBase(): Rational

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

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:133

Parameters
value

Rational

Returns

void

Methods

getNative()

getNative(): NativeStream

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

Internal

Get the underlying native Stream object.

Returns

NativeStream

The native Stream binding object

Implementation of

NativeWrapper.getNative