Skip to content

node-av / lib / FilterGraph

Class: FilterGraph ​

Defined in: src/lib/filter-graph.ts:65

Filter graph for audio/video processing pipelines.

Manages a collection of interconnected filters forming a processing pipeline. Filters are connected through their input/output pads to create complex audio/video transformations. Supports both simple linear chains and complex graphs with multiple inputs/outputs. Essential for effects, format conversions, scaling, and other media processing operations.

Direct mapping to FFmpeg's AVFilterGraph.

Example ​

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

// Create and configure filter graph
const graph = new FilterGraph();
graph.alloc();

// Create filters
const bufferSrc = graph.createFilter(
  Filter.getByName('buffer')!,
  'src',
  'video_size=1920x1080:pix_fmt=yuv420p'
);

const scale = graph.createFilter(
  Filter.getByName('scale')!,
  'scale',
  '640:480'
);

const bufferSink = graph.createFilter(
  Filter.getByName('buffersink')!,
  'sink'
);

// Link filters
bufferSrc.link(0, scale, 0);
scale.link(0, bufferSink, 0);

// Configure graph
const ret = await graph.config();
FFmpegError.throwIfError(ret, 'config');

// Parse filter string
const ret2 = graph.parse2('[in]scale=640:480[out]');
FFmpegError.throwIfError(ret2, 'parse2');

See ​

Extends ​

Implements ​

Constructors ​

Constructor ​

new FilterGraph(): FilterGraph

Defined in: src/lib/filter-graph.ts:66

Returns ​

FilterGraph

Overrides ​

OptionMember<NativeFilterGraph>.constructor

Properties ​

native ​

protected native: NativeFilterGraph

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

Inherited from ​

OptionMember.native

Accessors ​

aresampleSwrOpts ​

Get Signature ​

get aresampleSwrOpts(): string | null

Defined in: src/lib/filter-graph.ts:148

Swresample options for aresample filter.

Options string passed to swresample for audio resampling operations.

Direct mapping to AVFilterGraph->aresample_swr_opts.

Returns ​

string | null

Set Signature ​

set aresampleSwrOpts(value): void

Defined in: src/lib/filter-graph.ts:152

Parameters ​
value ​

string | null

Returns ​

void


filters ​

Get Signature ​

get filters(): FilterContext[] | null

Defined in: src/lib/filter-graph.ts:88

Array of filters in the graph.

All filter contexts currently in the graph.

Direct mapping to AVFilterGraph->filters.

Returns ​

FilterContext[] | null


nbFilters ​

Get Signature ​

get nbFilters(): number

Defined in: src/lib/filter-graph.ts:77

Number of filters in the graph.

Total count of filter contexts in this graph.

Direct mapping to AVFilterGraph->nb_filters.

Returns ​

number


nbThreads ​

Get Signature ​

get nbThreads(): number

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

Number of threads for parallel processing.

Number of threads used for filter execution. 0 means automatic detection.

Direct mapping to AVFilterGraph->nb_threads.

Returns ​

number

Set Signature ​

set nbThreads(value): void

Defined in: src/lib/filter-graph.ts:122

Parameters ​
value ​

number

Returns ​

void


scaleSwsOpts ​

Get Signature ​

get scaleSwsOpts(): string | null

Defined in: src/lib/filter-graph.ts:133

Swscale options for scale filter.

Options string passed to swscale for scaling operations.

Direct mapping to AVFilterGraph->scale_sws_opts.

Returns ​

string | null

Set Signature ​

set scaleSwsOpts(value): void

Defined in: src/lib/filter-graph.ts:137

Parameters ​
value ​

string | null

Returns ​

void


threadType ​

Get Signature ​

get threadType(): AVFilterConstants

Defined in: src/lib/filter-graph.ts:102

Threading type for graph execution.

Controls how filters are executed in parallel. Use AVFILTER_THREAD_SLICE for slice-based threading.

Direct mapping to AVFilterGraph->thread_type.

Returns ​

AVFilterConstants

Set Signature ​

set threadType(value): void

Defined in: src/lib/filter-graph.ts:106

Parameters ​
value ​

AVFilterConstants

Returns ​

void

Methods ​

[dispose]() ​

[dispose](): void

Defined in: src/lib/filter-graph.ts:734

Dispose of the filter graph.

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

Returns ​

void

Example ​

typescript
{
  using graph = new FilterGraph();
  graph.alloc();
  // Build and use graph...
} // Automatically freed when leaving scope

Implementation of ​

Disposable.[dispose]


alloc() ​

alloc(): void

Defined in: src/lib/filter-graph.ts:176

Allocate a filter graph.

Allocates memory for the filter graph structure. Must be called before using the graph.

Direct mapping to avfilter_graph_alloc().

Returns ​

void

Throws ​

If allocation fails (ENOMEM)

Example ​

typescript
const graph = new FilterGraph();
graph.alloc();
// Graph is now ready for filter creation

See ​

  • free To deallocate
  • config To configure after building

allocFilter() ​

allocFilter(filter, name): FilterContext | null

Defined in: src/lib/filter-graph.ts:273

Allocate a filter in the graph.

Creates a new filter context and adds it to the graph, but does not initialize it. Call init() on the context afterwards.

Direct mapping to avfilter_graph_alloc_filter().

Parameters ​

filter ​

Filter

Filter descriptor to instantiate

name ​

string

Name for this filter instance

Returns ​

FilterContext | null

Allocated filter context, or null on failure

Example ​

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

const filter = graph.allocFilter(
  Filter.getByName('scale')!,
  'scaler'
);
if (filter) {
  // Initialize separately
  const ret = filter.initStr('640:480');
  FFmpegError.throwIfError(ret, 'initStr');
}

See ​

createFilter To allocate and initialize


config() ​

config(): Promise<number>

Defined in: src/lib/filter-graph.ts:332

Configure the filter graph.

Validates and finalizes the graph configuration. Must be called after all filters are created and linked.

Direct mapping to avfilter_graph_config().

Returns ​

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid graph configuration
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

// Build graph...
// Link filters...

// Configure the complete graph
const ret = await graph.config();
FFmpegError.throwIfError(ret, 'config');
// Graph is now ready for processing

See ​

validate To check configuration


configSync() ​

configSync(): number

Defined in: src/lib/filter-graph.ts:361

Configure the filter graph synchronously. Synchronous version of config.

Validates and finalizes the graph structure after all filters have been added and connected. Must be called before processing.

Direct mapping to avfilter_graph_config().

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid graph structure
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

// Configure graph after building
const ret = graph.configSync();
FFmpegError.throwIfError(ret, 'configSync');
// Graph is now ready for processing

See ​

config For async version


createFilter() ​

createFilter(filter, name, args?): FilterContext | null

Defined in: src/lib/filter-graph.ts:237

Create and initialize a filter in the graph.

Creates a new filter context, adds it to the graph, and initializes it with the provided arguments.

Direct mapping to avfilter_graph_create_filter().

Parameters ​

filter ​

Filter

Filter descriptor to instantiate

name ​

string

Name for this filter instance

args? ​

string | null = null

Initialization arguments (filter-specific)

Returns ​

FilterContext | null

Created filter context, or null on failure

Example ​

typescript
// Create a scale filter
const scale = graph.createFilter(
  Filter.getByName('scale')!,
  'scaler',
  '640:480'  // width:height
);

// Create a buffer source
const src = graph.createFilter(
  Filter.getByName('buffer')!,
  'source',
  'video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25'
);

See ​


dump() ​

dump(): string | null

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

Dump the filter graph to a string.

Returns a textual representation of the graph structure. Useful for debugging and visualization.

Direct mapping to avfilter_graph_dump().

Returns ​

string | null

Graph description string, or null on failure

Example ​

typescript
const graphStr = graph.dump();
if (graphStr) {
  console.log('Graph structure:');
  console.log(graphStr);
}

free() ​

free(): void

Defined in: src/lib/filter-graph.ts:197

Free the filter graph.

Releases all resources associated with the graph, including all contained filters.

Direct mapping to avfilter_graph_free().

Returns ​

void

Example ​

typescript
graph.free();
// Graph is now invalid

See ​


getFilter() ​

getFilter(name): FilterContext | null

Defined in: src/lib/filter-graph.ts:300

Get a filter by name from the graph.

Retrieves an existing filter context by its instance name.

Direct mapping to avfilter_graph_get_filter().

Parameters ​

name ​

string

Name of the filter instance

Returns ​

FilterContext | null

Filter context if found, null otherwise

Example ​

typescript
// Find a previously created filter
const scaler = graph.getFilter('scaler');
if (scaler) {
  console.log('Found scaler filter');
}

See ​

createFilter To create new filters


getNative() ​

getNative(): NativeFilterGraph

Defined in: src/lib/filter-graph.ts:715

Internal

Get the underlying native FilterGraph object.

Returns ​

NativeFilterGraph

The native FilterGraph 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


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


parse() ​

parse(filters, inputs, outputs): number

Defined in: src/lib/filter-graph.ts:405

Parse a filter graph description.

Parses a textual representation of a filter graph and adds filters to this graph. Handles labeled inputs and outputs.

Direct mapping to avfilter_graph_parse().

Parameters ​

filters ​

string

Filter graph description string

inputs ​

FilterInOut | null

Linked list of graph inputs (copied; still yours to free)

outputs ​

FilterInOut | null

Linked list of graph outputs (copied; still yours to free)

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Parse error
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

const inputs = FilterInOut.createList([
  { name: 'in', filterCtx: bufferSrc, padIdx: 0 }
]);
const outputs = FilterInOut.createList([
  { name: 'out', filterCtx: bufferSink, padIdx: 0 }
]);

const ret = graph.parse(
  '[in]scale=640:480,format=yuv420p[out]',
  inputs,
  outputs
);
FFmpegError.throwIfError(ret, 'parse');

See ​


parse2() ​

parse2(filters): number

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

Parse a filter graph description (simplified).

Parses a textual filter description with automatic input/output handling. Simpler than parse() but less flexible.

Direct mapping to avfilter_graph_parse2().

Parameters ​

filters ​

string

Filter graph description string

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Parse error
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

// Parse a simple filter chain
const ret = graph.parse2(
  'scale=640:480,format=yuv420p'
);
FFmpegError.throwIfError(ret, 'parse2');

See ​

parse For labeled inputs/outputs


parsePtr() ​

parsePtr(filters, inputs?, outputs?): number

Defined in: src/lib/filter-graph.ts:470

Parse a filter graph description with pointer.

Alternative parsing method with different parameter handling.

Direct mapping to avfilter_graph_parse_ptr().

Parameters ​

filters ​

string

Filter graph description string

inputs? ​

FilterInOut | null

Optional linked list of inputs (copied; still yours to free)

outputs? ​

FilterInOut | null

Optional linked list of outputs (copied; still yours to free)

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Parse error
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

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

const ret = graph.parsePtr(
  '[in]scale=w=640:h=480[out]'
);
FFmpegError.throwIfError(ret, 'parsePtr');

See ​

  • parse For standard parsing
  • parse2 For simplified parsing

queueCommand() ​

queueCommand(target, cmd, arg, ts, flags?): number

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

Queue a command for delayed execution.

Schedules a command to be executed at a specific timestamp. The command is executed when the filter processes a frame with that timestamp.

Direct mapping to avfilter_graph_queue_command().

Parameters ​

target ​

string

Filter name or "all"

cmd ​

string

Command to queue

arg ​

string

Command argument

ts ​

number

Timestamp for execution

flags? ​

AVFilterCmdFlag

Command flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

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

// Queue volume change at 5 seconds
const ret = graph.queueCommand(
  'volume',
  'volume',
  '0.2',
  5000000,  // microseconds
  0
);
FFmpegError.throwIfError(ret, 'queueCommand');

See ​

sendCommand For immediate execution


requestOldest() ​

requestOldest(): Promise<number>

Defined in: src/lib/filter-graph.ts:564

Request a frame from the oldest sink.

Requests that a frame be output from the oldest sink in the graph. Used to drive the filter graph processing.

Direct mapping to avfilter_graph_request_oldest().

Returns ​

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_EOF: End of stream reached
  • AVERROR_EAGAIN: Need more input

Example ​

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

const ret = await graph.requestOldest();
if (ret === AVERROR_EOF) {
  // No more frames
} else if (ret === AVERROR_EAGAIN) {
  // Need to provide more input
} else {
  FFmpegError.throwIfError(ret, 'requestOldest');
}

requestOldestSync() ​

requestOldestSync(): number

Defined in: src/lib/filter-graph.ts:599

Request the oldest queued frame from filters synchronously. Synchronous version of requestOldest.

Requests a frame from the oldest sink in the graph. Used for pulling frames through the filter pipeline.

Direct mapping to avfilter_graph_request_oldest().

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EOF: No more frames
  • AVERROR_EAGAIN: Need more input

Example ​

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

// Pull frames through the graph
const ret = graph.requestOldestSync();
if (ret === AVERROR_EOF) {
  // All frames processed
} else if (ret === AVERROR_EAGAIN) {
  // Need more input frames
} else {
  FFmpegError.throwIfError(ret, 'requestOldestSync');
}

See ​

requestOldest For async version


segmentParse() ​

segmentParse(filters, flags?): FilterGraphSegment | null

Defined in: src/lib/filter-graph.ts:509

Parse a filter graph into a segment.

Parses a textual filter description and returns a segment object. The segment separates parsing from initialization, allowing filter contexts to be configured before initialization.

Direct mapping to avfilter_graph_segment_parse().

Parameters ​

filters ​

string

Filter graph description string

flags? ​

number = 0

Parsing flags (default: 0)

Returns ​

FilterGraphSegment | null

FilterGraphSegment instance or null on error

Example ​

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

const segment = graph.segmentParse('scale=640:480');
if (!segment) {
  throw new Error('Failed to parse filter');
}

// Create and configure filters
FFmpegError.throwIfError(segment.createFilters(), 'createFilters');
FFmpegError.throwIfError(segment.applyOpts(), 'applyOpts');
FFmpegError.throwIfError(segment.apply(inputs, outputs), 'apply');

segment.free();

See ​


sendCommand() ​

sendCommand(target, cmd, arg, flags?): number | { response: string | null; }

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

Send a command to filters in the graph.

Sends a command to one or more filters for immediate execution. Target can be a specific filter name or "all" for all filters.

Direct mapping to avfilter_graph_send_command().

Parameters ​

target ​

string

Filter name or "all"

cmd ​

string

Command to send

arg ​

string

Command argument

flags? ​

AVFilterCmdFlag

Command flags

Returns ​

number | { response: string | null; }

Error code or response object

Example ​

typescript
// Send command to specific filter
const result = graph.sendCommand(
  'volume',
  'volume',
  '0.5'
);

// Send to all filters
const result2 = graph.sendCommand(
  'all',
  'enable',
  'timeline'
);

See ​

queueCommand For delayed execution


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


validate() ​

validate(): number

Defined in: src/lib/filter-graph.ts:533

Validate the filter graph configuration.

Checks if the graph is valid and properly configured. Does not finalize the graph like config() does.

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_EINVAL: Invalid configuration

Example ​

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

const ret = graph.validate();
FFmpegError.throwIfError(ret, 'validate');

See ​

config To configure and finalize