Skip to content

node-av / lib / FilterGraphSegment

Class: FilterGraphSegment

Defined in: src/lib/filter-graph-segment.ts:16

Parsed filter graph segment.

Represents a parsed filtergraph segment that separates parsing from initialization. This allows filter contexts to be configured after creation but before initialization. The workflow involves parsing the filter description, creating filter instances, applying options, and finally initializing and linking the filters.

Direct mapping to FFmpeg's AVFilterGraphSegment.

See

AVFilterGraphSegment - FFmpeg Doxygen

Implements

  • Disposable

Constructors

Constructor

new FilterGraphSegment(native): FilterGraphSegment

Defined in: src/lib/filter-graph-segment.ts:24

Internal

Parameters

native

NativeFilterGraphSegment

The native filter graph segment instance

Returns

FilterGraphSegment

Methods

[dispose]()

[dispose](): void

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

Dispose of the segment.

Automatically frees the segment when using the using statement. This implements the Disposable interface for automatic resource cleanup. Equivalent to calling free().

Returns

void

Example

typescript
{
  using segment = graph.segmentParse('scale=640:480');
  // Use segment...
} // Automatically freed

Implementation of

Disposable.[dispose]


apply()

apply(inputs, outputs, flags): number

Defined in: src/lib/filter-graph-segment.ts:134

Initialize and link all filters in the segment.

Initializes all filter contexts in the segment and creates links between them according to the parsed filter graph description. This is the final step that completes the filter setup. All necessary filter configuration should be done before calling this method.

Direct mapping to avfilter_graph_segment_apply().

Parameters

inputs

FilterInOut

Input filter pads

outputs

FilterInOut

Output filter pads

flags

number = 0

Apply flags (default: 0)

Returns

number

0 on success, negative AVERROR on failure:

  • AVERROR_EINVAL: Invalid segment or pads
  • AVERROR_ENOMEM: Memory allocation failure

Example

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

const segment = graph.segmentParse('scale=640:480');
if (segment) {
  FFmpegError.throwIfError(segment.createFilters(), 'createFilters');
  FFmpegError.throwIfError(segment.applyOpts(), 'applyOpts');

  const inputs = new FilterInOut();
  const outputs = new FilterInOut();
  FFmpegError.throwIfError(segment.apply(inputs, outputs), 'apply');

  inputs.free();
  outputs.free();
  segment.free();
}

See


applyOpts()

applyOpts(flags): number

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

Apply options to filter instances.

Applies the parsed filter options to their respective filter contexts. This method should be called after creating filters and before initializing them.

Direct mapping to avfilter_graph_segment_apply_opts().

Parameters

flags

number = 0

Option flags (default: 0)

Returns

number

0 on success, negative AVERROR on failure:

  • AVERROR_EINVAL: Invalid options
  • AVERROR_OPTION_NOT_FOUND: Unknown option

Example

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

const segment = graph.segmentParse('scale=640:480');
if (segment) {
  FFmpegError.throwIfError(segment.createFilters(), 'createFilters');
  FFmpegError.throwIfError(segment.applyOpts(), 'applyOpts');
}

See

  • createFilters To create filter instances first
  • apply To initialize and link after applying options

createFilters()

createFilters(flags): number

Defined in: src/lib/filter-graph-segment.ts:56

Create filter instances in the segment.

Allocates all filter contexts defined in the segment but does not initialize them. This separation allows configuration of filter properties before the filters are initialized.

Direct mapping to avfilter_graph_segment_create_filters().

Parameters

flags

number = 0

Creation flags (default: 0)

Returns

number

0 on success, negative AVERROR on failure:

  • AVERROR_EINVAL: Invalid segment
  • AVERROR_ENOMEM: Memory allocation failure

Example

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

const segment = graph.segmentParse('scale=640:480');
if (segment) {
  const ret = segment.createFilters();
  FFmpegError.throwIfError(ret, 'createFilters');
}

See

  • applyOpts To apply options after creation
  • apply To initialize and link filters

free()

free(): void

Defined in: src/lib/filter-graph-segment.ts:157

Free the segment and all associated resources.

Releases all memory and resources allocated for this filter graph segment. After calling this method, the segment cannot be used anymore.

Direct mapping to avfilter_graph_segment_free().

Returns

void

Example

typescript
const segment = graph.segmentParse('scale=640:480');
if (segment) {
  // Use segment...
  segment.free();
}

See

Symbol.dispose For automatic cleanup with using statement