Skip to content

compile_python

Python code compilation utilities for FFmpeg streams.

Functions:

Name Description
compile

Compile the python code.

compile_fluent

Compile the fluent code.

compile_kwargs

Compile the kwargs for the node.

filter_stream_typed_index

Get the index of the matched stream in the outgoing streams of the node.

get_input_var_name

Get the input variable name for the stream.

get_output_var_name

Get the output variable name for the node.

parse

Parse the python code.

compile

compile(
    stream: Stream,
    auto_fix: bool = True,
    fluent: bool = True,
) -> str

Compile the python code.

This is used to compile the python code. For example, if the stream is a video stream, the compiled code will be the python code to create the video stream.

Parameters:

Name Type Description Default
stream Stream

The stream to compile.

required
auto_fix bool

Whether to auto fix the stream.

True
fluent bool

Whether to use fluent syntax.

True

Returns:

Type Description
str

The compiled python code.

compile_fluent

compile_fluent(code: list[str]) -> list[str]

Compile the fluent code.

This is used to compile the fluent code. For example, if the code is ["a=1", "b=2"], the compiled code will be ["a=1", "b=2"].

Parameters:

Name Type Description Default
code list[str]

The code to compile.

required

Returns:

Type Description
list[str]

The compiled code.

compile_kwargs

compile_kwargs(kwargs: Mapping[str, Any]) -> str

Compile the kwargs for the node.

This is used to compile the kwargs for the node. For example, if the kwargs is {"a": 1, "b": 2}, the compiled kwargs will be "a=1, b=2".

Parameters:

Name Type Description Default
kwargs Mapping[str, Any]

The kwargs to compile.

required

Returns:

Type Description
str

The compiled kwargs.

filter_stream_typed_index

filter_stream_typed_index(
    matched_stream: FilterableStream, context: DAGContext
) -> int

Get the index of the matched stream in the outgoing streams of the node.

This is used to get the index of the stream in the outgoing streams of the node. For example, if the node has 2 outgoing streams, and the first one is a video stream, and the second one is an audio stream, and the matched stream is the first video stream, the index will be 0.

Parameters:

Name Type Description Default
matched_stream FilterableStream

The stream to get the index of.

required
context DAGContext

The context of the node.

required

Returns:

Type Description
int

The index of the matched stream in the outgoing streams of the node.

get_input_var_name

get_input_var_name(
    stream: Stream,
    context: DAGContext,
    filter_data_dict: dict[str, FFMpegFilter],
) -> str

Get the input variable name for the stream.

This is used to get the input variable name for the stream. For example, if the stream is a video stream, the input variable name will be "video_stream_0".

Parameters:

Name Type Description Default
stream Stream

The stream to get the input variable name for.

required
context DAGContext

The context of the node.

required

Returns:

Type Description
str

The input variable name for the stream.

Raises:

Type Description
ValueError

If the stream type is unknown

get_output_var_name

get_output_var_name(node: Node, context: DAGContext) -> str

Get the output variable name for the node.

This is used to get the output variable name for the node. For example, if the node is an input node, the output variable name will be "input_0".

Parameters:

Name Type Description Default
node Node

The node to get the output variable name for.

required
context DAGContext

The context of the node.

required

Returns:

Type Description
str

The output variable name for the node.

Raises:

Type Description
ValueError

If the node type is unknown

parse

parse(code: str) -> Stream

Parse the python code.

This is used to parse the python code. For example, if the code is ["import ffmpeg", "input_0 = ffmpeg.input('input1.mp4')", "result = input_0"], the parsed stream will be the stream created by the input node.

Parameters:

Name Type Description Default
code str

The code to parse.

required

Returns:

Type Description
Stream

The parsed stream.