FilterGraph

A compiled libavfilter graph. Build with FilterGraph.buildVideo / FilterGraph.buildAudio (single input) or buildVideoMulti / buildAudioMulti (N inputs: overlay, amix, …). Feed frames through process (single input) or feedInput (any input). Close it when done. feedInput and flushInput answer with a FeedResult, which names the input a graph with several inputs waits for.

A graph is single-shot: once EOF has been flushed through it, it cannot accept more frames. process closes the graph itself when its returned flow terminates; push-style users call close (idempotent) when finished.

Multi-input descriptions reference pads by label: inputs are [in0]…[inN-1], the output is [out], e.g. "[in0][in1]overlay=10:10[out]" or "[in0][in1]amix=inputs=2[out]".

Types

Link copied to clipboard
object Companion

Builds graphs.

Properties

Link copied to clipboard

Number of buffersrc inputs this graph was built with.

Link copied to clipboard

Time-base of frames leaving the graph. Filters like fps/atempo may change it.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun feedInput(index: Int, frame: Frame, onOutput: (Frame) -> Unit): FeedResult

Push one frame into input index; each output frame is handed to onOutput as it comes out, before the graph is asked for the next one. Closes frame (the graph keeps its own reference). Output frames are valid only for the duration of the callback; Frame.copy to keep one.

Link copied to clipboard
fun flushInput(index: Int, onOutput: (Frame) -> Unit): FeedResult

Signal EOF on input index and hand over whatever the graph can produce, one frame at a time as for feedInput. Filters like overlay emit their final frames only once every input is flushed. Flush every input, in any order. The last call delivers the remaining frames.

Link copied to clipboard
fun process(input: Flow<Frame>): Flow<Frame>

Drive input through the graph (single-input graphs only), emitting each processed frame owned by the collector as it comes out, before the graph is asked for the next one. Closes every input frame once consumed.

Link copied to clipboard
fun setOutputFrameSize(samples: Int)

Fixed-size sample chunking for the buffersink (audio graphs only). Encoders such as AAC accept exactly frameSize samples per call; setting this makes the graph emit that.