VideoType.
View source on GitHub
udf clip()
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(Float | None): End time in secondsduration(Float | None): Duration of the clip in secondsmode(String): -'fast': avoids re-encoding but starts the clip at the nearest keyframes and as a result, the clip duration will be slightly longer than requested'accurate': extracts a frame-accurate clip, but requires re-encoding
video_encoder(String | None): Video encoder to use. If not specified, uses the default encoder for the current platform. Only available formode='accurate'.video_encoder_args(Json | None): Additional arguments to pass to the video encoder. Only available formode='accurate'.
Video | None: New video containing only the specified time range or None if start_time is beyond the end of the video.
udf concat_videos()
ffmpegneeds to be installed and in PATH
videos(Json): List of videos to merge.
Video: A new video containing the merged videos.
udf extract_audio()
stream_idx(Int): Index of the audio stream to extract.format(String): The target audio format. ('wav','mp3','flac').codec(String | None): 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:
udf extract_frame()
video(Video): The video from which to extract the frame.timestamp(Float): Extract frame at this timestamp (in seconds).
Image | None: 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:
udf get_duration()
video(Video): The video for which to get the duration.
Float | None: The duration in seconds, or None if the duration cannot be determined.
udf get_metadata()
video(Video): The video for which to get metadata.
Json: Adictsuch as the following:
video_col column of the table tbl:
udf overlay_text()
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(String | None): 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(Json | None): 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.
udf scene_detect_adaptive()
pip install scenedetect
video(Video): The video to analyze for scene cuts.fps(Float | None): Number of frames to extract per second for analysis. If None or 0, analyzes all frames. Lower values process faster but may miss exact scene cuts.adaptive_threshold(Float): Threshold that the score ratio must exceed to trigger a new scene cut. Lower values will detect more scenes (more sensitive), higher values will detect fewer scenes.min_scene_len(Int): Once a cut is detected, this many frames must pass before a new one can be added to the scene list.window_width(Int): Size of window (number of frames) before and after each frame to average together in order to detect deviations from the mean. Must be at least 1.min_content_val(Float): Minimum threshold (float) that the content_val must exceed in order to register as a new scene. This is calculated the same way thatscene_detect_content()calculates frame score based on weights/luma_only/kernel_size.delta_hue(Float): Weight for hue component changes. Higher values make hue changes more important.delta_sat(Float): Weight for saturation component changes. Higher values make saturation changes more important.delta_lum(Float): Weight for luminance component changes. Higher values make brightness changes more important.delta_edges(Float): Weight for edge detection changes. Higher values make edge changes more important. Edge detection can help detect cuts in scenes with similar colors but different content.luma_only(Bool): If True, only analyzes changes in the luminance (brightness) channel of the video, ignoring color information. This can be faster and may work better for grayscale content.kernel_size(Int | None): Size of kernel to use for post edge detection filtering. If None, automatically set based on video resolution.
-
Json: A list of dictionaries, one for each detected scene, with the following keys:start_time(float): The start time of the scene in seconds.start_pts(int): The pts of the start of the scene.duration(float): The duration of the scene in seconds.
udf scene_detect_content()
pip install scenedetect
video(Video): The video to analyze for scene cuts.fps(Float | None): Number of frames to extract per second for analysis. If None, analyzes all frames. Lower values process faster but may miss exact scene cuts.threshold(Float): Threshold that the weighted sum of component changes must exceed to trigger a scene cut. Lower values detect more scenes (more sensitive), higher values detect fewer scenes.min_scene_len(Int): Once a cut is detected, this many frames must pass before a new one can be added to the scene list.delta_hue(Float): Weight for hue component changes. Higher values make hue changes more important.delta_sat(Float): Weight for saturation component changes. Higher values make saturation changes more important.delta_lum(Float): Weight for luminance component changes. Higher values make brightness changes more important.delta_edges(Float): Weight for edge detection changes. Higher values make edge changes more important. Edge detection can help detect cuts in scenes with similar colors but different content.luma_only(Bool): If True, only analyzes changes in the luminance (brightness) channel, ignoring color information. This can be faster and may work better for grayscale content.kernel_size(Int | None): Size of kernel for expanding detected edges. Must be odd integer greater than or equal to 3. If None, automatically set using video resolution.filter_mode(String): How to handle fast cuts/flashes. ‘merge’ combines quick cuts, ‘suppress’ filters them out.
-
Json: A list of dictionaries, one for each detected scene, with the following keys:start_time(float): The start time of the scene in seconds.start_pts(int): The pts of the start of the scene.duration(float): The duration of the scene in seconds.
udf scene_detect_hash()
pip install scenedetect
video(Video): The video to analyze for scene cuts.fps(Float | None): Number of frames to extract per second for analysis. If None, analyzes all frames. Lower values process faster but may miss exact scene cuts.threshold(Float): Value from 0.0 and 1.0 representing the relative hamming distance between the perceptual hashes of adjacent frames. A distance of 0 means the image is the same, and 1 means no correlation. Smaller threshold values thus require more correlation, making the detector more sensitive. The Hamming distance is divided by size x size before comparing to threshold for normalization. Lower values detect more scenes (more sensitive), higher values detect fewer scenes.size(Int): Size of square of low frequency data to use for the DCT. Larger values are more precise but slower. Common values are 8, 16, or 32.lowpass(Int): How much high frequency information to filter from the DCT. A value of 2 means keep lower 1/2 of the frequency data, 4 means only keep 1/4, etc. Larger values make the detector less sensitive to high-frequency details and noise.min_scene_len(Int): Once a cut is detected, this many frames must pass before a new one can be added to the scene list.
-
Json: A list of dictionaries, one for each detected scene, with the following keys:start_time(float): The start time of the scene in seconds.start_pts(int): The pts of the start of the scene.duration(float): The duration of the scene in seconds.
udf scene_detect_histogram()
pip install scenedetect
video(Video): The video to analyze for scene cuts.fps(Float | None): Number of frames to extract per second for analysis. If None or 0, analyzes all frames. Lower values process faster but may miss exact scene cuts.threshold(Float): Maximum relative difference between 0.0 and 1.0 that the histograms can differ. Histograms are calculated on the Y channel after converting the frame to YUV, and normalized based on the number of bins. Higher differences imply greater change in content, so larger threshold values are less sensitive to cuts. Lower values detect more scenes (more sensitive), higher values detect fewer scenes.bins(Int): Number of bins to use for histogram calculation (typically 16-256). More bins provide finer granularity but may be more sensitive to noise.min_scene_len(Int): Once a cut is detected, this many frames must pass before a new one can be added to the scene list.
-
Json: A list of dictionaries, one for each detected scene, with the following keys:start_time(float): The start time of the scene in seconds.start_pts(int): The pts of the start of the scene.duration(float): The duration of the scene in seconds.
udf scene_detect_threshold()
pip install scenedetect
video(Video): The video to analyze for fade transitions.fps(Float | None): Number of frames to extract per second for analysis. If None or 0, analyzes all frames. Lower values process faster but may miss exact transition points.threshold(Float): 8-bit intensity value that each pixel value (R, G, and B) must be <= to in order to trigger a fade in/out.min_scene_len(Int): Once a cut is detected, this many frames must pass before a new one can be added to the scene list.fade_bias(Float): Float between -1.0 and +1.0 representing the percentage of timecode skew for the start of a scene (-1.0 causing a cut at the fade-to-black, 0.0 in the middle, and +1.0 causing the cut to be right at the position where the threshold is passed).add_final_scene(Bool): Boolean indicating if the video ends on a fade-out to generate an additional scene at this timecode.method(String): How to treat threshold when detecting fade events- ‘ceiling’: Fade out happens when frame brightness rises above threshold.
- ‘floor’: Fade out happens when frame brightness falls below threshold.
-
Json: A list of dictionaries, one for each detected scene, with the following keys:start_time(float): The start time of the scene in seconds.start_pts(int): The pts of the start of the scene.duration(float): The duration of the scene in seconds.
udf segment_video()
ffmpegneeds to be installed and in PATH
video(Video): Input video file to segmentduration(Float | None): 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(Json | None): 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(String | None): Video encoder to use. If not specified, uses the default encoder for the current platform. Only available formode='accurate'.video_encoder_args(Json | None): Additional arguments to pass to the video encoder. Only available formode='accurate'.
Json: List of file paths for the generated video segments.
udf with_audio()
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(Float | None): 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(Float | None): 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.