Skip to content

Inputs

VideoFile

VideoFile(filepath)

Bases: BaseInput

A class representing a video file that can be processed with FFmpeg.

This class provides methods for interacting with a video file, such as building FFmpeg input flags, extracting streams (audio, video, subtitles), creating subclips, and retrieving the video file's resolution.

Initializes the VideoFile object with the specified file path.

Parameters:

Name Type Description Default
filepath str

The path to the video file to be processed.

required

audio property

audio

Access the audio stream of the video file.

Returns:

Name Type Description
StreamSpecifier StreamSpecifier

A StreamSpecifier object for the audio stream.

subtitle property

subtitle

Access the subtitle stream of the video file.

Returns:

Name Type Description
StreamSpecifier StreamSpecifier

A StreamSpecifier object for the subtitle stream.

video property

video

Access the video stream of the video file.

Returns:

Type Description
StreamSpecifier

StreamSpecifier

__getitem__

__getitem__(index)

Get stream from video by index

build_input_flags

build_input_flags()

Builds the FFmpeg input flags for the video file.

This method constructs the FFmpeg command line input flags to specify the video file to be processed.

Returns:

Type Description
list[str]

list[str]: A list of input flags for FFmpeg, including the file path.

from_imagefile classmethod

from_imagefile(imgpath, duration, fps)

Creates a VideoFile object from an image file, looping it for the given duration and setting the frame rate.

Parameters:

Name Type Description Default
imgpath str

The path to the image file to use as a video.

required
duration float

The duration of the video in seconds.

required
fps int

The frame rate of the video.

required

Returns:

Name Type Description
VideoFile VideoFile

A VideoFile object created from the image file.

get_size

get_size()

Retrieves the resolution (width and height) of the video file.

Uses FFprobe to extract the width and height of the first video stream in the video file.

Returns:

Type Description
tuple[int, int]

tuple[int, int]: A tuple containing the width and height of the video.

get_stream

get_stream(stream_index, stream_name=None)

Get a specific stream from the video file by index and/or stream name.

Note

This function will not validate if stream exists.

Example

You get 2nd audio stream from video like this.

clip.get_stream(stream_index=1,stream_name="a")

Parameters:

Name Type Description Default
stream_index int

The index of the stream (e.g., 0 for the first stream).

required
stream_name Optional[Literal['a', 'v', 's', 'd', 't', 'V']]

The name of the stream to retrieve - a -> audio - v -> video - s -> subtitles - d -> data - t -> attachments - V -> video but excludes thumbnails/attached pics If not provided, retrieves the stream by index.

None

Returns:

Name Type Description
StreamSpecifier StreamSpecifier

A StreamSpecifier object for the requested stream.

subclip

subclip(start, end)

Defines a subclip from the video file by setting the start and end times. This will not make a new copy until exported.

Parameters:

Name Type Description Default
start float

The start time of the subclip in seconds.

required
end float

The end time of the subclip in seconds.

required

Returns:

Name Type Description
VideoFile VideoFile

The updated VideoFile object with the subclip flags set.

ImageFile

ImageFile(filepath)

Bases: BaseInput

A class representing a Image file that can be processed with FFmpeg.

This class provides methods for interacting with a Image file, such as building FFmpeg input flags

Initializes the ImageFile object with the specified file path.

Parameters:

Name Type Description Default
filepath str

The path to the image file to be processed.

required

build_input_flags

build_input_flags()

Builds the FFmpeg input flags for the video file.

This method constructs the FFmpeg command line input flags to specify the video file to be processed.

Returns:

Type Description
list[str]

list[str]: A list of input flags for FFmpeg, including the file path.

get_size

get_size()

Retrieves the resolution (width and height) of the image file.

Uses FFprobe to extract the width and height of the first image stream in the image file.

Returns:

Type Description
tuple[int, int]

tuple[int, int]: A tuple containing the width and height of the image.

AudioFile

AudioFile(filepath)

Bases: BaseInput

A class representing a Audio file that can be processed with FFmpeg.

This class provides methods for interacting with a Audio file, such as building FFmpeg input flags

Initializes the AudioFile object with the specified file path.

Parameters:

Name Type Description Default
filepath str

The path to the audio file to be processed.

required

build_input_flags

build_input_flags()

Builds the FFmpeg input flags for the video file.

This method constructs the FFmpeg command line input flags to specify the video file to be processed.

Returns:

Type Description
list[str]

list[str]: A list of input flags for FFmpeg, including the file path.

get_duration

get_duration()

Retrieves the duration of the audio file.

Uses FFprobe to extract the width and height of the first audio stream in the audio file.

Returns:

Name Type Description
float float

duration in seconds.

probe

probe()

Retrieves the duration of the audio file.

Uses FFprobe to extract the stats of the in the audio file.

Returns:

Name Type Description
dict dict

with all data from ffprobe.

subclip

subclip(start, end)

Defines a subclip from the Audio file by setting the start and end times. This will not make a new copy until exported.

Parameters:

Name Type Description Default
start float

The start time of the subclip in seconds.

required
end float

The end time of the subclip in seconds.

required

Returns:

Name Type Description
AudioFile AudioFile

The updated AudioFile object with the subclip flags set.

InputFile

InputFile(filepath, options=None, **kwargs)

Bases: BaseInput

General Input for FFMPEG backend You can use custom flags

VirtualVideo

VirtualVideo(name, format='lavfi', flags=None, **kwargs)

Bases: BaseVirtualInput

ssdsad

build_input_flags

build_input_flags()

Builds the FFmpeg input flags for the video file.

This method constructs the FFmpeg command line input flags to specify the video file to be processed.

Returns:

Type Description
list[str]

list[str]: A list of input flags for FFmpeg, including the file path.

from_cellauto classmethod

from_cellauto(width, height, pattern=None, rate=None, random_fill_ratio=None, random_seed=None, rule=None, scroll=None, start_full=None, stitch=None)

Create a pattern generated by an elementary cellular automaton. The initial state of the cellular automaton can be defined through the filename and pattern options. If such options are not specified an initial state is created randomly. At each new frame a new row in the video is filled with the result of the cellular automaton next generation. The behavior when the whole frame is filled is defined by the scroll option.

https://ffmpeg.org/ffmpeg-filters.html#cellauto

from_ddagrab classmethod

from_ddagrab(output_idx, draw_mouse=None, framerate=None, rate=25, sar=None, preset=None, seed=None)
output_idx        <int>        ..FV....... dda output index to capture (from 0 to INT_MAX) (default 0)

draw_mouse ..FV....... draw the mouse pointer (default true) framerate ..FV....... set video frame rate (default "30") video_size ..FV....... set video frame size offset_x ..FV....... capture area x offset (from INT_MIN to INT_MAX) (default 0) offset_y ..FV....... capture area y offset (from INT_MIN to INT_MAX) (default 0) output_fmt ..FV....... desired output format (from 0 to INT_MAX) (default 8bit) auto 0 ..FV....... let dda pick its preferred format 8bit 87 ..FV....... only output default 8 Bit format bgra 87 ..FV....... only output 8 Bit BGRA 10bit 24 ..FV....... only output default 10 Bit format x2bgr10 24 ..FV....... only output 10 Bit X2BGR10 16bit 10 ..FV....... only output default 16 Bit format rgbaf16 10 ..FV....... only output 16 Bit RGBAF16 allow_fallback ..FV....... don't error on fallback to default 8 Bit format (default false) force_fmt ..FV....... exclude BGRA from format list (experimental, discouraged by Microsoft) (default false)

from_gradients classmethod

from_gradients(height, width, duration=None, rate=None, c0=None, c1=None, c2=None, c3=None, c4=None, c5=None, c6=None, c7=None, x0=None, y0=None, x1=None, y1=None, nb_colors=None, seed=None, speed=None, type=None)

Generate several animated gradients.

https://ffmpeg.org/ffmpeg-filters.html#gradients

from_mandelbrot classmethod

from_mandelbrot(width=640, height=480, rate=None, end_pts=None, end_scale=None, inner=None, bailout=None, maxiter=None, outer=None, start_scale=None, start_x=None, start_y=None)

Generate a Mandelbrot set fractal with zoom animation.

https://ffmpeg.org/ffmpeg-filters.html#mandelbrot

from_testsrc classmethod

from_testsrc(width, height, duration=None, rate=25, sar=None, decimals=None)

size : set video size (default "320x240") rate : set video rate (default "25") duration : set video duration (default -0.000001) sar : set video sample aspect ratio (from 0 to INT_MAX) (default 1/1) decimals : set number of decimals to show (from 0 to 17) (default 0)

get_size

get_size()

Retrieves the resolution (width and height).

Returns:

Type Description
tuple[int, int]

tuple[int, int]: A tuple containing the width and height of the video.

FileInputOptions

FileInputOptions(duration=None, start_time=None, format=None, codec=None, frame_rate=None, video_size=None, pixel_format=None, sample_rate=None, audio_channels=None, thread_queue_size=None, itsoffset=None, itsoverride=None, analyzeduration=None, probesize=None, rtbufsize=None, re=None, accurate_seek=None, discard=None, vsync=None, async_audio=None, fps_mode=None, loop=None)

Bases: BaseOptions

Represents input options for FFmpeg's -i flag.

This class allows users to specify various input-related parameters for FFmpeg command generation.

Note

The types for flags like duration are int but ffmpeg can accept multiple formats. see ffmpeg

Example usage:

options = InputOptions(duration=10, start_time="00:00:05", format="mp4", frame_rate=30)

add_flags

add_flags(key, value)

Add other FFMPEG flags

StreamSpecifier

StreamSpecifier(parent, output_index=0, stream_index=None, stream_name=None, codec_type=None, metadata=None)

Used specify in ffmpeg command

ffmpeg docs : https://ffmpeg.org/ffmpeg.html#toc-Automatic-stream-selection