vikit.wrappers.ffmpeg_wrapper

Overview

Function

concatenate_videos(video_file_paths, target_file_name, ratio_to_multiply_animations)

Concatenate multiple videos into a single video.

convert_as_mp3_file(fileName, target_file_name)

Save the incoming audio file to a regular mp3 file with a standardized filename

create_zoom_video(image_url, target_duration, target_video_name)

Creates a video zooming into an image for a certain duration

cut_video(video_url, start_time, end_time, target_duration, target_video_name)

Cuts the video starting at start_time and ending at end_time

extract_audio_from_video(video_full_path, target_dir)

Extract all audio tracks from a video and output them as separate files.

extract_audio_slice(audiofile_path, start, end, target_file_name)

Extract a slice of the audio file using ffmpeg

generate_video_from_image(image_url, duration, dimensions, target_path)

Generates a video from an image

get_first_frame_as_image_ffmpeg(media_url, target_path)

Get the first frame of the video

get_last_frame_as_image_ffmpeg(media_url, target_path)

Get the last frame of the video

get_media_duration(input_video_path)

Get the duration of a media file.

get_media_fps(input_video_path)

Get the frames per second of a media file.

has_audio_track(video_path)

Check if the video has an audio track

merge_audio(media_url, audio_file_path, audio_file_relative_volume, target_file_name)

Merge audio with the video

reencode_video(video_url, target_video_name, fps)

Reencode the video, doing this for imported video that might not concatenate well

reverse_video(video_url, target_video_name)

Reverses the frames of the video, with last frame being the first, second to last

Functions

async vikit.wrappers.ffmpeg_wrapper.concatenate_videos(video_file_paths: list[str], target_file_name: str = None, ratio_to_multiply_animations: float = 1) str

Concatenate multiple videos into a single video.

Parameters:
  • video_file_paths -- The file paths to the videos to concatenate. Must contain at least 1 path and all videos must have the same FPS.

  • target_file_name -- The target file of the video file to create. Default: TargetCompositeVideo.mp4

  • ratioToMultiplyAnimations -- The ratio by which to speed up or slow down the video to match its duration to an expected duration, e.g. of an audio track.

Returns:

The path to the concatenated video file

Return type:

str

Raises:
  • ValueError -- If video_file_paths is empty or the videos don’t have the same FPS.

  • FileNotFoundError -- If any of the video files does not exist.

async vikit.wrappers.ffmpeg_wrapper.convert_as_mp3_file(fileName, target_file_name: str)

Save the incoming audio file to a regular mp3 file with a standardized filename

Parameters:

fileName (str) -- The path to the audio file to convert

Returns:

The path to the converted audio file

Return type:

str

async vikit.wrappers.ffmpeg_wrapper.create_zoom_video(image_url, target_duration=3, target_video_name=None)

Creates a video zooming into an image for a certain duration :param image_url: The image url to zoom in :type image_url: str :param target_duration: Optional, the duration of the output video in seconds :type target_duration: float :param target_video_name: Optional, the name of the output video :type target_video_name: string

Returns:

The zoomed video

Return type:

Video

async vikit.wrappers.ffmpeg_wrapper.cut_video(video_url, start_time, end_time, target_duration=None, target_video_name=None)

Cuts the video starting at start_time and ending at end_time :param video_url: The video url to cut (eg ./videofolder/video.mp4) :type video_url: str :param start_time: The begining time of the video in seconds :type start_time: float :param end_time: The end time of the video in seconds :type end_time: float :param target_duration: Optional, the duration of the output video in seconds :type target_duration: float :param target_video_name: Optional, the name of the output video in seconds :type target_video_name: string

Returns:

The reencoded video

Return type:

Video

async vikit.wrappers.ffmpeg_wrapper.extract_audio_from_video(video_full_path, target_dir: str = None) str

Extract all audio tracks from a video and output them as separate files. Naive implementation:

  • we do not check the existence of audio stream,

  • we do not check the pre-existence of the output file,

Parameters:
  • video_full_path (str) -- Full path of the input video file.

  • target_dir -- Directory where to store audio file

Returns:

The output audio file path

async vikit.wrappers.ffmpeg_wrapper.extract_audio_slice(audiofile_path: str, start: float = 0, end: float = 1, target_file_name: str = None)

Extract a slice of the audio file using ffmpeg

Parameters:
  • start (int) -- The start of the slice

  • end (int) -- The end of the slice

  • audiofile_path (str) -- The path to the audio file

  • target_file_name -- the target file name

Returns:

The path to the extracted audio slice

Return type:

str

async vikit.wrappers.ffmpeg_wrapper.generate_video_from_image(image_url, duration=5, dimensions=(1280, 720), target_path=None)

Generates a video from an image

async vikit.wrappers.ffmpeg_wrapper.get_first_frame_as_image_ffmpeg(media_url, target_path=None)

Get the first frame of the video

async vikit.wrappers.ffmpeg_wrapper.get_last_frame_as_image_ffmpeg(media_url, target_path=None)

Get the last frame of the video

vikit.wrappers.ffmpeg_wrapper.get_media_duration(input_video_path)

Get the duration of a media file.

Parameters:

input_video_path (str) -- The path to the input video file.

Returns:

The duration of the media file in seconds.

Return type:

float

vikit.wrappers.ffmpeg_wrapper.get_media_fps(input_video_path)

Get the frames per second of a media file.

Parameters:

input_video_path (str) -- The path to the input video file.

Returns:

The FPS of the media file in frames per seconds.

Return type:

float

vikit.wrappers.ffmpeg_wrapper.has_audio_track(video_path)

Check if the video has an audio track

Parameters:

video_path (str) -- The path to the video file

Returns:

True if the video has an audio track, False otherwise

Return type:

bool

async vikit.wrappers.ffmpeg_wrapper.merge_audio(media_url: str, audio_file_path: str, audio_file_relative_volume: float | None = None, target_file_name=None)

Merge audio with the video

Parameters:
  • media_url (str) -- The media url to merge

  • audio_file_path (str) -- The audio file path to merge

  • audio_file_relative_volume (float) -- The relative volume of the audio file

  • target_file_name (str) -- The target file name

Returns:

The merged audio file path

Return type:

str

async vikit.wrappers.ffmpeg_wrapper.reencode_video(video_url, target_video_name=None, fps=24)

Reencode the video, doing this for imported video that might not concatenate well with generated ones or among themselves

Parameters:
  • video_url (str) -- The video url to reencode

  • target_video_name (str) -- The target video name

Returns:

The reencoded video

Return type:

Video

async vikit.wrappers.ffmpeg_wrapper.reverse_video(video_url, target_video_name=None)

Reverses the frames of the video, with last frame being the first, second to last the second etc… and first frame the latest one :param video_url: The video to reverse :type video_url: str :param target_video_name: Optional, the name of the output video :type target_video_name: string

Returns:

The reversed video

Return type:

Video