Skip to content

node-av / lib / Option

Class: Option ​

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

FFmpeg option management utilities.

Provides static methods for getting, setting, and querying options on FFmpeg objects that support the AVOption API. Handles type conversion and validation for various option types including strings, numbers, rationals, pixel formats, and more.

Direct mapping to FFmpeg's AVOption API.

Example ​

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

// Set various option types
let ret = Option.set(obj, 'preset', 'fast');
FFmpegError.throwIfError(ret, 'set preset');

ret = Option.setInt(obj, 'bitrate', 2000000);
FFmpegError.throwIfError(ret, 'set bitrate');

ret = Option.setRational(obj, 'framerate', { num: 30, den: 1 });
FFmpegError.throwIfError(ret, 'set framerate');

// Get option values
const preset = Option.get(obj, 'preset');
const bitrate = Option.getInt(obj, 'bitrate');
const framerate = Option.getRational(obj, 'framerate');

// List all options
let opt = null;
while ((opt = Option.next(obj, opt))) {
  console.log(`${opt.name}: ${opt.help}`);
}

See ​

Constructors ​

Constructor ​

new Option(): Option

Returns ​

Option

Methods ​

copy() ​

static copy(dest, src): number

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

Copy options between objects.

Copies option values from source to destination.

Direct mapping to av_opt_copy().

Parameters ​

dest ​

OptionCapableObject

Destination object

src ​

OptionCapableObject

Source object

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Copy options from one codec context to another
const ret = Option.copy(destCodecContext, srcCodecContext);
FFmpegError.throwIfError(ret, 'Failed to copy options');

find() ​

static find(obj, name, searchFlags?): OptionInfo | null

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

Find option by name.

Searches for an option with the specified name.

Direct mapping to av_opt_find().

Parameters ​

obj ​

OptionCapableObject

Object to search

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

OptionInfo | null

Option info if found, null otherwise

Example ​

typescript
const opt = Option.find(obj, 'bitrate');
if (opt) {
  console.log(`Found: ${opt.name}, Type: ${opt.type}`);
}

find2() ​

static find2(obj, name, searchFlags?): { isDifferentTarget: boolean; option: OptionInfo | null; } | null

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

Find option with target info.

Like find() but also indicates if option was found on different target.

Direct mapping to av_opt_find2().

Parameters ​

obj ​

OptionCapableObject

Object to search

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

{ isDifferentTarget: boolean; option: OptionInfo | null; } | null

Object with option and target info

Example ​

typescript
const result = Option.find2(obj, 'bitrate', AV_OPT_SEARCH_CHILDREN);
if (result?.option) {
  console.log(`Found on ${result.isDifferentTarget ? 'child' : 'object'}`);
}

free() ​

static free(obj): void

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

Free option resources.

Direct mapping to av_opt_free().

Parameters ​

obj ​

OptionCapableObject

Object to free options from

Returns ​

void

Example ​

typescript
// Free codec context options
Option.free(codecContext);

get() ​

static get(obj, name, searchFlags?): string | null

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

Get string option value.

Direct mapping to av_opt_get().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

string | null

Option value as string, or null

Example ​

typescript
// Get codec preset option
const preset = Option.get(codecContext, 'preset', AV_OPT_SEARCH_CHILDREN);
console.log('Codec preset:', preset); // 'medium', 'fast', etc.

getChannelLayout() ​

static getChannelLayout(obj, name, searchFlags?): ChannelLayout | null

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

Get channel layout option value.

Direct mapping to av_opt_get_chlayout().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

ChannelLayout | null

Channel layout, or null

Example ​

typescript
// Get audio channel layout
const layout = Option.getChannelLayout(codecContext, 'channel_layout', AV_OPT_SEARCH_CHILDREN);
console.log('Channel layout:', layout); // stereo, 5.1, etc.

getDict() ​

static getDict(obj, name, searchFlags?): Dictionary | null

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

Get dictionary option value.

Direct mapping to av_opt_get_dict_val().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

Dictionary | null

Dictionary value, or null

Example ​

typescript
// Get metadata dictionary
const metadata = Option.getDict(formatContext, 'metadata', AV_OPT_SEARCH_CHILDREN);
console.log('Metadata:', metadata?.get('title'));

getDouble() ​

static getDouble(obj, name, searchFlags?): number | null

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

Get double option value.

Direct mapping to av_opt_get_double().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number | null

Option value as double, or null

Example ​

typescript
// Get codec quality scale
const crf = Option.getDouble(codecContext, 'crf', AV_OPT_SEARCH_CHILDREN);
console.log('CRF value:', crf); // 23.0, 18.0, etc.

getImageSize() ​

static getImageSize(obj, name, searchFlags?): IDimension | null

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

Get image size option value.

Direct mapping to av_opt_get_image_size().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

IDimension | null

Width and height, or null

Example ​

typescript
// Get filter output size
const size = Option.getImageSize(filterContext, 'size', AV_OPT_SEARCH_CHILDREN);
console.log('Output size:', size); // { width: 1920, height: 1080 }

getInt() ​

static getInt(obj, name, searchFlags?): number | null

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

Get integer option value.

Direct mapping to av_opt_get_int().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number | null

Option value as integer, or null

Example ​

typescript
// Get codec GOP size
const gopSize = Option.getInt(codecContext, 'g', AV_OPT_SEARCH_CHILDREN);
console.log('GOP size:', gopSize); // 60, 120, etc.

getInt64() ​

static getInt64(obj, name, searchFlags?): bigint | null

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

Get 64-bit integer option value.

Returns a bigint to keep full int64 precision - getInt goes through a double and truncates values above 2^53.

Direct mapping to av_opt_get_int().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

bigint | null

Option value as bigint, or null

Example ​

typescript
// Get maximum interleave delta
const delta = Option.getInt64(formatContext, 'max_interleave_delta', AV_OPT_SEARCH_CHILDREN);
console.log('Max interleave delta:', delta); // 10000000n

See ​

getInt For 32-bit safe integer options


getPixelFormat() ​

static getPixelFormat(obj, name, searchFlags?): AVPixelFormat | null

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

Get pixel format option value.

Direct mapping to av_opt_get_pixel_fmt().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

AVPixelFormat | null

Pixel format value, or null

Example ​

typescript
// Get filter pixel format
const pixFmt = Option.getPixelFormat(filterContext, 'pix_fmt', AV_OPT_SEARCH_CHILDREN);
console.log('Pixel format:', pixFmt); // AV_PIX_FMT_YUV420P, etc.

getRational() ​

static getRational(obj, name, searchFlags?): IRational | null

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

Get rational option value.

Direct mapping to av_opt_get_q().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

IRational | null

Option value as rational, or null

Example ​

typescript
// Get codec time base
const timeBase = Option.getRational(codecContext, 'time_base', AV_OPT_SEARCH_CHILDREN);
console.log('Time base:', timeBase); // { num: 1, den: 30 }

getSampleFormat() ​

static getSampleFormat(obj, name, searchFlags?): AVSampleFormat | null

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

Get sample format option value.

Direct mapping to av_opt_get_sample_fmt().

Parameters ​

obj ​

OptionCapableObject

Object to query

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

AVSampleFormat | null

Sample format value, or null

Example ​

typescript
// Get audio codec sample format
const sampleFmt = Option.getSampleFormat(codecContext, 'sample_fmt', AV_OPT_SEARCH_CHILDREN);
console.log('Sample format:', sampleFmt); // AV_SAMPLE_FMT_FLTP, etc.

isSetToDefault() ​

static isSetToDefault(obj, name, searchFlags?): boolean | null

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

Check if option is set to default.

Direct mapping to av_opt_is_set_to_default().

Parameters ​

obj ​

OptionCapableObject

Object to check

name ​

string

Option name

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

boolean | null

True if default, false if modified, null if not found

Example ​

typescript
// Check if bitrate is at default value
const isDefault = Option.isSetToDefault(codecContext, 'b', AV_OPT_SEARCH_CHILDREN);
console.log('Bitrate is default:', isDefault);

next() ​

static next(obj, prev?): OptionInfo | null

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

Iterate to next option.

Iterates through available options on an object.

Direct mapping to av_opt_next().

Parameters ​

obj ​

OptionCapableObject

Object with options

prev? ​

OptionInfo | null = null

Previous option (null to get first)

Returns ​

OptionInfo | null

Next option, or null if no more

Example ​

typescript
let opt = null;
while ((opt = Option.next(obj, opt))) {
  console.log(`Option: ${opt.name}`);
}

serialize() ​

static serialize(obj, optFlags?, flags?, keyValSep?, pairsSep?): string | null

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

Serialize options to string.

Direct mapping to av_opt_serialize().

Parameters ​

obj ​

OptionCapableObject

Object to serialize

optFlags? ​

number = 0

Option flags filter

flags? ​

number = 0

Serialization flags

keyValSep? ​

string = '='

Key-value separator

pairsSep? ​

string = ','

Pairs separator

Returns ​

string | null

Serialized string, or null on error

Example ​

typescript
// Serialize codec options to string
const serialized = Option.serialize(codecContext, 0, 0, '=', ':');
console.log('Options:', serialized); // 'bitrate=2000000:preset=fast'

set() ​

static set(obj, name, value, searchFlags?): number

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

Set string option value.

Direct mapping to av_opt_set().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

string

String value

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set codec preset
const ret = Option.set(codecContext, 'preset', 'fast', AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set preset');

setBin() ​

static setBin(obj, name, value, searchFlags?): number

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

Set binary option value.

Direct mapping to av_opt_set_bin().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

Buffer

Binary data

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set binary extradata
const extradata = Buffer.from([0x00, 0x01, 0x02, 0x03]);
const ret = Option.setBin(codecContext, 'extradata', extradata, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set extradata');

setChannelLayout() ​

static setChannelLayout(obj, name, value, searchFlags?): number

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

Set channel layout option value.

Direct mapping to av_opt_set_chlayout().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

number

Channel layout

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set audio channel layout to stereo
const ret = Option.setChannelLayout(codecContext, 'channel_layout', AV_CHANNEL_LAYOUT_STEREO, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set channel layout');

setDefaults() ​

static setDefaults(obj): void

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

Set defaults on object.

Sets all options to their default values.

Direct mapping to av_opt_set_defaults().

Parameters ​

obj ​

OptionCapableObject

Object to reset

Returns ​

void

Example ​

typescript
// Reset all codec options to defaults
Option.setDefaults(codecContext);

setDict() ​

static setDict(obj, name, value, searchFlags?): number

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

Set dictionary option value.

Direct mapping to av_opt_set_dict_val().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

Dictionary

Dictionary value

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set metadata dictionary
const dict = new Dictionary();
dict.set('title', 'My Video');
const ret = Option.setDict(formatContext, 'metadata', dict, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set metadata');

setDouble() ​

static setDouble(obj, name, value, searchFlags?): number

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

Set double option value.

Direct mapping to av_opt_set_double().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

number

Double value

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set codec CRF value
const ret = Option.setDouble(codecContext, 'crf', 23.0, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set CRF');

setImageSize() ​

static setImageSize(obj, name, width, height, searchFlags?): number

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

Set image size option value.

Direct mapping to av_opt_set_image_size().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

width ​

number

Image width

height ​

number

Image height

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set filter output size
const ret = Option.setImageSize(filterContext, 'size', 1920, 1080, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set image size');

setInt() ​

static setInt(obj, name, value, searchFlags?): number

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

Set integer option value.

Direct mapping to av_opt_set_int().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

number | bigint

Integer value

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set codec bitrate
const ret = Option.setInt(codecContext, 'b', 2000000, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set bitrate');

setPixelFormat() ​

static setPixelFormat(obj, name, value, searchFlags?): number

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

Set pixel format option value.

Direct mapping to av_opt_set_pixel_fmt().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

AVPixelFormat

Pixel format

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set filter pixel format
const ret = Option.setPixelFormat(filterContext, 'pix_fmt', AV_PIX_FMT_YUV420P, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set pixel format');

setRational() ​

static setRational(obj, name, value, searchFlags?): number

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

Set rational option value.

Direct mapping to av_opt_set_q().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

IRational

Rational value

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set codec frame rate
const ret = Option.setRational(codecContext, 'framerate', { num: 30, den: 1 }, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set framerate');

setSampleFormat() ​

static setSampleFormat(obj, name, value, searchFlags?): number

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

Set sample format option value.

Direct mapping to av_opt_set_sample_fmt().

Parameters ​

obj ​

OptionCapableObject

Object to modify

name ​

string

Option name

value ​

AVSampleFormat

Sample format

searchFlags? ​

AVOptionSearchFlags = AVFLAG_NONE

Search flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Set audio codec sample format
const ret = Option.setSampleFormat(codecContext, 'sample_fmt', AV_SAMPLE_FMT_FLTP, AV_OPT_SEARCH_CHILDREN);
FFmpegError.throwIfError(ret, 'Failed to set sample format');

show() ​

static show(obj, reqFlags?, rejFlags?): number

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

Show options for debugging.

Direct mapping to av_opt_show2().

Parameters ​

obj ​

OptionCapableObject

Object to show options for

reqFlags? ​

number = 0

Required flags

rejFlags? ​

number = 0

Rejected flags

Returns ​

number

0 on success, negative AVERROR on error

Example ​

typescript
// Show all codec options for debugging
const ret = Option.show(codecContext, 0, 0);
FFmpegError.throwIfError(ret, 'Failed to show options');