VideoFileClip¶
classvidiopy.VideoFileClip(filename: str, audio: bool = True, ffmpeg_options: dict | None = None)
-
Bases:
vidiopy.VideoClipAll Methods and properties of the
VideoClipclass are available.A video clip originating from a Video file.
- Parameters:
-
filename: str
- The name of the video file, as a string or a path-like object. It can have any extension supported by ffmpeg.
All Sported extensions
- .mp4
- .avi
- .mov
- .mkv
- .webm
- .flv
- .wmv
- .3gp
- .ogg
- .ogv
- .mts
- .m2ts
- .ts
- .vob
- .mpg
- .mpeg
- .m2v
- .m4v
- .mxf
- .dv
- .f4v
- .gif
- .mp3
- .wav
- .flac
- .ogg
- .m4a
- .wma
- .aac
- .ac3
- .alac
- .aiff
- .amr
- .au
- .mka
- .mp2
- .mpa
- .opus
- .ra
- .tta
- .wv
- .weba
- .webm
- .webvtt
- .srt ETC.
audio: boolDefault:True- Set to
Falseif the clip doesn’t have any audio or if you do not wish to read the audio.
ffmpeg_options: dict | NoneDefault:None- A dictionary of options to be passed to ffmpeg when generating the clip’s audio. If
None, the default options will be used. If you want to pass options to the video part of the clip, you will have to use thevidiopy.VideoFileClip.set_make_framemethod.
- The name of the video file, as a string or a path-like object. It can have any extension supported by ffmpeg.
- Attributes:
-
clip:- The Numpy array of the clip’s video frames.
Read docs for
Clip()andVideoClip()for other, more generic, attributes.- Methods:
-
fl_frame_transform(self, func, *args, **kwargs) -> Self:-
Applies a function to each frame of the video clip.
This method iterates over each frame in the video clip, applies a function to it, and replaces the original frame with the result.
- Args:
func (callable): The function to apply to each frame. It should take an Image as its first argument, and return an Image.*args: Additional positional arguments to pass to func.**kwargs: Additional keyword arguments to pass to func.- Returns:
Self: Returns the instance of the class with updated frames.- Raises:
- None
- Example:
- Note:
- This method requires the start and end of the video clip to be set.
fl_clip_transform(self, func, *args, **kwargs) -> Self:-
Applies a function to each frame of the video clip along with its timestamp.
This method iterates over each frame in the video clip, applies a function to it and its timestamp, and replaces the original frame with the result.
- Args:
func (callable): The function to apply to each frame. It should take an Image and a float (representing the timestamp) as its first two arguments, and return an Image.*args: Additional positional arguments to pass to func.**kwargs: Additional keyword arguments to pass to func.- Returns:
Self: Returns the instance of the class with updated frames.- Raises:
- None
- Example:
- Note:
- This method requires the fps of the video clip to be set.
make_frame_array(self, t: int | float) -> np.ndarray:-
Generates a numpy array representation of a specific frame in the video clip.
This method calculates the index of the frame for a specific time, retrieves the frame from the video clip, and converts it to a numpy array.
- Args:
t (int | float): The time of the frame to convert.- Returns:
np.ndarray: The numpy array representation of the frame.- Raises:
ValueError: If the duration of the video clip is not set.- Example:
- Note:
- This method requires the duration of the video clip to be set.
make_frame_pil(self, t: int | float) -> Image.Image:-
Generates a PIL Image representation of a specific frame in the video clip.
This method calculates the index of the frame for a specific time, retrieves the frame from the video clip, and returns it as a PIL Image.
- Args:
t (int | float): The time of the frame to convert.- Returns:
Image.Image: The PIL Image representation of the frame.- Raises:
ValueError: If the duration of the video clip is not set.- Example:
- Note:
- This method requires the duration of the video clip to be set.
_import_video_clip(self, file_name: str, ffmpeg_options: dict | None = None) -> tuple:-
Imports a video clip from a file using ffmpeg.
This method reads a video file using ffmpeg, converts each frame to a PIL Image, and returns a tuple of the images and the fps of the video.
- Args:
file_name (str): The name of the video file to import.ffmpeg_options (dict | None, optional): Additional options to pass to ffmpeg. Defaults to None.- Returns:
tuple: A tuple of the frames as PIL Images and the fps of the video.- Raises:
- None
- Example:
- Note:
- This method uses ffmpeg to read the video file. It is a private method and not intended for external use.
-