Skip to content

node-av / lib / CodecContext

Class: CodecContext

Defined in: src/lib/codec-context.ts:74

Codec context for encoding and decoding.

Main structure for codec operations, containing all codec parameters and state. Handles encoding raw frames to packets and decoding packets to frames. Supports both software and hardware-accelerated codecs. Must be configured and opened before use.

Direct mapping to FFmpeg's AVCodecContext.

Example

typescript
import { CodecContext, Codec, FFmpegError } from 'node-av';
import { AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P } from 'node-av/constants';

// Create decoder
const decoder = new CodecContext();
const codec = Codec.findDecoder(AV_CODEC_ID_H264);
decoder.allocContext3(codec);

// Configure from stream parameters
decoder.parametersToContext(stream.codecpar);

// Open decoder
let ret = await decoder.open2(codec);
FFmpegError.throwIfError(ret, 'open2');

// Decode packets
ret = await decoder.sendPacket(packet);
if (ret >= 0) {
  ret = await decoder.receiveFrame(frame);
  if (ret >= 0) {
    // Process decoded frame
  }
}

// Cleanup
decoder.freeContext();

See

Extends

Implements

Constructors

Constructor

new CodecContext(): CodecContext

Defined in: src/lib/codec-context.ts:78

Returns

CodecContext

Overrides

OptionMember<NativeCodecContext>.constructor

Properties

native

protected native: NativeCodecContext

Defined in: src/lib/option.ts:1030

Inherited from

OptionMember.native

Accessors

bitRate

Get Signature

get bitRate(): bigint

Defined in: src/lib/codec-context.ts:149

Average bitrate.

Target bitrate for encoding, detected bitrate for decoding. In bits per second.

Direct mapping to AVCodecContext->bit_rate.

Returns

bigint

Set Signature

set bitRate(value): void

Defined in: src/lib/codec-context.ts:153

Parameters
value

bigint

Returns

void


bitsPerCodedSample

Get Signature

get bitsPerCodedSample(): number

Defined in: src/lib/codec-context.ts:559

Number of bits per coded sample.

Bits per sample/pixel from the demuxer (needed by some codecs). For uncompressed formats, this is the bits per sample.

Direct mapping to AVCodecContext->bits_per_coded_sample.

Returns

number

Set Signature

set bitsPerCodedSample(value): void

Defined in: src/lib/codec-context.ts:563

Parameters
value

number

Returns

void


bitsPerRawSample

Get Signature

get bitsPerRawSample(): number

Defined in: src/lib/codec-context.ts:575

Number of bits per raw sample.

Bits per sample before compression/encoding. Only set when different from bitsPerCodedSample.

Direct mapping to AVCodecContext->bits_per_raw_sample.

Returns

number

Set Signature

set bitsPerRawSample(value): void

Defined in: src/lib/codec-context.ts:579

Parameters
value

number

Returns

void


channelLayout

Get Signature

get channelLayout(): ChannelLayout

Defined in: src/lib/codec-context.ts:601

Audio channel layout.

Describes channel configuration.

Direct mapping to AVCodecContext->ch_layout.

Returns

ChannelLayout

Set Signature

set channelLayout(value): void

Defined in: src/lib/codec-context.ts:605

Parameters
value

ChannelLayout

Returns

void


channels

Get Signature

get channels(): number

Defined in: src/lib/codec-context.ts:515

Number of audio channels.

Direct mapping to AVCodecContext->channels.

Returns

number

Set Signature

set channels(value): void

Defined in: src/lib/codec-context.ts:519

Parameters
value

number

Returns

void


chromaLocation

Get Signature

get chromaLocation(): AVChromaLocation

Defined in: src/lib/codec-context.ts:487

Chroma sample location.

Position of chroma samples.

Direct mapping to AVCodecContext->chroma_sample_location.

Returns

AVChromaLocation

Set Signature

set chromaLocation(value): void

Defined in: src/lib/codec-context.ts:491

Parameters
value

AVChromaLocation

Returns

void


codecId

Get Signature

get codecId(): AVCodecID

Defined in: src/lib/codec-context.ts:100

Codec identifier.

Direct mapping to AVCodecContext->codec_id.

Returns

AVCodecID

Set Signature

set codecId(value): void

Defined in: src/lib/codec-context.ts:104

Parameters
value

AVCodecID

Returns

void


codecTag

Get Signature

get codecTag(): number

Defined in: src/lib/codec-context.ts:115

Codec tag.

Additional codec tag used by some formats.

Direct mapping to AVCodecContext->codec_tag.

Returns

number

Set Signature

set codecTag(value): void

Defined in: src/lib/codec-context.ts:119

Parameters
value

string | number

Returns

void


codecTagString

Get Signature

get codecTagString(): string | null

Defined in: src/lib/codec-context.ts:137

Codec tag as string (FourCC).

Human-readable string representation of the codec tag. Returns the FourCC (Four Character Code) format.

Returns

string | null


codecType

Get Signature

get codecType(): AVMediaType

Defined in: src/lib/codec-context.ts:87

Type of codec (video/audio/subtitle).

Direct mapping to AVCodecContext->codec_type.

Returns

AVMediaType

Set Signature

set codecType(value): void

Defined in: src/lib/codec-context.ts:91

Parameters
value

AVMediaType

Returns

void


colorPrimaries

Get Signature

get colorPrimaries(): AVColorPrimaries

Defined in: src/lib/codec-context.ts:442

Color primaries.

Chromaticity coordinates of source primaries.

Direct mapping to AVCodecContext->color_primaries.

Returns

AVColorPrimaries

Set Signature

set colorPrimaries(value): void

Defined in: src/lib/codec-context.ts:446

Parameters
value

AVColorPrimaries

Returns

void


colorRange

Get Signature

get colorRange(): AVColorRange

Defined in: src/lib/codec-context.ts:427

Color range.

MPEG (limited) or JPEG (full) range.

Direct mapping to AVCodecContext->color_range.

Returns

AVColorRange

Set Signature

set colorRange(value): void

Defined in: src/lib/codec-context.ts:431

Parameters
value

AVColorRange

Returns

void


colorSpace

Get Signature

get colorSpace(): AVColorSpace

Defined in: src/lib/codec-context.ts:472

YUV color space.

Color space for YUV content.

Direct mapping to AVCodecContext->colorspace.

Returns

AVColorSpace

Set Signature

set colorSpace(value): void

Defined in: src/lib/codec-context.ts:476

Parameters
value

AVColorSpace

Returns

void


colorTrc

Get Signature

get colorTrc(): AVColorTransferCharacteristic

Defined in: src/lib/codec-context.ts:457

Color transfer characteristic.

Transfer function (gamma).

Direct mapping to AVCodecContext->color_trc.

Returns

AVColorTransferCharacteristic

Set Signature

set colorTrc(value): void

Defined in: src/lib/codec-context.ts:461

Parameters
value

AVColorTransferCharacteristic

Returns

void


delay

Get Signature

get delay(): number

Defined in: src/lib/codec-context.ts:196

Codec delay.

Number of frames the decoder needs to output before first frame.

Direct mapping to AVCodecContext->delay.

Returns

number


extraData

Get Signature

get extraData(): Buffer<ArrayBufferLike> | null

Defined in: src/lib/codec-context.ts:237

Extra binary data for codec.

Contains codec-specific initialization data.

Direct mapping to AVCodecContext->extradata.

Returns

Buffer<ArrayBufferLike> | null

Set Signature

set extraData(value): void

Defined in: src/lib/codec-context.ts:241

Parameters
value

Buffer<ArrayBufferLike> | null

Returns

void


extraHWFrames

Get Signature

get extraHWFrames(): number

Defined in: src/lib/codec-context.ts:748

Number of extra hardware frames to allocate.

Specifies additional hardware frame buffers for decoders that need them. Useful for hardware decoders requiring frame buffering or reordering.

Direct mapping to AVCodecContext->extra_hw_frames.

Returns

number

Set Signature

set extraHWFrames(value): void

Defined in: src/lib/codec-context.ts:752

Parameters
value

number

Returns

void


flags

Get Signature

get flags(): AVCodecFlag

Defined in: src/lib/codec-context.ts:207

Codec flags.

Combination of AV_CODEC_FLAG_* values.

Direct mapping to AVCodecContext->flags.

Returns

AVCodecFlag

Set Signature

set flags(value): void

Defined in: src/lib/codec-context.ts:211

Parameters
value

AVCodecFlag

Returns

void


flags2

Get Signature

get flags2(): AVCodecFlag2

Defined in: src/lib/codec-context.ts:222

Additional codec flags.

Combination of AV_CODEC_FLAG2_* values.

Direct mapping to AVCodecContext->flags2.

Returns

AVCodecFlag2

Set Signature

set flags2(value): void

Defined in: src/lib/codec-context.ts:226

Parameters
value

AVCodecFlag2

Returns

void


frameNumber

Get Signature

get frameNumber(): number

Defined in: src/lib/codec-context.ts:590

Current frame number.

Frame counter for debugging.

Direct mapping to AVCodecContext->frame_number.

Returns

number


framerate

Get Signature

get framerate(): Rational

Defined in: src/lib/codec-context.ts:411

Frame rate.

Frames per second for encoding.

Direct mapping to AVCodecContext->framerate.

Returns

Rational

Set Signature

set framerate(value): void

Defined in: src/lib/codec-context.ts:416

Parameters
value

Rational

Returns

void


frameSize

Get Signature

get frameSize(): number

Defined in: src/lib/codec-context.ts:543

Number of samples per audio frame.

Direct mapping to AVCodecContext->frame_size.

Returns

number

Set Signature

set frameSize(value): void

Defined in: src/lib/codec-context.ts:547

Parameters
value

number

Returns

void


globalQuality

Get Signature

get globalQuality(): number

Defined in: src/lib/codec-context.ts:654

Global quality for constant quality mode.

Used by encoders that support constant quality mode (e.g., -qscale in FFmpeg CLI). Set this value to enable constant quality encoding instead of constant bitrate. Valid range depends on the codec (e.g., 0-69 for MPEG-4, FF_LAMBDA_SCALE for others).

Direct mapping to AVCodecContext->global_quality.

Example
typescript
// MPEG-4 constant quality (lower = better quality)
codecContext.globalQuality = 5 * FF_QP2LAMBDA;
Returns

number

Set Signature

set globalQuality(value): void

Defined in: src/lib/codec-context.ts:658

Parameters
value

number

Returns

void


gopSize

Get Signature

get gopSize(): number

Defined in: src/lib/codec-context.ts:324

Group of pictures size.

Maximum number of frames between keyframes.

Direct mapping to AVCodecContext->gop_size.

Returns

number

Set Signature

set gopSize(value): void

Defined in: src/lib/codec-context.ts:328

Parameters
value

number

Returns

void


hasBFrames

Get Signature

get hasBFrames(): number

Defined in: src/lib/codec-context.ts:384

Number of frames delay in decoder.

For codecs with B-frames.

Direct mapping to AVCodecContext->has_b_frames.

Returns

number


height

Get Signature

get height(): number

Defined in: src/lib/codec-context.ts:309

Picture height in pixels.

Direct mapping to AVCodecContext->height.

Returns

number

Set Signature

set height(value): void

Defined in: src/lib/codec-context.ts:313

Parameters
value

number

Returns

void


hwDeviceCtx

Get Signature

get hwDeviceCtx(): HardwareDeviceContext | null

Defined in: src/lib/codec-context.ts:714

Hardware device context.

Reference to hardware device for acceleration.

Direct mapping to AVCodecContext->hw_device_ctx.

Returns

HardwareDeviceContext | null

Set Signature

set hwDeviceCtx(value): void

Defined in: src/lib/codec-context.ts:734

Parameters
value

HardwareDeviceContext | null

Returns

void


hwFramesCtx

Get Signature

get hwFramesCtx(): HardwareFramesContext | null

Defined in: src/lib/codec-context.ts:763

Hardware frames context.

Reference to hardware frames for GPU memory.

Direct mapping to AVCodecContext->hw_frames_ctx.

Returns

HardwareFramesContext | null

Set Signature

set hwFramesCtx(value): void

Defined in: src/lib/codec-context.ts:783

Parameters
value

HardwareFramesContext | null

Returns

void


isOpen

Get Signature

get isOpen(): boolean

Defined in: src/lib/codec-context.ts:794

Check if codec is open.

True if the codec has been opened.

Returns

boolean


level

Get Signature

get level(): number

Defined in: src/lib/codec-context.ts:267

Codec level.

Level within the specified profile.

Direct mapping to AVCodecContext->level.

Returns

number

Set Signature

set level(value): void

Defined in: src/lib/codec-context.ts:271

Parameters
value

number

Returns

void


maxBFrames

Get Signature

get maxBFrames(): number

Defined in: src/lib/codec-context.ts:354

Maximum number of B-frames.

B-frames between non-B-frames.

Direct mapping to AVCodecContext->max_b_frames.

Returns

number

Set Signature

set maxBFrames(value): void

Defined in: src/lib/codec-context.ts:358

Parameters
value

number

Returns

void


mbDecision

Get Signature

get mbDecision(): number

Defined in: src/lib/codec-context.ts:369

Macroblock decision mode.

Algorithm for macroblock decision.

Direct mapping to AVCodecContext->mb_decision.

Returns

number

Set Signature

set mbDecision(value): void

Defined in: src/lib/codec-context.ts:373

Parameters
value

number

Returns

void


pixelFormat

Get Signature

get pixelFormat(): AVPixelFormat

Defined in: src/lib/codec-context.ts:339

Pixel format.

Format of the video frames.

Direct mapping to AVCodecContext->pix_fmt.

Returns

AVPixelFormat

Set Signature

set pixelFormat(value): void

Defined in: src/lib/codec-context.ts:343

Parameters
value

AVPixelFormat

Returns

void


pktTimebase

Get Signature

get pktTimebase(): Rational

Defined in: src/lib/codec-context.ts:180

Packet time base.

Time base of the packets from/to the demuxer/muxer.

Direct mapping to AVCodecContext->pkt_timebase.

Returns

Rational

Set Signature

set pktTimebase(value): void

Defined in: src/lib/codec-context.ts:185

Parameters
value

Rational

Returns

void


profile

Get Signature

get profile(): AVProfile

Defined in: src/lib/codec-context.ts:252

Codec profile.

FF_PROFILE_* value indicating codec profile.

Direct mapping to AVCodecContext->profile.

Returns

AVProfile

Set Signature

set profile(value): void

Defined in: src/lib/codec-context.ts:256

Parameters
value

AVProfile

Returns

void


qMax

Get Signature

get qMax(): number

Defined in: src/lib/codec-context.ts:631

Maximum quantizer.

Maximum quantization parameter.

Direct mapping to AVCodecContext->qmax.

Returns

number

Set Signature

set qMax(value): void

Defined in: src/lib/codec-context.ts:635

Parameters
value

number

Returns

void


qMin

Get Signature

get qMin(): number

Defined in: src/lib/codec-context.ts:616

Minimum quantizer.

Minimum quantization parameter.

Direct mapping to AVCodecContext->qmin.

Returns

number

Set Signature

set qMin(value): void

Defined in: src/lib/codec-context.ts:620

Parameters
value

number

Returns

void


rcBufferSize

Get Signature

get rcBufferSize(): number

Defined in: src/lib/codec-context.ts:669

Rate control buffer size.

Decoder bitstream buffer size.

Direct mapping to AVCodecContext->rc_buffer_size.

Returns

number

Set Signature

set rcBufferSize(value): void

Defined in: src/lib/codec-context.ts:673

Parameters
value

number

Returns

void


rcMaxRate

Get Signature

get rcMaxRate(): bigint

Defined in: src/lib/codec-context.ts:684

Maximum bitrate.

Maximum bitrate in bits per second.

Direct mapping to AVCodecContext->rc_max_rate.

Returns

bigint

Set Signature

set rcMaxRate(value): void

Defined in: src/lib/codec-context.ts:688

Parameters
value

bigint

Returns

void


rcMinRate

Get Signature

get rcMinRate(): bigint

Defined in: src/lib/codec-context.ts:699

Minimum bitrate.

Minimum bitrate in bits per second.

Direct mapping to AVCodecContext->rc_min_rate.

Returns

bigint

Set Signature

set rcMinRate(value): void

Defined in: src/lib/codec-context.ts:703

Parameters
value

bigint

Returns

void


sampleAspectRatio

Get Signature

get sampleAspectRatio(): Rational

Defined in: src/lib/codec-context.ts:395

Sample aspect ratio.

Pixel width/height ratio.

Direct mapping to AVCodecContext->sample_aspect_ratio.

Returns

Rational

Set Signature

set sampleAspectRatio(value): void

Defined in: src/lib/codec-context.ts:400

Parameters
value

Rational

Returns

void


sampleFormat

Get Signature

get sampleFormat(): AVSampleFormat

Defined in: src/lib/codec-context.ts:530

Audio sample format.

Format of audio samples.

Direct mapping to AVCodecContext->sample_fmt.

Returns

AVSampleFormat

Set Signature

set sampleFormat(value): void

Defined in: src/lib/codec-context.ts:534

Parameters
value

AVSampleFormat

Returns

void


sampleRate

Get Signature

get sampleRate(): number

Defined in: src/lib/codec-context.ts:502

Audio sample rate.

Samples per second.

Direct mapping to AVCodecContext->sample_rate.

Returns

number

Set Signature

set sampleRate(value): void

Defined in: src/lib/codec-context.ts:506

Parameters
value

number

Returns

void


threadCount

Get Signature

get threadCount(): number

Defined in: src/lib/codec-context.ts:283

Thread count for codec.

Number of threads to use for decoding/encoding. 0 for automatic selection.

Direct mapping to AVCodecContext->thread_count.

Returns

number

Set Signature

set threadCount(value): void

Defined in: src/lib/codec-context.ts:287

Parameters
value

number

Returns

void


timeBase

Get Signature

get timeBase(): Rational

Defined in: src/lib/codec-context.ts:164

Time base for timestamps.

Fundamental unit of time in seconds for this context.

Direct mapping to AVCodecContext->time_base.

Returns

Rational

Set Signature

set timeBase(value): void

Defined in: src/lib/codec-context.ts:169

Parameters
value

Rational

Returns

void


width

Get Signature

get width(): number

Defined in: src/lib/codec-context.ts:296

Picture width in pixels.

Direct mapping to AVCodecContext->width.

Returns

number

Set Signature

set width(value): void

Defined in: src/lib/codec-context.ts:300

Parameters
value

number

Returns

void

Methods

[dispose]()

[dispose](): void

Defined in: src/lib/codec-context.ts:1476

Dispose of the codec context.

Implements the Disposable interface for automatic cleanup. Equivalent to calling freeContext().

Returns

void

Example

typescript
{
  using ctx = new CodecContext();
  ctx.allocContext3(codec);
  await ctx.open2();
  // Use context...
} // Automatically freed when leaving scope

Implementation of

Disposable.[dispose]


allocContext3()

allocContext3(codec): void

Defined in: src/lib/codec-context.ts:819

Allocate codec context.

Allocates and initializes the context for the given codec.

Direct mapping to avcodec_alloc_context3().

Parameters

codec

Codec to use (null for default)

Codec | null

Returns

void

Example

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

const codec = Codec.findDecoder(AV_CODEC_ID_H264);
ctx.allocContext3(codec);

See


clearFlags()

clearFlags(...flags): void

Defined in: src/lib/codec-context.ts:1329

Clear codec flags.

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

Parameters

flags

...AVCodecFlag[]

One or more flag values to clear

Returns

void

Example

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

// Clear specific flag
codecContext.clearFlags(AV_CODEC_FLAG_PSNR);

See


clearFlags2()

clearFlags2(...flags): void

Defined in: src/lib/codec-context.ts:1412

Clear codec flags2.

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

Parameters

flags

...AVCodecFlag2[]

One or more flag2 values to clear

Returns

void

Example

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

// Clear specific flag2
codecContext.clearFlags2(AV_CODEC_FLAG2_FAST);

See


flushBuffers()

flushBuffers(): void

Defined in: src/lib/codec-context.ts:976

Flush codec buffers.

Resets the internal codec state. Used when seeking or switching streams.

Direct mapping to avcodec_flush_buffers().

Returns

void

Example

typescript
// Flush when seeking
ctx.flushBuffers();
// Codec is now ready for new data

freeContext()

freeContext(): void

Defined in: src/lib/codec-context.ts:839

Free the codec context.

Releases all resources. The context becomes invalid.

Direct mapping to avcodec_free_context().

Returns

void

Example

typescript
ctx.freeContext();
// Context is now invalid

See


getNative()

getNative(): NativeCodecContext

Defined in: src/lib/codec-context.ts:1456

Internal

Get the underlying native CodecContext object.

Returns

NativeCodecContext

The native CodecContext binding object

Implementation of

NativeWrapper.getNative


getOption()

Get an option value from this object.

Uses the AVOption API to retrieve options.

Direct mapping to av_opt_get* functions.

Param

Option name

Param

Option type (defaults to AV_OPT_TYPE_STRING)

Param

Search flags (default: AV_OPT_SEARCH_CHILDREN)

Example

typescript
import { AV_OPT_TYPE_STRING, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_PIXEL_FMT, AV_OPT_TYPE_INT64 } from 'node-av/constants';

// String options (default)
const preset = obj.getOption('preset');
const codec = obj.getOption('codec', AV_OPT_TYPE_STRING);

// Typed options
const framerate = obj.getOption('framerate', AV_OPT_TYPE_RATIONAL); // Returns {num, den}
const pixFmt = obj.getOption('pix_fmt', AV_OPT_TYPE_PIXEL_FMT); // Returns AVPixelFormat
const bitrate = obj.getOption('bitrate', AV_OPT_TYPE_INT64); // Returns bigint

Call Signature

getOption(name, type?, searchFlags?): string | null

Defined in: src/lib/option.ts:1259

Parameters
name

string

type?

AVOptionTypeString

searchFlags?

AVOptionSearchFlags

Returns

string | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): string | null

Defined in: src/lib/option.ts:1260

Parameters
name

string

type

AVOptionTypeColor

searchFlags?

AVOptionSearchFlags

Returns

string | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1263

Parameters
name

string

type

AVOptionTypeInt

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): bigint | null

Defined in: src/lib/option.ts:1264

Parameters
name

string

type

AVOptionTypeInt64

searchFlags?

AVOptionSearchFlags

Returns

bigint | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1265

Parameters
name

string

type

AVOptionTypeUint

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): bigint | null

Defined in: src/lib/option.ts:1266

Parameters
name

string

type

AVOptionTypeUint64

searchFlags?

AVOptionSearchFlags

Returns

bigint | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1267

Parameters
name

string

type

AVOptionTypeFlags

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): boolean | null

Defined in: src/lib/option.ts:1268

Parameters
name

string

type

AVOptionTypeBool

searchFlags?

AVOptionSearchFlags

Returns

boolean | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1269

Parameters
name

string

type

AVOptionTypeDuration

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1270

Parameters
name

string

type

AVOptionTypeConst

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1273

Parameters
name

string

type

AVOptionTypeDouble

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): number | null

Defined in: src/lib/option.ts:1274

Parameters
name

string

type

AVOptionTypeFloat

searchFlags?

AVOptionSearchFlags

Returns

number | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): IRational | null

Defined in: src/lib/option.ts:1277

Parameters
name

string

type

AVOptionTypeRational

searchFlags?

AVOptionSearchFlags

Returns

IRational | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): IRational | null

Defined in: src/lib/option.ts:1278

Parameters
name

string

type

AVOptionTypeVideoRate

searchFlags?

AVOptionSearchFlags

Returns

IRational | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): AVPixelFormat | null

Defined in: src/lib/option.ts:1279

Parameters
name

string

type

AVOptionTypePixelFmt

searchFlags?

AVOptionSearchFlags

Returns

AVPixelFormat | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): AVSampleFormat | null

Defined in: src/lib/option.ts:1280

Parameters
name

string

type

AVOptionTypeSampleFmt

searchFlags?

AVOptionSearchFlags

Returns

AVSampleFormat | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): IDimension | null

Defined in: src/lib/option.ts:1281

Parameters
name

string

type

AVOptionTypeImageSize

searchFlags?

AVOptionSearchFlags

Returns

IDimension | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): ChannelLayout | null

Defined in: src/lib/option.ts:1282

Parameters
name

string

type

AVOptionTypeChLayout

searchFlags?

AVOptionSearchFlags

Returns

ChannelLayout | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): Dictionary | null

Defined in: src/lib/option.ts:1283

Parameters
name

string

type

AVOptionTypeDict

searchFlags?

AVOptionSearchFlags

Returns

Dictionary | null

Inherited from

OptionMember.getOption

Call Signature

getOption(name, type, searchFlags?): string | null

Defined in: src/lib/option.ts:1284

Parameters
name

string

type

AVOptionTypeBinary

searchFlags?

AVOptionSearchFlags

Returns

string | null

Inherited from

OptionMember.getOption


hasFlags()

hasFlags(...flags): boolean

Defined in: src/lib/codec-context.ts:1357

Check if codec has specific flags.

Tests whether all specified flags are set using bitwise AND.

Parameters

flags

...AVCodecFlag[]

One or more flag values to check

Returns

boolean

true if all specified flags are set, false otherwise

Example

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

if (codecContext.hasFlags(AV_CODEC_FLAG_QSCALE)) {
  console.log('QSCALE flag is set');
}

See


hasFlags2()

hasFlags2(...flags): boolean

Defined in: src/lib/codec-context.ts:1440

Check if codec has specific flags2.

Tests whether all specified flags2 are set using bitwise AND.

Parameters

flags

...AVCodecFlag2[]

One or more flag2 values to check

Returns

boolean

true if all specified flags2 are set, false otherwise

Example

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

if (codecContext.hasFlags2(AV_CODEC_FLAG2_FAST)) {
  console.log('FAST flag2 is set');
}

See


listOptions()

listOptions(): OptionInfo[]

Defined in: src/lib/option.ts:1400

List all available options for this object.

Uses the AVOption API to enumerate all options. Useful for discovering available settings and their types.

Direct mapping to av_opt_next() iteration.

Returns

OptionInfo[]

Array of option information objects

Example

typescript
const options = obj.listOptions();
for (const opt of options) {
  console.log(`${opt.name}: ${opt.help}`);
  console.log(`  Type: ${opt.type}, Default: ${opt.defaultValue}`);
  console.log(`  Range: ${opt.min} - ${opt.max}`);
}

See

OptionInfo For option metadata structure

Inherited from

OptionMember.listOptions


open2()

open2(codec, options): Promise<number>

Defined in: src/lib/codec-context.ts:871

Open the codec.

Initializes the codec for encoding/decoding. Must be called before processing frames/packets.

Direct mapping to avcodec_open2().

Parameters

codec

Codec to open with (null to use already set)

Codec | null

options

Codec-specific options

Dictionary | null

Returns

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid parameters
  • AVERROR_ENOMEM: Memory allocation failure

Example

typescript
import { FFmpegError } from 'node-av';

const ret = await ctx.open2(codec);
FFmpegError.throwIfError(ret, 'open2');
// Codec is now open and ready

See


open2Sync()

open2Sync(codec, options): number

Defined in: src/lib/codec-context.ts:903

Open the codec synchronously. Synchronous version of open2.

Initializes the codec for encoding/decoding. Must be called before processing frames/packets.

Direct mapping to avcodec_open2().

Parameters

codec

Codec to open with (null to use already set)

Codec | null

options

Codec-specific options

Dictionary | null

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid parameters
  • AVERROR_ENOMEM: Memory allocation failure

Example

typescript
import { FFmpegError } from 'node-av';

const ret = ctx.open2Sync(codec);
FFmpegError.throwIfError(ret, 'open2Sync');
// Codec is now open and ready

See

open2 For async version


parametersFromContext()

parametersFromContext(params): number

Defined in: src/lib/codec-context.ts:957

Fill parameters from codec context.

Copies codec parameters from context to stream. Used when setting up encoders.

Direct mapping to avcodec_parameters_from_context().

Parameters

params

CodecParameters

Destination codec parameters

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid parameters

Example

typescript
import { FFmpegError } from 'node-av';

const ret = ctx.parametersFromContext(stream.codecpar);
FFmpegError.throwIfError(ret, 'parametersFromContext');

See

parametersToContext For the reverse


parametersToContext()

parametersToContext(params): number

Defined in: src/lib/codec-context.ts:930

Fill codec context from parameters.

Copies codec parameters from stream to context. Used when setting up decoders.

Direct mapping to avcodec_parameters_to_context().

Parameters

params

CodecParameters

Source codec parameters

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid parameters

Example

typescript
import { FFmpegError } from 'node-av';

const ret = ctx.parametersToContext(stream.codecpar);
FFmpegError.throwIfError(ret, 'parametersToContext');

See

parametersFromContext For the reverse


receiveFrame()

receiveFrame(frame): Promise<number>

Defined in: src/lib/codec-context.ts:1081

Receive decoded frame.

Gets a decoded frame from the decoder. Call after sendPacket().

Direct mapping to avcodec_receive_frame().

Parameters

frame

Frame

Frame to receive into

Returns

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Need more input
  • AVERROR_EOF: All frames have been output
  • AVERROR_EINVAL: Invalid decoder state

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';

const ret = await ctx.receiveFrame(frame);
if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
  // No frame available
} else {
  FFmpegError.throwIfError(ret, 'receiveFrame');
  // Process decoded frame
}

See

sendPacket To send packets for decoding


receiveFrameSync()

receiveFrameSync(frame): number

Defined in: src/lib/codec-context.ts:1117

Receive decoded frame synchronously. Synchronous version of receiveFrame.

Gets a decoded frame from the decoder. Call after sendPacketSync().

Direct mapping to avcodec_receive_frame().

Parameters

frame

Frame

Frame to receive into

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Need more input
  • AVERROR_EOF: All frames have been output
  • AVERROR_EINVAL: Invalid decoder state

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';

const ret = ctx.receiveFrameSync(frame);
if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
  // No frame available
} else {
  FFmpegError.throwIfError(ret, 'receiveFrameSync');
  // Process frame
}

See

receiveFrame For async version


receivePacket()

receivePacket(packet): Promise<number>

Defined in: src/lib/codec-context.ts:1222

Receive encoded packet.

Gets an encoded packet from the encoder. Call after sendFrame().

Direct mapping to avcodec_receive_packet().

Parameters

packet

Packet

Packet to receive into

Returns

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Need more input
  • AVERROR_EOF: All packets have been output
  • AVERROR_EINVAL: Invalid encoder state

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';

const ret = await ctx.receivePacket(packet);
if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
  // No packet available
} else {
  FFmpegError.throwIfError(ret, 'receivePacket');
  // Process encoded packet
}

See

sendFrame To send frames for encoding


receivePacketSync()

receivePacketSync(packet): number

Defined in: src/lib/codec-context.ts:1258

Receive encoded packet synchronously. Synchronous version of receivePacket.

Gets an encoded packet from the encoder. Call after sendFrameSync().

Direct mapping to avcodec_receive_packet().

Parameters

packet

Packet

Packet to receive into

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Need more input
  • AVERROR_EOF: All packets have been output
  • AVERROR_EINVAL: Invalid encoder state

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';

const ret = ctx.receivePacketSync(packet);
if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
  // No packet available
} else {
  FFmpegError.throwIfError(ret, 'receivePacketSync');
  // Process packet
}

See

receivePacket For async version


sendFrame()

sendFrame(frame): Promise<number>

Defined in: src/lib/codec-context.ts:1152

Send frame to encoder.

Submits raw frame for encoding. Call receivePacket() to get encoded packets.

Direct mapping to avcodec_send_frame().

Parameters

frame

Frame to encode (null to flush)

Frame | null

Returns

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Must receive packets first
  • AVERROR_EOF: Encoder has been flushed
  • AVERROR_EINVAL: Invalid encoder state
  • AVERROR_ENOMEM: Memory allocation failure

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN } from 'node-av';

const ret = await ctx.sendFrame(frame);
if (ret === AVERROR_EAGAIN) {
  // Need to receive packets first
} else {
  FFmpegError.throwIfError(ret, 'sendFrame');
}

See

receivePacket To get encoded packets


sendFrameSync()

sendFrameSync(frame): number

Defined in: src/lib/codec-context.ts:1187

Send frame to encoder synchronously. Synchronous version of sendFrame.

Submits raw frame for encoding. Call receivePacketSync() to get encoded packets.

Direct mapping to avcodec_send_frame().

Parameters

frame

Frame to encode (null to flush)

Frame | null

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Must receive packets first
  • AVERROR_EOF: Encoder has been flushed
  • AVERROR_EINVAL: Invalid encoder state
  • AVERROR_ENOMEM: Memory allocation failure

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN } from 'node-av';

const ret = ctx.sendFrameSync(frame);
if (ret === AVERROR_EAGAIN) {
  // Need to receive packets first
  ctx.receivePacketSync(packet);
}

See

sendFrame For async version


sendPacket()

sendPacket(packet): Promise<number>

Defined in: src/lib/codec-context.ts:1011

Send packet to decoder.

Submits encoded data for decoding. Call receiveFrame() to get decoded frames.

Direct mapping to avcodec_send_packet().

Parameters

packet

Packet to decode (null to flush)

Packet | null

Returns

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Must receive frames first
  • AVERROR_EOF: Decoder has been flushed
  • AVERROR_EINVAL: Invalid decoder state
  • AVERROR_ENOMEM: Memory allocation failure

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN } from 'node-av';

const ret = await ctx.sendPacket(packet);
if (ret === AVERROR_EAGAIN) {
  // Need to receive frames first
} else {
  FFmpegError.throwIfError(ret, 'sendPacket');
}

See

receiveFrame To get decoded frames


sendPacketSync()

sendPacketSync(packet): number

Defined in: src/lib/codec-context.ts:1046

Send packet to decoder synchronously. Synchronous version of sendPacket.

Submits compressed data for decoding. Call receiveFrameSync() to get decoded frames.

Direct mapping to avcodec_send_packet().

Parameters

packet

Packet to decode (null to flush)

Packet | null

Returns

number

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Must receive frames first
  • AVERROR_EOF: Decoder has been flushed
  • AVERROR_EINVAL: Invalid decoder state
  • AVERROR_ENOMEM: Memory allocation failure

Example

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN } from 'node-av';

const ret = ctx.sendPacketSync(packet);
if (ret === AVERROR_EAGAIN) {
  // Need to receive frames first
  ctx.receiveFrameSync(frame);
}

See

sendPacket For async version


setFlags()

setFlags(...flags): void

Defined in: src/lib/codec-context.ts:1303

Set codec flags.

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

Parameters

flags

...AVCodecFlag[]

One or more flag values to set

Returns

void

Example

typescript
import { AV_CODEC_FLAG_QSCALE, AV_CODEC_FLAG_PSNR } from 'node-av/constants';

// Set multiple flags at once
codecContext.setFlags(AV_CODEC_FLAG_QSCALE, AV_CODEC_FLAG_PSNR);

See


setFlags2()

setFlags2(...flags): void

Defined in: src/lib/codec-context.ts:1386

Set codec flags2.

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

Parameters

flags

...AVCodecFlag2[]

One or more flag2 values to set

Returns

void

Example

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

// Set multiple flags2 at once
codecContext.setFlags2(AV_CODEC_FLAG2_FAST);

See


setHardwarePixelFormat()

setHardwarePixelFormat(hwFormat, swFormat?): void

Defined in: src/lib/codec-context.ts:1279

Set hardware pixel format.

Configures hardware acceleration pixel formats. Used in get_format callback for hardware decoding.

Parameters

hwFormat

AVPixelFormat

Hardware pixel format

swFormat?

AVPixelFormat

Software pixel format (optional)

Returns

void

Example

typescript
import { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12 } from 'node-av/constants';

ctx.setHardwarePixelFormat(AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12);

setOption()

Set an option on this object.

Uses the AVOption API to set options. Available options depend on the specific object type.

Direct mapping to av_opt_set* functions.

Param

Option name

Param

Option value

Param

Option type (defaults to AV_OPT_TYPE_STRING)

Param

Search flags (default: AV_OPT_SEARCH_CHILDREN)

Example

typescript
import { FFmpegError } from 'node-av';
import { AV_OPT_TYPE_STRING, AV_OPT_TYPE_INT64, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_PIXEL_FMT } from 'node-av/constants';

// String options (default)
let ret = obj.setOption('preset', 'fast');
FFmpegError.throwIfError(ret, 'set preset');

ret = obj.setOption('codec', 'h264', AV_OPT_TYPE_STRING);
FFmpegError.throwIfError(ret, 'set codec');

// Integer options
ret = obj.setOption('bitrate', 2000000, AV_OPT_TYPE_INT64);
FFmpegError.throwIfError(ret, 'set bitrate');

ret = obj.setOption('threads', 4, AV_OPT_TYPE_INT);
FFmpegError.throwIfError(ret, 'set threads');

// Complex types with proper types
ret = obj.setOption('framerate', {num: 30, den: 1}, AV_OPT_TYPE_RATIONAL);
FFmpegError.throwIfError(ret, 'set framerate');

ret = obj.setOption('pix_fmt', AV_PIX_FMT_YUV420P, AV_OPT_TYPE_PIXEL_FMT);
FFmpegError.throwIfError(ret, 'set pixel format');

Call Signature

setOption(name, value): number

Defined in: src/lib/option.ts:1037

Parameters
name

string

value

string | number | bigint | boolean | null | undefined

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1038

Parameters
name

string

value

string

type

AVOptionTypeString

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1039

Parameters
name

string

value

string

type

AVOptionTypeColor

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1042

Parameters
name

string

value

number

type

AVOptionTypeInt

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1043

Parameters
name

string

value

bigint

type

AVOptionTypeInt64

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1044

Parameters
name

string

value

number

type

AVOptionTypeUint

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1045

Parameters
name

string

value

bigint

type

AVOptionTypeUint64

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1046

Parameters
name

string

value

number

type

AVOptionTypeFlags

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1047

Parameters
name

string

value

boolean

type

AVOptionTypeBool

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1048

Parameters
name

string

value

number

type

AVOptionTypeDuration

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1049

Parameters
name

string

value

number

type

AVOptionTypeConst

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1052

Parameters
name

string

value

number

type

AVOptionTypeDouble

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1053

Parameters
name

string

value

number

type

AVOptionTypeFloat

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1056

Parameters
name

string

value

IRational

type

AVOptionTypeRational

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1057

Parameters
name

string

value

IRational

type

AVOptionTypeVideoRate

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1058

Parameters
name

string

value

AVPixelFormat

type

AVOptionTypePixelFmt

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1059

Parameters
name

string

value

AVSampleFormat

type

AVOptionTypeSampleFmt

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1060

Parameters
name

string

value

IDimension

type

AVOptionTypeImageSize

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1061

Parameters
name

string

value

number | bigint

type

AVOptionTypeChLayout

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1062

Parameters
name

string

value

Buffer

type

AVOptionTypeBinary

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1063

Parameters
name

string

value

number[]

type

AVOptionTypeBinaryIntArray

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption

Call Signature

setOption(name, value, type, searchFlags?): number

Defined in: src/lib/option.ts:1064

Parameters
name

string

value

Dictionary

type

AVOptionTypeDict

searchFlags?

AVOptionSearchFlags

Returns

number

Inherited from

OptionMember.setOption