Skip to content

node-av / lib / FilterContext

Class: FilterContext ​

Defined in: src/lib/filter-context.ts:51

Filter instance in a filter graph.

Represents an instantiated filter within a filter graph. Each context contains a specific filter configuration with its parameters, connections to other filters, and input/output pads. Supports both software and hardware filtering operations. Essential for building complex filter chains for audio/video processing.

A filter context belongs to its filter graph. Once that graph is freed, the context reads its defaults (e.g. name null), ignores writes and its frame operations fail.

Direct mapping to FFmpeg's AVFilterContext.

Example ​

typescript
import { FilterContext, FilterGraph, Filter, FFmpegError } from 'node-av';

// Create filter context in a graph
const graph = new FilterGraph();
const filter = Filter.getByName('scale');
const context = graph.createFilter(filter, 'scaler');

// Initialize with parameters
const ret = context.initStr('640:480');
FFmpegError.throwIfError(ret, 'initStr');

// Link filters together
const ret2 = source.link(0, context, 0);
FFmpegError.throwIfError(ret2, 'link');

// For buffer source/sink
const ret3 = await bufferSrc.buffersrcAddFrame(frame);
FFmpegError.throwIfError(ret3, 'buffersrcAddFrame');

See ​

Extends ​

Implements ​

Constructors ​

Constructor ​

new FilterContext(native): FilterContext

Defined in: src/lib/filter-context.ts:57

Internal

Parameters ​

native ​

NativeFilterContext

The native filter context instance

Returns ​

FilterContext

Overrides ​

OptionMember<NativeFilterContext>.constructor

Properties ​

native ​

protected native: NativeFilterContext

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

Inherited from ​

OptionMember.native

Accessors ​

extraHWFrames ​

Get Signature ​

get extraHWFrames(): number

Defined in: src/lib/filter-context.ts:155

Number of extra hardware frames to allocate.

Specifies additional hardware frame buffers for filters that need them. Useful for deinterlacing or other filters requiring frame buffering.

Direct mapping to AVFilterContext->extra_hw_frames.

Returns ​

number

Set Signature ​

set extraHWFrames(value): void

Defined in: src/lib/filter-context.ts:159

Parameters ​
value ​

number

Returns ​

void


filter ​

Get Signature ​

get filter(): Filter | null

Defined in: src/lib/filter-context.ts:84

Filter descriptor.

Reference to the filter type this context instantiates.

Direct mapping to AVFilterContext->filter.

Returns ​

Filter | null


graph ​

Get Signature ​

get graph(): NativeFilterGraph | null

Defined in: src/lib/filter-context.ts:96

Parent filter graph.

Reference to the graph containing this filter context.

Direct mapping to AVFilterContext->graph.

Returns ​

NativeFilterGraph | null


hwDeviceCtx ​

Get Signature ​

get hwDeviceCtx(): HardwareDeviceContext | null

Defined in: src/lib/filter-context.ts:130

Hardware device context.

Hardware acceleration context for GPU-based filtering. Set to enable hardware-accelerated filter operations.

Direct mapping to AVFilterContext->hw_device_ctx.

Returns ​

HardwareDeviceContext | null

Set Signature ​

set hwDeviceCtx(value): void

Defined in: src/lib/filter-context.ts:143

Parameters ​
value ​

HardwareDeviceContext | null

Returns ​

void


name ​

Get Signature ​

get name(): string | null

Defined in: src/lib/filter-context.ts:69

Filter instance name.

User-assigned name for this filter instance in the graph. Used for identification and debugging.

Direct mapping to AVFilterContext->name.

Returns ​

string | null

Set Signature ​

set name(value): void

Defined in: src/lib/filter-context.ts:73

Parameters ​
value ​

string | null

Returns ​

void


nbInputs ​

Get Signature ​

get nbInputs(): number

Defined in: src/lib/filter-context.ts:107

Number of input pads.

Total number of input connections this filter can accept.

Direct mapping to AVFilterContext->nb_inputs.

Returns ​

number


nbOutputs ​

Get Signature ​

get nbOutputs(): number

Defined in: src/lib/filter-context.ts:118

Number of output pads.

Total number of output connections this filter can provide.

Direct mapping to AVFilterContext->nb_outputs.

Returns ​

number

Methods ​

[dispose]() ​

[dispose](): void

Defined in: src/lib/filter-context.ts:834

Dispose of the filter context.

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

Returns ​

void

Example ​

typescript
{
  using context = graph.createFilter(filter, 'test');
  context.initStr('640:480');
  // Use context...
} // Automatically freed when leaving scope

Implementation of ​

Disposable.[dispose]


buffersinkGetChannelLayout() ​

buffersinkGetChannelLayout(): ChannelLayout

Defined in: src/lib/filter-context.ts:704

Get channel layout from buffer sink.

Returns the channel layout of audio from a buffer sink filter. Only valid for audio buffer sink filters.

Direct mapping to av_buffersink_get_channel_layout().

Returns ​

ChannelLayout

Channel layout configuration

Example ​

typescript
const layout = bufferSink.buffersinkGetChannelLayout();
console.log(`Channels: ${layout.nbChannels}`);

buffersinkGetColorRange() ​

buffersinkGetColorRange(): AVColorRange

Defined in: src/lib/filter-context.ts:744

Get color range from buffer sink.

Returns the color range of video from a buffer sink filter. Only valid for video buffer sink filters.

Direct mapping to av_buffersink_get_color_range().

Returns ​

AVColorRange

Color range

Example ​

typescript
const colorRange = bufferSink.buffersinkGetColorRange();
console.log(`Color range: ${colorRange}`);

buffersinkGetColorspace() ​

buffersinkGetColorspace(): AVColorSpace

Defined in: src/lib/filter-context.ts:724

Get color space from buffer sink.

Returns the color space of video from a buffer sink filter. Only valid for video buffer sink filters.

Direct mapping to av_buffersink_get_colorspace().

Returns ​

AVColorSpace

Color space

Example ​

typescript
const colorSpace = bufferSink.buffersinkGetColorspace();
console.log(`Color space: ${colorSpace}`);

buffersinkGetFormat() ​

buffersinkGetFormat(): AVPixelFormat | AVSampleFormat

Defined in: src/lib/filter-context.ts:582

Get pixel/sample format from buffer sink.

Returns the format of frames from a buffer sink filter. Only valid for buffer sink filters.

Direct mapping to av_buffersink_get_format().

Returns ​

AVPixelFormat | AVSampleFormat

Pixel format for video, sample format for audio

Example ​

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

const format = bufferSink.buffersinkGetFormat();
if (format === AV_PIX_FMT_YUV420P) {
  console.log('Output is YUV420P');
}

buffersinkGetFrame() ​

buffersinkGetFrame(frame): Promise<number>

Defined in: src/lib/filter-context.ts:493

Get a frame from a buffer sink filter.

Retrieves a filtered frame from the filter graph through a buffer sink. Only valid for buffer sink filters.

Direct mapping to av_buffersink_get_frame().

Parameters ​

frame ​

Frame

Frame to receive filtered data

Returns ​

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: No frame available yet
  • AVERROR_EOF: No more frames will be produced
  • AVERROR_EINVAL: Not a buffer sink filter

Example ​

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

const frame = new Frame();
frame.alloc();

const ret = await bufferSink.buffersinkGetFrame(frame);
if (ret === AVERROR_EAGAIN) {
  // No frame available yet
} else if (ret === AVERROR_EOF) {
  // End of stream
} else {
  FFmpegError.throwIfError(ret, 'buffersinkGetFrame');
  // Process filtered frame
}

See ​

buffersrcAddFrame To send frames for filtering


buffersinkGetFrameRate() ​

buffersinkGetFrameRate(): Rational

Defined in: src/lib/filter-context.ts:663

Get frame rate from buffer sink.

Returns the frame rate of video from a buffer sink filter. Only valid for video buffer sink filters.

Direct mapping to av_buffersink_get_frame_rate().

Returns ​

Rational

Frame rate as Rational

Example ​

typescript
const frameRate = bufferSink.buffersinkGetFrameRate();
console.log(`Frame rate: ${frameRate.num}/${frameRate.den} fps`);

buffersinkGetFrameSync() ​

buffersinkGetFrameSync(frame): number

Defined in: src/lib/filter-context.ts:537

Get frame from buffer sink filter synchronously. Synchronous version of buffersinkGetFrame.

Retrieves a filtered frame from a buffer sink filter. Only valid for buffer sink filters (buffersink, abuffersink).

Direct mapping to av_buffersink_get_frame().

Parameters ​

frame ​

Frame

Frame to receive filtered data

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Need more input
  • AVERROR_EOF: No more frames available
  • AVERROR_EINVAL: Invalid parameters

Example ​

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

// Get filtered frame
const filtered = new Frame();
const ret = bufferSink.buffersinkGetFrameSync(filtered);

if (ret === 0) {
  // Process filtered frame
  console.log(`Got filtered frame with ${filtered.nbSamples} samples`);
  filtered.unref();
} else if (ret === AVERROR_EAGAIN) {
  // Need more input frames
} else if (ret === AVERROR_EOF) {
  // No more frames
} else {
  FFmpegError.throwIfError(ret, 'buffersinkGetFrameSync');
}

See ​

buffersinkGetFrame For async version


buffersinkGetHeight() ​

buffersinkGetHeight(): number

Defined in: src/lib/filter-context.ts:622

Get frame height from buffer sink.

Returns the height of video frames from a buffer sink filter. Only valid for video buffer sink filters.

Direct mapping to av_buffersink_get_h().

Returns ​

number

Frame height in pixels

Example ​

typescript
const height = bufferSink.buffersinkGetHeight();
console.log(`Output height: ${height}px`);

buffersinkGetSampleAspectRatio() ​

buffersinkGetSampleAspectRatio(): Rational

Defined in: src/lib/filter-context.ts:642

Get sample aspect ratio from buffer sink.

Returns the pixel aspect ratio of video frames from a buffer sink filter. Only valid for video buffer sink filters.

Direct mapping to av_buffersink_get_sample_aspect_ratio().

Returns ​

Rational

Sample aspect ratio as Rational

Example ​

typescript
const sar = bufferSink.buffersinkGetSampleAspectRatio();
console.log(`SAR: ${sar.num}:${sar.den}`);

buffersinkGetSampleRate() ​

buffersinkGetSampleRate(): number

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

Get sample rate from buffer sink.

Returns the sample rate of audio from a buffer sink filter. Only valid for audio buffer sink filters.

Direct mapping to av_buffersink_get_sample_rate().

Returns ​

number

Sample rate in Hz

Example ​

typescript
const sampleRate = bufferSink.buffersinkGetSampleRate();
console.log(`Sample rate: ${sampleRate} Hz`);

buffersinkGetTimeBase() ​

buffersinkGetTimeBase(): Rational

Defined in: src/lib/filter-context.ts:557

Get time base from buffer sink.

Returns the time base of frames from a buffer sink filter. Only valid for buffer sink filters.

Direct mapping to av_buffersink_get_time_base().

Returns ​

Rational

Time base as Rational

Example ​

typescript
const timeBase = bufferSink.buffersinkGetTimeBase();
console.log(`Time base: ${timeBase.num}/${timeBase.den}`);

buffersinkGetWidth() ​

buffersinkGetWidth(): number

Defined in: src/lib/filter-context.ts:602

Get frame width from buffer sink.

Returns the width of video frames from a buffer sink filter. Only valid for video buffer sink filters.

Direct mapping to av_buffersink_get_w().

Returns ​

number

Frame width in pixels

Example ​

typescript
const width = bufferSink.buffersinkGetWidth();
console.log(`Output width: ${width}px`);

buffersrcAddFrame() ​

buffersrcAddFrame(frame, flags?): Promise<number>

Defined in: src/lib/filter-context.ts:321

Add a frame to a buffer source filter.

Sends a frame into the filter graph through a buffer source. Only valid for buffer source filters. Send null to signal EOF.

Direct mapping to av_buffersrc_add_frame_flags().

Parameters ​

frame ​

Frame | null

Frame to send, or null for EOF

flags? ​

AVBufferSrcFlag

Optional buffersrc flags (defaults to AV_BUFFERSRC_FLAG_NONE = 0)

Returns ​

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Filter needs more output consumption
  • AVERROR_EOF: Filter has been closed
  • AVERROR_EINVAL: Not a buffer source filter
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN, AV_BUFFERSRC_FLAG_PUSH } from 'node-av/constants';

// Send frame to filter graph with PUSH flag (immediate processing)
const ret = await bufferSrc.buffersrcAddFrame(frame, AV_BUFFERSRC_FLAG_PUSH);
if (ret === AVERROR_EAGAIN) {
  // Need to consume output first
} else {
  FFmpegError.throwIfError(ret, 'buffersrcAddFrame');
}

// Signal EOF
await bufferSrc.buffersrcAddFrame(null);

See ​

buffersinkGetFrame To retrieve filtered frames


buffersrcAddFrameSync() ​

buffersrcAddFrameSync(frame, flags?): number

Defined in: src/lib/filter-context.ts:365

Add frame to buffer source filter synchronously. Synchronous version of buffersrcAddFrame.

Sends a frame to a buffer source filter for processing. Only valid for buffer source filters (buffer, abuffer).

Direct mapping to av_buffersrc_add_frame_flags().

Parameters ​

frame ​

Frame | null

Frame to send (null to mark EOF)

flags? ​

AVBufferSrcFlag

Optional buffersrc flags (defaults to AV_BUFFERSRC_FLAG_NONE = 0)

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EAGAIN: Need to retrieve output first
  • AVERROR_EOF: Graph has finished processing
  • AVERROR_EINVAL: Invalid parameters
  • AVERROR(ENOMEM): Memory allocation failure

Example ​

typescript
import { FFmpegError } from 'node-av';
import { AVERROR_EAGAIN, AV_BUFFERSRC_FLAG_PUSH } from 'node-av/constants';

// Send frame to filter with PUSH flag (immediate processing)
const ret = bufferSrc.buffersrcAddFrameSync(frame, AV_BUFFERSRC_FLAG_PUSH);
if (ret === AVERROR_EAGAIN) {
  // Need to get output frames first
  const filtered = new Frame();
  bufferSink.buffersinkGetFrameSync(filtered);
} else {
  FFmpegError.throwIfError(ret, 'buffersrcAddFrameSync');
}

// Mark end of stream
bufferSrc.buffersrcAddFrameSync(null);

See ​

buffersrcAddFrame For async version


buffersrcParametersSet() ​

buffersrcParametersSet(params): number

Defined in: src/lib/filter-context.ts:436

Set parameters for a buffer source filter.

Configures the format and properties of frames that will be sent to the buffer source. Must be called before sending frames.

Direct mapping to av_buffersrc_parameters_set().

Parameters ​

params ​

Source parameters

alphaMode? ​

number

Alpha channel mode

channelLayout? ​

bigint

Audio channel layout

colorRange? ​

AVColorRange

Color range for video

colorSpace? ​

AVColorSpace

Color space for video

format? ​

AVPixelFormat | AVSampleFormat

Pixel or sample format

frameRate? ​

IRational

Video frame rate

height? ​

number

Video frame height

hwFramesCtx? ​

HardwareFramesContext | null

Hardware frames context

sampleAspectRatio? ​

IRational

Pixel aspect ratio

sampleRate? ​

number

Audio sample rate

timeBase? ​

IRational

Time base for timestamps

width? ​

number

Video frame width

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid parameters
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

typescript
import { FFmpegError, Rational } from 'node-av';
import { AV_PIX_FMT_YUV420P } from 'node-av/constants';

// Configure video buffer source
const ret = bufferSrc.buffersrcParametersSet({
  width: 1920,
  height: 1080,
  format: AV_PIX_FMT_YUV420P,
  timeBase: { num: 1, den: 25 },
  frameRate: { num: 25, den: 1 }
});
FFmpegError.throwIfError(ret, 'buffersrcParametersSet');

@example
```typescript
import { FFmpegError } from 'node-av';
import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';

// Configure audio buffer source
const ret = bufferSrc.buffersrcParametersSet({
  format: AV_SAMPLE_FMT_FLTP,
  sampleRate: 44100,
  channelLayout: AV_CHANNEL_LAYOUT_STEREO
});
FFmpegError.throwIfError(ret, 'buffersrcParametersSet');

free() ​

free(): void

Defined in: src/lib/filter-context.ts:764

Free the filter context.

Releases all resources associated with the filter context. The context becomes invalid after calling this.

Direct mapping to avfilter_free().

Returns ​

void

Example ​

typescript
context.free();
// Context is now invalid

See ​

Symbol.dispose For automatic cleanup


getNative() ​

getNative(): NativeFilterContext

Defined in: src/lib/filter-context.ts:815

Internal

Get the underlying native FilterContext object.

Returns ​

NativeFilterContext

The native FilterContext 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 ​

name

Option name

Param ​

type

Option type (defaults to AV_OPT_TYPE_STRING)

Param ​

searchFlags

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Parameters ​
name ​

string

type ​

AVOptionTypeBinary

searchFlags? ​

AVOptionSearchFlags

Returns ​

string | null

Inherited from ​

OptionMember.getOption


init() ​

init(options?): number

Defined in: src/lib/filter-context.ts:188

Initialize filter with dictionary options.

Configures the filter with key-value option pairs. Must be called after creation and before processing.

Direct mapping to avfilter_init_dict().

Parameters ​

options? ​

NativeDictionary | null = null

Dictionary of filter options

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 options = { width: '1920', height: '1080' };
const ret = context.init(options);
FFmpegError.throwIfError(ret, 'init');

See ​

initStr For string-based initialization


initStr() ​

initStr(args?): number

Defined in: src/lib/filter-context.ts:221

Initialize filter with string arguments.

Configures the filter using a string representation of parameters. Format depends on the specific filter.

Direct mapping to avfilter_init_str().

Parameters ​

args? ​

string | null = null

Filter arguments string

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid arguments
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

// Scale filter with width:height
const ret = scaleContext.initStr('1920:1080');
FFmpegError.throwIfError(ret, 'initStr');

// Crop filter with width:height:x:y
const ret2 = cropContext.initStr('640:480:100:50');
FFmpegError.throwIfError(ret2, 'initStr');

See ​

init For dictionary-based initialization


isSink() ​

isSink(): boolean

Defined in: src/lib/filter-context.ts:804

Check if filter is a sink.

Sink filters consume frames without output.

Returns ​

boolean

True if filter has no outputs

Example ​

typescript
if (context.isSink()) {
  console.log('This is a sink filter');
}

See ​

isSource To check for source filters


isSource() ​

isSource(): boolean

Defined in: src/lib/filter-context.ts:784

Check if filter is a source.

Source filters generate frames without input.

Returns ​

boolean

True if filter has no inputs

Example ​

typescript
if (context.isSource()) {
  console.log('This is a source filter');
}

See ​

isSink To check for sink filters


link(srcPad, dst, dstPad): number

Defined in: src/lib/filter-context.ts:258

Link this filter's output to another filter's input.

Creates a connection between two filters in the graph. Data flows from this filter's output pad to the destination's input pad.

Direct mapping to avfilter_link().

Parameters ​

srcPad ​

number

Output pad index of this filter

dst ​

FilterContext

Destination filter context

dstPad ​

number

Input pad index of destination filter

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid pad indices or incompatible formats
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

// Link source output 0 to scale input 0
const ret = source.link(0, scale, 0);
FFmpegError.throwIfError(ret, 'link');

// Link scale output 0 to sink input 0
const ret2 = scale.link(0, sink, 0);
FFmpegError.throwIfError(ret2, 'link');

See ​

unlink To disconnect filters


listOptions() ​

listOptions(): OptionInfo[]

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

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


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 ​

name

Option name

Param ​

value

Option value

Param ​

type

Option type; when omitted, the option's declared type is looked up via av_opt_find and the value converted accordingly

Param ​

searchFlags

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';

// Untyped - the option's declared type is inferred
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:1066

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Parameters ​
name ​

string

value ​

Dictionary

type ​

AVOptionTypeDict

searchFlags? ​

AVOptionSearchFlags

Returns ​

number

Inherited from ​

OptionMember.setOption


unlink(pad): void

Defined in: src/lib/filter-context.ts:280

Unlink a filter pad.

Disconnects a pad from its linked filter. Used to reconfigure filter connections.

Direct mapping to avfilter_link_free().

Parameters ​

pad ​

number

Pad index to unlink

Returns ​

void

Example ​

typescript
// Disconnect output pad 0
context.unlink(0);

See ​

link To connect filters