Filters
apply
apply(node, *parent)
Apply a filter input streams.
This function connects the given input nodes (either BaseInput or StreamSpecifier) to a filter node and returns a single output stream from the filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
BaseFilter
|
The filter node to apply. |
required |
*parent
|
BaseInput | StreamSpecifier
|
Input nodes to connect to the filter. |
()
|
Returns:
Name | Type | Description |
---|---|---|
StreamSpecifier |
StreamSpecifier
|
The resulting single output stream from the filter. |
apply2
apply2(node, *parent)
Apply a filter input streams.
This function connects the given input nodes (either BaseInput or StreamSpecifier) to a filter node and returns a list of all output streams from the filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
BaseFilter
|
The filter node to apply. |
required |
*parent
|
BaseInput | StreamSpecifier
|
Input nodes to connect to the filter. |
()
|
Returns:
Type | Description |
---|---|
list[StreamSpecifier]
|
list[StreamSpecifier]: A list of output streams from the filter. |
Text
Text(text, x, y, fontsize=16, fontname='arial.ttf', color='white', alpha=None, text_expansion=False, **kwargs)
Bases: BaseFilter
, TimelineEditingMixin
Draw a text string or text from a specified file on top of a video, using the libfreetype library.
enable_after
enable_after(t)
Enable the filter only after the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) after which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_before
enable_before(t)
Enable the filter only before the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) before which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_between
enable_between(start, end)
Enable the filter only between the given start and end times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
float
|
Start time (in seconds). |
required |
end
|
float
|
End time (in seconds). |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
f_expression
staticmethod
f_expression(expr)
Returns an FFmpeg drawtext expansion string that evaluate expression.
f_frame_num
staticmethod
f_frame_num()
Returns an FFmpeg drawtext expansion string that expands to the local time with given strftime format.
f_gmtime
staticmethod
f_gmtime(fmt='%a %b %d %Y')
Returns an FFmpeg drawtext expansion string that expands to the local time with given strftime format.
f_localtime
staticmethod
f_localtime(fmt='%a %b %d %Y')
Returns an FFmpeg drawtext expansion string that expands to the local time with given strftime format.
f_pts
staticmethod
f_pts(fmt='flt', offset=None, extra=None)
Returns an FFmpeg drawtext expansion string that expands to the PTS (presentation timestamp).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fmt
|
Literal['flt', 'hms', 'gmtime', 'localtime']
|
Format of the timestamp. - "flt" -> seconds with microsecond precision (default) - "hms" -> [-]HH:MM:SS.mmm - "gmtime" -> UTC timestamp (strftime supported if extra is given) - "localtime" -> local timestamp (strftime supported if extra is given) |
'flt'
|
offset
|
Optional[str]
|
Offset to add to timestamp (e.g., "10" for +10s). |
None
|
extra
|
Optional[str]
|
Optional third argument: - for "hms" format: "24HH" - for gmtime/localtime: strftime format string. |
None
|
Examples:
f_pts() -> "%{pts}" f_pts("hms") -> "%{pts:hms}" f_pts("hms", "5") -> "%{pts:hms:5}" f_pts("localtime", "0", "%H\:%M\:%S") -> "%{pts:localtime:0:%H\:%M\:%S}"
Box
Box(x, y, width, height, color='red', t=5, replace=False)
Bases: BaseFilter
, TimelineEditingMixin
enable_after
enable_after(t)
Enable the filter only after the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) after which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_before
enable_before(t)
Enable the filter only before the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) before which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_between
enable_between(start, end)
Enable the filter only between the given start and end times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
float
|
Start time (in seconds). |
required |
end
|
float
|
End time (in seconds). |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
Split
Split(n)
Bases: BaseFilter
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
XFade
XFade(name, offset=0, duration=1, expression=None)
Bases: BaseFilter
Combine two videos with transition.
Note
Requires same size and fps and aspect ratio.
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
Subtitles
Subtitles(filename, width=None, height=None, fontsdir=None, alpha=None, charenc=None, stream_index=None, force_style=None, wrap_unicode=None)
Bases: BaseFilter
Draw subtitles on top of input video using the libass library.
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
Overlay
Overlay(overlay_input, x, y)
Bases: BaseFilter
, TimelineEditingMixin
Represents an overlay filter that combines two video streams.
enable_after
enable_after(t)
Enable the filter only after the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) after which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_before
enable_before(t)
Enable the filter only before the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) before which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_between
enable_between(start, end)
Enable the filter only between the given start and end times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
float
|
Start time (in seconds). |
required |
end
|
float
|
End time (in seconds). |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
Concat
Concat(nodes)
Bases: BaseFilter
Represents an overlay filter that combines streams.
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
Scale
Scale(width, height, **kwargs)
Bases: BaseFilter
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
SetTimeBase
SetTimeBase(expression='AVTB')
Bases: BaseFilter
, TimelineEditingMixin
enable_after
enable_after(t)
Enable the filter only after the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) after which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_before
enable_before(t)
Enable the filter only before the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) before which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_between
enable_between(start, end)
Enable the filter only between the given start and end times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
float
|
Start time (in seconds). |
required |
end
|
float
|
End time (in seconds). |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
SetSampleAspectRatio
SetSampleAspectRatio(expression='1')
Bases: BaseFilter
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |
TimelineEditingMixin
Mixin providing timeline-based activation control for FFmpeg filter graphs.
This mixin allows enabling filters conditionally based on the video timestamp,
using FFmpeg's enable
expression mechanism with between
, gte
, and lte
.
Attributes:
Name | Type | Description |
---|---|---|
flags |
dict
|
Dictionary storing FFmpeg filter options, such as enable expressions. |
enable_after
enable_after(t)
Enable the filter only after the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) after which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_before
enable_before(t)
Enable the filter only before the given timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
float
|
Time (in seconds) before which the filter is enabled. |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
enable_between
enable_between(start, end)
Enable the filter only between the given start and end times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
float
|
Start time (in seconds). |
required |
end
|
float
|
End time (in seconds). |
required |
Returns:
Name | Type | Description |
---|---|---|
TimelineEditingMixin |
Self
|
The current instance with the updated |
BaseFilter
BaseFilter(filter_name)
Base class for all FFmpeg filters.
escape_arguments
escape_arguments(text)
Escapes all characters that require escaping in FFmpeg filter arguments.
Returns:
Type | Description |
---|---|
OptionalStr
|
None if text was None otherwise new str with escaped chars |