VideoType.
View source on GitHub
UDFs
clip() udf
Extract a clip from a video, specified by start_time and either end_time or duration (in seconds).
If start_time is beyond the end of the video, returns None. Can only specify one of end_time and duration. If both end_time and duration are None, the clip goes to the end of the video.
Requirements:
ffmpegneeds to be installed and in PATH
video(Video): Input video filestart_time(Float): Start time in secondsend_time(Optional[Float]): End time in secondsduration(Optional[Float]): Duration of the clip in seconds
- Optional[Video]: New video containing only the specified time range or None if start_time is beyond the end of the video.
concat_videos() udf
Merge multiple videos into a single video.
Requirements:
ffmpegneeds to be installed and in PATH
videos(Json): List of videos to merge.
- Video: A new video containing the merged videos.
extract_audio() udf
Extract an audio stream from a video.
Signature:
stream_idx(Int): Index of the audio stream to extract.format(String): The target audio format. ('wav','mp3','flac').codec(Optional[String]): The codec to use for the audio stream. If not provided, a default codec will be used.
- Audio: The extracted audio.
tbl that extracts audio from an existing column video_col:
extract_frame() udf
Extract a single frame from a video at a specific timestamp.
Signature:
video(Video): The video from which to extract the frame.timestamp(Float): Extract frame at this timestamp (in seconds).
- Optional[Image]: The extracted frame as a PIL Image, or None if the timestamp is beyond the video duration.
video column of the table tbl:
video column of the table tbl:
get_duration() udf
Get video duration in seconds.
Signature:
video(Video): The video for which to get the duration.
- Optional[Float]: The duration in seconds, or None if the duration cannot be determined.
get_metadata() udf
Gets various metadata associated with a video file and returns it as a dictionary.
Signature:
video(Video): The video for which to get metadata.
- Json: A
dictsuch as the following:
video_col column of the table tbl:
overlay_text() udf
Overlay text on a video with customizable positioning and styling.
Requirements:
ffmpegneeds to be installed and in PATH
video(Video): Input video to overlay text on.text(String): The text string to overlay on the video.font(Optional[String]): Font family or path to font file. If None, uses the system default.font_size(Int): Size of the text in points.color(String): Text color (e.g.,'white','red','#FF0000').opacity(Float): Text opacity from 0.0 (transparent) to 1.0 (opaque).horizontal_align(String): Horizontal text alignment ('left','center','right').horizontal_margin(Int): Horizontal margin in pixels from the alignment edge.vertical_align(String): Vertical text alignment ('top','center','bottom').vertical_margin(Int): Vertical margin in pixels from the alignment edge.box(Bool): Whether to draw a background box behind the text.box_color(String): Background box color as a string.box_opacity(Float): Background box opacity from 0.0 to 1.0.box_border(Optional[Json]): Padding around text in the box in pixels.[10]: 10 pixels on all sides[10, 20]: 10 pixels on top/bottom, 20 on left/right[10, 20, 30]: 10 pixels on top, 20 on left/right, 30 on bottom[10, 20, 30, 40]: 10 pixels on top, 20 on right, 30 on bottom, 40 on left
- Video: A new video with the text overlay applied.
segment_video() udf
Split a video into segments.
Requirements:
ffmpegneeds to be installed and in PATH
video(Video): Input video file to segmentduration(Optional[Float]): Duration of each segment (in seconds). Formode='fast', this is approximate; formode='accurate', segments will have exact durations. Cannot be specified together withsegment_times.segment_times(Optional[Json]): List of timestamps (in seconds) in video where segments should be split. Note that these are not segment durations. If all segment times are less than the duration of the video, produces exactlylen(segment_times) + 1segments. Cannot be empty or be specified together withduration.mode(String): Segmentation mode:'fast': Quick segmentation using stream copy (splits only at keyframes, approximate durations)'accurate': Precise segmentation with re-encoding (exact durations, slower)
video_encoder(Optional[String]): Video encoder to use. If not specified, uses the default encoder for the current platform. Only available formode='accurate'.video_encoder_args(Optional[Json]): Additional arguments to pass to the video encoder. Only available formode='accurate'.
- Json: List of file paths for the generated video segments.
with_audio() udf
Creates a new video that combines the video stream from video and the audio stream from audio.
The start_time and duration parameters can be used to select a specific time range from each input. If the audio input (or selected time range) is longer than the video, the audio will be truncated.
Requirements:
ffmpegneeds to be installed and in PATH
video(Video): Input video.audio(Audio): Input audio.video_start_time(Float): Start time in the video input (in seconds).video_duration(Optional[Float]): Duration of video segment (in seconds). If None, uses the remainder of the video aftervideo_start_time.video_durationdetermines the duration of the output video.audio_start_time(Float): Start time in the audio input (in seconds).audio_duration(Optional[Float]): Duration of audio segment (in seconds). If None, uses the remainder of the audio afteraudio_start_time. If the audio is longer than the output video, it will be truncated.
- Video: A new video file with the audio track added.