Skip to content

node-av / lib / InputFormat

Class: InputFormat

Defined in: src/lib/input-format.ts:46

Input format descriptor for demuxing media files.

Represents a demuxer that can read and parse specific media container formats. Each format handles specific file types (e.g., MP4, MKV, AVI) and knows how to extract streams and packets from them. Used to identify and open media files for reading.

Direct mapping to FFmpeg's AVInputFormat.

Example

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

// Find format by name
const mp4Format = InputFormat.findInputFormat('mp4');
if (mp4Format) {
  console.log(`Format: ${mp4Format.name}`);
  console.log(`Description: ${mp4Format.longName}`);
  console.log(`Extensions: ${mp4Format.extensions}`);
}

// Probe format from file data
const fileData = Buffer.from([...]); // First few KB of file
const detectedFormat = InputFormat.probe(fileData, 'video.mp4');
if (detectedFormat) {
  console.log(`Detected: ${detectedFormat.name}`);
}

// Use with format context
const formatContext = new FormatContext();
formatContext.inputFormat = mp4Format;
const ret = await formatContext.openInput('video.mp4');
FFmpegError.throwIfError(ret, 'openInput');

See

Implements

Constructors

Constructor

new InputFormat(native): InputFormat

Defined in: src/lib/input-format.ts:54

Internal

Parameters

native

NativeInputFormat

The native input format instance

Returns

InputFormat

Accessors

extensions

Get Signature

get extensions(): string | null

Defined in: src/lib/input-format.ts:259

File extensions.

Comma-separated list of file extensions for this format.

Direct mapping to AVInputFormat->extensions.

Returns

string | null


flags

Get Signature

get flags(): AVFormatFlag

Defined in: src/lib/input-format.ts:281

Format flags.

Combination of AVFMT_* flags indicating format capabilities.

Direct mapping to AVInputFormat->flags.

Returns

AVFormatFlag


longName

Get Signature

get longName(): string | null

Defined in: src/lib/input-format.ts:248

Format long name.

Human-readable description of the format.

Direct mapping to AVInputFormat->long_name.

Returns

string | null


mimeType

Get Signature

get mimeType(): string | null

Defined in: src/lib/input-format.ts:270

MIME type.

MIME type(s) associated with this format.

Direct mapping to AVInputFormat->mime_type.

Returns

string | null


name

Get Signature

get name(): string | null

Defined in: src/lib/input-format.ts:237

Format short name.

Short identifier for the format (e.g., 'mp4', 'mkv').

Direct mapping to AVInputFormat->name.

Returns

string | null

Methods

getNative()

getNative(): NativeInputFormat

Defined in: src/lib/input-format.ts:321

Internal

Get the underlying native InputFormat object.

Returns

NativeInputFormat

The native InputFormat binding object

Implementation of

NativeWrapper.getNative


hasFlags()

hasFlags(...flags): boolean

Defined in: src/lib/input-format.ts:305

Check if input format has specific flags.

Tests whether all specified flags are set using bitwise AND.

Parameters

flags

...AVFormatFlag[]

One or more flag values to check

Returns

boolean

true if all specified flags are set, false otherwise

Example

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

if (inputFormat.hasFlags(AVFMT_NOFILE)) {
  console.log('This format does not need a file');
}

See

flags For direct flags access


findInputFormat()

static findInputFormat(shortName): InputFormat | null

Defined in: src/lib/input-format.ts:84

Find input format by short name.

Searches for a demuxer by its short name identifier.

Direct mapping to av_find_input_format().

Parameters

shortName

string

Format short name (e.g., 'mp4', 'mkv', 'avi')

Returns

InputFormat | null

Input format if found, null otherwise

Example

typescript
// Find specific formats
const mp4 = InputFormat.findInputFormat('mp4');
const mkv = InputFormat.findInputFormat('matroska');
const avi = InputFormat.findInputFormat('avi');

// Check if format is available
if (!mp4) {
  console.error('MP4 format not available');
}

See

probe To auto-detect format


probe()

static probe(buffer, filename?): InputFormat | null

Defined in: src/lib/input-format.ts:124

Probe format from buffer data.

Analyzes buffer content to determine the media format. Optionally uses filename for additional format hints.

Direct mapping to av_probe_input_format2().

Parameters

buffer

Buffer

Buffer containing file header/start

filename?

string

Optional filename for format hints

Returns

InputFormat | null

Detected format, or null if not recognized

Example

typescript
import { readFileSync } from 'fs';

// Read first 4KB for probing
const data = readFileSync('video.mp4').subarray(0, 4096);
const format = InputFormat.probe(data, 'video.mp4');

if (format) {
  console.log(`Detected format: ${format.name}`);
} else {
  console.error('Unknown format');
}

See


probeBuffer()

static probeBuffer(ioContext, maxProbeSize?): Promise<InputFormat | null>

Defined in: src/lib/input-format.ts:165

Probe format from IO context.

Reads data from an IO context to determine format. Useful for custom IO scenarios and network streams.

Direct mapping to av_probe_input_buffer2().

Parameters

ioContext

NativeWrapper<NativeIOContext>

IO context to read from

maxProbeSize?

number

Maximum bytes to read for probing

Returns

Promise<InputFormat | null>

Detected format, or null if not recognized

Example

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

// Create custom IO context
const ioContext = new IOContext();
// ... configure IO context ...

// Probe format
const format = await InputFormat.probeBuffer(ioContext, 32768);
if (format) {
  console.log(`Stream format: ${format.name}`);
}

See

probe For buffer probing


probeBufferSync()

static probeBufferSync(ioContext, maxProbeSize?): InputFormat | null

Defined in: src/lib/input-format.ts:215

Probe format from IO context synchronously. Synchronous version of probeBuffer.

Reads data from an IO context to determine format. Useful for custom IO scenarios and network streams.

Direct mapping to av_probe_input_buffer2().

Parameters

ioContext

NativeWrapper<NativeIOContext>

IO context to read from

maxProbeSize?

number

Maximum bytes to read for probing

Returns

InputFormat | null

Detected format, or null if not recognized

Example

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

// Create IO context
const ioContext = new IOContext();
// ... configure IO context ...

// Probe format
const format = InputFormat.probeBufferSync(ioContext, 32768);
if (format) {
  console.log(`Format: ${format.name}`);
}

See

probeBuffer For async version