Skip to content

node-av / lib / IOContext

Class: IOContext ​

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

I/O context for custom input/output operations.

Provides an abstraction layer for all I/O operations in FFmpeg. Enables reading from and writing to various sources including files, network streams, memory buffers, and custom callbacks. Essential for implementing custom protocols or handling non-standard I/O scenarios.

Direct mapping to FFmpeg's AVIOContext.

Example ​

typescript
import { IOContext, FFmpegError } from 'node-av';
import { AVIO_FLAG_READ, AVIO_FLAG_WRITE, AVSEEK_SET } from 'node-av/constants';

// Open file for reading
const io = new IOContext();
const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
FFmpegError.throwIfError(ret, 'open2');

// Read data
const data = await io.read(4096);
if (data instanceof Buffer) {
  console.log(`Read ${data.length} bytes`);
}

// Seek to position
const pos = await io.seek(1024n, AVSEEK_SET);
console.log(`Seeked to position ${pos}`);

// Get file size
const fileSize = await io.size();
console.log(`File size: ${fileSize}`);

// Close when done
await io.closep();

// Custom I/O with callbacks
const customIO = new IOContext();
let position = 0n;
const buffer = Buffer.from('Hello World');

customIO.allocContextWithCallbacks(
  4096,  // Buffer size
  0,     // Read mode
  (size) => {
    // Read callback
    const end = Number(position) + size;
    const chunk = buffer.subarray(Number(position), end);
    position = BigInt(end);
    return chunk;
  },
  null,  // No write callback for read mode
  (offset, whence) => {
    // Seek callback
    if (whence === AVSEEK_SET) position = offset;
    else if (whence === AVSEEK_CUR) position += offset;
    else if (whence === AVSEEK_END) position = BigInt(buffer.length) + offset;
    return position;
  }
);

See ​

Extends ​

Implements ​

Constructors ​

Constructor ​

new IOContext(): IOContext

Defined in: src/lib/io-context.ts:75

Returns ​

IOContext

Overrides ​

OptionMember<NativeIOContext>.constructor

Properties ​

native ​

protected native: NativeIOContext

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

Inherited from ​

OptionMember.native

Accessors ​

bufferSize ​

Get Signature ​

get bufferSize(): number

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

Internal buffer size.

Size of the internal buffer used for I/O operations.

Direct mapping to AVIOContext->buffer_size.

Returns ​

number


direct ​

Get Signature ​

get direct(): number

Defined in: src/lib/io-context.ts:154

Direct mode flag.

If set, the I/O context will attempt to avoid buffering.

Direct mapping to AVIOContext->direct.

Returns ​

number

Set Signature ​

set direct(value): void

Defined in: src/lib/io-context.ts:158

Parameters ​
value ​

number

Returns ​

void


eof ​

Get Signature ​

get eof(): boolean

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

End of file indicator.

True if end of file has been reached during reading.

Direct mapping to AVIOContext->eof_reached.

Returns ​

boolean


error ​

Get Signature ​

get error(): number

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

Error code.

Contains the last error that occurred, or 0 if no error.

Direct mapping to AVIOContext->error.

Returns ​

number


maxPacketSize ​

Get Signature ​

get maxPacketSize(): number

Defined in: src/lib/io-context.ts:139

Maximum packet size.

Used to limit packet sizes in network protocols. 0 means no limit.

Direct mapping to AVIOContext->max_packet_size.

Returns ​

number

Set Signature ​

set maxPacketSize(value): void

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

Parameters ​
value ​

number

Returns ​

void


pos ​

Get Signature ​

get pos(): bigint

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

Current position.

Current byte position in the stream.

Direct mapping to AVIOContext->pos.

Returns ​

bigint


seekable ​

Get Signature ​

get seekable(): number

Defined in: src/lib/io-context.ts:127

Seekability indicator.

Non-zero if the underlying resource supports seeking. Some protocols like pipes or network streams may not be seekable.

Direct mapping to AVIOContext->seekable.

Returns ​

number


writeFlag ​

Get Signature ​

get writeFlag(): boolean

Defined in: src/lib/io-context.ts:191

Write flag.

True if opened for writing, false for reading.

Direct mapping to AVIOContext->write_flag.

Returns ​

boolean

Methods ​

[asyncDispose]() ​

[asyncDispose](): Promise<void>

Defined in: src/lib/io-context.ts:811

Dispose of the I/O context asynchronously.

Implements the AsyncDisposable interface for automatic cleanup. Closes the context and releases resources.

Returns ​

Promise<void>

Example ​

typescript
{
  await using io = new IOContext();
  await io.open2('input.mp4');
  // Use io...
} // Automatically closed when leaving scope

Implementation of ​

AsyncDisposable.[asyncDispose]


[dispose]() ​

[dispose](): void

Defined in: src/lib/io-context.ts:792

Dispose of the I/O context synchronously.

Implements the Disposable interface for automatic cleanup. Closes the context and releases resources.

Returns ​

void

Example ​

typescript
{
  using io = IOStream.create(buffer);
  // Use io...
} // Automatically freed when leaving scope

Implementation of ​

Disposable.[dispose]


allocContext() ​

allocContext(bufferSize, writeFlag): void

Defined in: src/lib/io-context.ts:215

Allocate I/O context with buffer.

Allocates a basic I/O context with an internal buffer. For custom I/O, use allocContextWithCallbacks instead.

Direct mapping to avio_alloc_context() without callbacks.

Parameters ​

bufferSize ​

number

Size of internal buffer

writeFlag ​

number

1 for write, 0 for read

Returns ​

void

Example ​

typescript
const io = new IOContext();
io.allocContext(4096, 0); // 4KB buffer for reading

See ​

allocContextWithCallbacks For custom I/O


allocContextWithCallbacks() ​

allocContextWithCallbacks(bufferSize, writeFlag, readCallback?, writeCallback?, seekCallback?): void

Defined in: src/lib/io-context.ts:274

Allocate I/O context with custom callbacks.

Creates an I/O context with custom read, write, and seek callbacks. Enables implementing custom protocols or data sources.

NOTE: When using JavaScript callbacks, synchronous operations (e.g., readSync, seekSync) cannot be used on this context. This is because JavaScript callbacks require the event loop to be available, which is blocked during synchronous operations. Always use async methods (read, seek) when working with custom callbacks.

Direct mapping to avio_alloc_context() with callbacks.

Parameters ​

bufferSize ​

number

Size of internal buffer

writeFlag ​

0 | 1

1 for write mode, 0 for read mode

readCallback? ​

((size) => number | Buffer<ArrayBufferLike> | Promise<number | Buffer<ArrayBufferLike> | null> | null) | null

Function to read data (null for write-only)

writeCallback? ​

((buffer) => number | void | Promise<number | void>) | null

Function to write data (null for read-only)

seekCallback? ​

((offset, whence) => number | bigint | Promise<number | bigint>) | null

Function to seek in stream (optional)

Returns ​

void

Example ​

typescript
import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END, AVSEEK_SIZE } from 'node-av/constants';

const data = Buffer.from('Custom data source');
let position = 0;

io.allocContextWithCallbacks(
  4096,
  0, // Read mode
  (size) => {
    // Read callback
    if (position >= data.length) return -541; // EOF
    const chunk = data.subarray(position, position + size);
    position += chunk.length;
    return chunk;
  },
  null,
  (offset, whence) => {
    // Seek callback
    if (whence === AVSEEK_SIZE) return BigInt(data.length);
    if (whence === AVSEEK_SET) position = Number(offset);
    else if (whence === AVSEEK_CUR) position += Number(offset);
    else if (whence === AVSEEK_END) position = data.length + Number(offset);
    return BigInt(position);
  }
);

See ​

allocContext For simple allocation


closep() ​

closep(): Promise<number>

Defined in: src/lib/io-context.ts:398

Close I/O context.

Closes the I/O context and releases associated resources. Flushes any buffered data before closing. A context that was already closed or freed is a no-op, matching avio_close() on a null context.

Direct mapping to avio_closep().

Returns ​

Promise<number>

0 on success or when there was nothing left to close, negative AVERROR on error

Example ​

typescript
const ret = await io.closep();
if (ret < 0) {
  console.error('Error closing I/O context');
}

See ​

open2 To open resources


closepSync() ​

closepSync(): number

Defined in: src/lib/io-context.ts:424

Close I/O context synchronously. Synchronous version of closep.

Closes the I/O context and frees resources. Sets internal pointer to NULL. A context that was already closed or freed is a no-op, matching avio_close() on a null context.

Direct mapping to avio_closep().

Returns ​

number

0 on success or when there was nothing left to close, negative AVERROR on error

Example ​

typescript
const ret = io.closepSync();
if (ret < 0) {
  console.error(`Failed to close: ${ret}`);
}

See ​

closep For async version


flush() ​

flush(): Promise<void>

Defined in: src/lib/io-context.ts:671

Flush buffered data.

Forces any buffered data to be written to the underlying resource.

Direct mapping to avio_flush().

Returns ​

Promise<void>

Example ​

typescript
await io.write(data);
await io.flush(); // Ensure data is written

See ​

write For writing data


flushSync() ​

flushSync(): void

Defined in: src/lib/io-context.ts:691

Flush buffered data synchronously. Synchronous version of flush.

Forces any buffered data to be written to the underlying resource.

Direct mapping to avio_flush().

Returns ​

void

Example ​

typescript
io.writeSync(data);
io.flushSync(); // Ensure data is written

See ​

flush For async version


freeContext() ​

freeContext(): void

Defined in: src/lib/io-context.ts:298

Free I/O context.

Releases the I/O context and its resources. The context becomes invalid after calling this.

Direct mapping to avio_context_free().

Returns ​

void

Example ​

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

getNative() ​

getNative(): NativeIOContext

Defined in: src/lib/io-context.ts:774

Internal

Get the underlying native IOContext object.

Returns ​

NativeIOContext

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


open2() ​

open2(url, flags?): Promise<number>

Defined in: src/lib/io-context.ts:335

Open resource for I/O.

Opens a URL or file for reading or writing. Automatically selects the appropriate protocol handler.

Direct mapping to avio_open2().

Parameters ​

url ​

string

URL or file path to open

flags? ​

AVIOFlag = AVIO_FLAG_READ

Open flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)

Returns ​

Promise<number>

0 on success, negative AVERROR on error:

  • AVERROR_ENOENT: File not found
  • AVERROR_EACCES: Permission denied
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

typescript
import { FFmpegError } from 'node-av';
import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';

// Open for reading
const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
FFmpegError.throwIfError(ret, 'open2');

// Open for writing
const ret2 = await io.open2('output.mp4', AVIO_FLAG_WRITE);
FFmpegError.throwIfError(ret2, 'open2');

See ​

closep To close after use


open2Sync() ​

open2Sync(url, flags?): number

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

Open resource for I/O synchronously. Synchronous version of open2.

Opens a URL or file for reading or writing. Automatically selects the appropriate protocol handler.

Direct mapping to avio_open2().

Parameters ​

url ​

string

URL or file path to open

flags? ​

AVIOFlag = AVIO_FLAG_READ

Open flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)

Returns ​

number

0 on success, negative AVERROR on error:

  • AVERROR_ENOENT: File not found
  • AVERROR_EACCES: Permission denied
  • AVERROR_ENOMEM: Memory allocation failure

Example ​

typescript
import { FFmpegError } from 'node-av';
import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';

// Open for reading
const ret = io.open2Sync('input.mp4', AVIO_FLAG_READ);
FFmpegError.throwIfError(ret, 'open2');

// Open for writing
const ret2 = io.open2Sync('output.mp4', AVIO_FLAG_WRITE);
FFmpegError.throwIfError(ret2, 'open2');

See ​

open2 For async version


read() ​

read(size): Promise<number | Buffer<ArrayBufferLike>>

Defined in: src/lib/io-context.ts:453

Read data from I/O context.

Reads up to the specified number of bytes from the stream.

Direct mapping to avio_read().

Parameters ​

size ​

number

Maximum number of bytes to read

Returns ​

Promise<number | Buffer<ArrayBufferLike>>

Buffer with data, or error code if negative:

  • AVERROR_EOF: End of file reached
  • AVERROR_EIO: I/O error

Example ​

typescript
const data = await io.read(4096);
if (data instanceof Buffer) {
  console.log(`Read ${data.length} bytes`);
} else {
  console.error(`Read error: ${data}`);
}

See ​

write For writing data


readSync() ​

readSync(size): number | Buffer<ArrayBufferLike>

Defined in: src/lib/io-context.ts:481

Read data from I/O context synchronously. Synchronous version of read.

Reads up to the specified number of bytes from the stream.

Direct mapping to avio_read().

Parameters ​

size ​

number

Number of bytes to read

Returns ​

number | Buffer<ArrayBufferLike>

Buffer with data, or negative AVERROR on error

Example ​

typescript
const result = io.readSync(4096);
if (Buffer.isBuffer(result)) {
  console.log(`Read ${result.length} bytes`);
} else {
  console.log(`Read error: ${result}`);
}

See ​

read For async version


seek() ​

seek(offset, whence): Promise<bigint>

Defined in: src/lib/io-context.ts:562

Seek to position in stream.

Changes the current position in the stream. Not all streams support seeking.

Direct mapping to avio_seek().

Parameters ​

offset ​

bigint

Byte offset to seek to

whence ​

AVSeekWhence

Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)

Returns ​

Promise<bigint>

New position, or negative AVERROR on error:

  • AVERROR_EINVAL: Invalid arguments
  • AVERROR_ENOSYS: Seeking not supported

Example ​

typescript
import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av/constants';

// Seek to absolute position
const pos1 = await io.seek(1024n, AVSEEK_SET);

// Seek relative to current position
const pos2 = await io.seek(512n, AVSEEK_CUR);

// Seek relative to end
const pos3 = await io.seek(-1024n, AVSEEK_END);

See ​

  • tell To get current position
  • skip For relative seeking

seekSync() ​

seekSync(offset, whence): bigint

Defined in: src/lib/io-context.ts:599

Seek to position in stream synchronously. Synchronous version of seek.

Changes the current position in the stream. Not all streams support seeking.

Direct mapping to avio_seek().

Parameters ​

offset ​

bigint

Byte offset to seek to

whence ​

AVSeekWhence

Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)

Returns ​

bigint

New position, or negative AVERROR on error:

  • AVERROR_EINVAL: Invalid arguments
  • AVERROR_ENOSYS: Seeking not supported

Example ​

typescript
import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av/constants';

// Seek to absolute position
const pos1 = io.seekSync(1024n, AVSEEK_SET);

// Seek relative to current position
const pos2 = io.seekSync(512n, AVSEEK_CUR);

// Seek relative to end
const pos3 = io.seekSync(-1024n, AVSEEK_END);

See ​

seek For async version


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


size() ​

size(): Promise<bigint>

Defined in: src/lib/io-context.ts:624

Get stream size.

Returns the total size of the stream in bytes. Not all streams have a known size.

Direct mapping to avio_size().

Returns ​

Promise<bigint>

Size in bytes, or negative AVERROR if unknown:

  • AVERROR_ENOSYS: Size not available

Example ​

typescript
const size = await io.size();
if (size >= 0n) {
  console.log(`Stream size: ${size} bytes`);
} else {
  console.log('Stream size unknown');
}

sizeSync() ​

sizeSync(): bigint

Defined in: src/lib/io-context.ts:652

Get stream size synchronously. Synchronous version of size.

Returns the total size of the stream in bytes. Not all streams have a known size.

Direct mapping to avio_size().

Returns ​

bigint

Size in bytes, or negative AVERROR if unknown:

  • AVERROR_ENOSYS: Size not available

Example ​

typescript
const size = io.sizeSync();
if (size >= 0n) {
  console.log(`Stream size: ${size} bytes`);
} else {
  console.log('Stream size unknown');
}

See ​

size For async version


skip() ​

skip(offset): Promise<bigint>

Defined in: src/lib/io-context.ts:716

Skip bytes in stream.

Advances the position by the specified offset. More efficient than reading and discarding data.

Direct mapping to avio_skip().

Parameters ​

offset ​

bigint

Number of bytes to skip

Returns ​

Promise<bigint>

New position after skipping

Example ​

typescript
// Skip 1024 bytes forward
const newPos = await io.skip(1024n);
console.log(`New position: ${newPos}`);

See ​

seek For absolute positioning


skipSync() ​

skipSync(offset): bigint

Defined in: src/lib/io-context.ts:742

Skip bytes in stream synchronously. Synchronous version of skip.

Advances the position by the specified offset. More efficient than reading and discarding data.

Direct mapping to avio_skip().

Parameters ​

offset ​

bigint

Number of bytes to skip

Returns ​

bigint

New position after skipping

Example ​

typescript
// Skip 1024 bytes forward
const newPos = io.skipSync(1024n);
console.log(`New position: ${newPos}`);

See ​

skip For async version


tell() ​

tell(): bigint

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

Get current position.

Returns the current byte position in the stream.

Direct mapping to avio_tell().

Returns ​

bigint

Current position in bytes

Example ​

typescript
const position = io.tell();
console.log(`Current position: ${position}`);

See ​

seek To change position


write() ​

write(buffer): Promise<void>

Defined in: src/lib/io-context.ts:503

Write data to I/O context.

Writes buffer data to the stream.

Direct mapping to avio_write().

Parameters ​

buffer ​

Buffer

Data to write

Returns ​

Promise<void>

Example ​

typescript
const data = Buffer.from('Hello World');
await io.write(data);

See ​


writeSync() ​

writeSync(buffer): void

Defined in: src/lib/io-context.ts:525

Write data to I/O context synchronously. Synchronous version of write.

Writes buffer data to the stream.

Direct mapping to avio_write().

Parameters ​

buffer ​

Buffer

Data to write

Returns ​

void

Example ​

typescript
const data = Buffer.from('Hello, World!');
io.writeSync(data);

See ​

write For async version


fromNative() ​

static fromNative(native): IOContext

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

Internal

Find input format by short name.

Creates an IOContext instance from a native binding object. Used internally for wrapping native I/O contexts.

Parameters ​

native ​

NativeIOContext

Native IOContext binding object

Returns ​

IOContext

Wrapped IOContext instance