Skip to content

Inputs

VideoFile

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.

audio property

audio

Access the audio stream of the video file.

subtitle property

subtitle

Access the subtitle stream of the video file.

Returns:

Type Description
StreamSpecifier

A StreamSpecifier object for the subtitle stream.

video property

video

Access the video stream of the video file.

__getitem__

__getitem__(index)

Get stream from video by index

__init__

__init__(filepath)

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

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:

Type Description
VideoFile

A VideoFile object created from the image file.

get_duration

get_duration()

Retrieves the duration of the video file.

Uses FFprobe to extract duration the first video stream in the video file.

Returns:

Type Description
float

Duration in seconds.

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:

Type Description
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:

Type Description
VideoFile

The updated VideoFile object with the subclip flags set.

ImageFile

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

__init__

__init__(filepath)

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

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]

A tuple containing the width and height of the image.

AudioFile

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

__init__

__init__(filepath)

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

get_duration

get_duration()

Retrieves the duration of the audio file.

Uses FFprobe to extract duration 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

Bases: BaseInput

General Input for FFMPEG backend You can use custom flags

VirtualVideo

Bases: BaseVirtualInput

Generate video with ffmpeg

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_color classmethod

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

Parameters:

Name Type Description Default
color

set color

required
duration Optional[float]

set video duration

None
rate

set video rate (default "25")

required
duration

set video duration (default -0.000001)

required
sar

set video sample aspect ratio (from 0 to INT_MAX) (default 1/1)

required
decimals

set number of decimals to show (from 0 to 17) (default 0)

required

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, duration=None, 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)

Parameters:

Name Type Description Default
rate

set video rate (default "25")

required
duration

set video duration (default -0.000001)

required
sar

set video sample aspect ratio (from 0 to INT_MAX) (default 1/1)

required
decimals

set number of decimals to show (from 0 to 17) (default 0)

required

FileInputOptions

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

Used specify in ffmpeg command

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