vikit.wrappers.ffmpeg_wrapper ============================= .. py:module:: vikit.wrappers.ffmpeg_wrapper Overview -------- .. list-table:: Function :header-rows: 0 :widths: auto :class: summarytable * - :py:obj:`concatenate_videos `\ (video_file_paths, target_file_name, ratio_to_multiply_animations) - Concatenate multiple videos into a single video. * - :py:obj:`convert_as_mp3_file `\ (fileName, target_file_name) - Save the incoming audio file to a regular mp3 file with a standardized filename * - :py:obj:`create_zoom_video `\ (image_url, target_duration, target_video_name) - Creates a video zooming into an image for a certain duration * - :py:obj:`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 * - :py:obj:`extract_audio_from_video `\ (video_full_path, target_dir) - Extract all audio tracks from a video and output them as separate files. * - :py:obj:`extract_audio_slice `\ (audiofile_path, start, end, target_file_name) - Extract a slice of the audio file using ffmpeg * - :py:obj:`generate_video_from_image `\ (image_url, duration, dimensions, target_path) - Generates a video from an image * - :py:obj:`get_first_frame_as_image_ffmpeg `\ (media_url, target_path) - Get the first frame of the video * - :py:obj:`get_last_frame_as_image_ffmpeg `\ (media_url, target_path) - Get the last frame of the video * - :py:obj:`get_media_duration `\ (input_video_path) - Get the duration of a media file. * - :py:obj:`get_media_fps `\ (input_video_path) - Get the frames per second of a media file. * - :py:obj:`has_audio_track `\ (video_path) - Check if the video has an audio track * - :py:obj:`merge_audio `\ (media_url, audio_file_path, audio_file_relative_volume, target_file_name) - Merge audio with the video * - :py:obj:`reencode_video `\ (video_url, target_video_name, fps) - Reencode the video, doing this for imported video that might not concatenate well * - :py:obj:`reverse_video `\ (video_url, target_video_name) - Reverses the frames of the video, with last frame being the first, second to last Functions --------- .. py:function:: concatenate_videos(video_file_paths: list[str], target_file_name: str = None, ratio_to_multiply_animations: float = 1) -> str :async: Concatenate multiple videos into a single video. :param 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. :param target_file_name: The target file of the video file to create. Default: TargetCompositeVideo.mp4 :param 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 :rtype: str :raises ValueError: If video_file_paths is empty or the videos don't have the same FPS. :raises FileNotFoundError: If any of the video files does not exist. .. py:function:: convert_as_mp3_file(fileName, target_file_name: str) :async: Save the incoming audio file to a regular mp3 file with a standardized filename :param fileName: The path to the audio file to convert :type fileName: str :returns: The path to the converted audio file :rtype: str .. py:function:: create_zoom_video(image_url, target_duration=3, target_video_name=None) :async: 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 :rtype: Video .. py:function:: cut_video(video_url, start_time, end_time, target_duration=None, target_video_name=None) :async: 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 :rtype: Video .. py:function:: extract_audio_from_video(video_full_path, target_dir: str = None) -> str :async: 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, :param video_full_path: Full path of the input video file. :type video_full_path: str :param target_dir: Directory where to store audio file :returns: The output audio file path .. py:function:: extract_audio_slice(audiofile_path: str, start: float = 0, end: float = 1, target_file_name: str = None) :async: Extract a slice of the audio file using ffmpeg :param start: The start of the slice :type start: int :param end: The end of the slice :type end: int :param audiofile_path: The path to the audio file :type audiofile_path: str :param target_file_name: the target file name :returns: The path to the extracted audio slice :rtype: str .. py:function:: generate_video_from_image(image_url, duration=5, dimensions=(1280, 720), target_path=None) :async: Generates a video from an image .. py:function:: get_first_frame_as_image_ffmpeg(media_url, target_path=None) :async: Get the first frame of the video .. py:function:: get_last_frame_as_image_ffmpeg(media_url, target_path=None) :async: Get the last frame of the video .. py:function:: get_media_duration(input_video_path) Get the duration of a media file. :param input_video_path: The path to the input video file. :type input_video_path: str :returns: The duration of the media file in seconds. :rtype: float .. py:function:: get_media_fps(input_video_path) Get the frames per second of a media file. :param input_video_path: The path to the input video file. :type input_video_path: str :returns: The FPS of the media file in frames per seconds. :rtype: float .. py:function:: has_audio_track(video_path) Check if the video has an audio track :param video_path: The path to the video file :type video_path: str :returns: True if the video has an audio track, False otherwise :rtype: bool .. py:function:: merge_audio(media_url: str, audio_file_path: str, audio_file_relative_volume: float | None = None, target_file_name=None) :async: Merge audio with the video :param media_url: The media url to merge :type media_url: str :param audio_file_path: The audio file path to merge :type audio_file_path: str :param audio_file_relative_volume: The relative volume of the audio file :type audio_file_relative_volume: float :param target_file_name: The target file name :type target_file_name: str :returns: The merged audio file path :rtype: str .. py:function:: reencode_video(video_url, target_video_name=None, fps=24) :async: Reencode the video, doing this for imported video that might not concatenate well with generated ones or among themselves :param video_url: The video url to reencode :type video_url: str :param target_video_name: The target video name :type target_video_name: str :returns: The reencoded video :rtype: Video .. py:function:: reverse_video(video_url, target_video_name=None) :async: 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 :rtype: Video