video_split_by_scene_mapper

Splits videos into scene clips based on detected scene changes.

This operator uses a specified scene detector to identify and split video scenes. It supports three types of detectors: ContentDetector, ThresholdDetector, and AdaptiveDetector. The operator processes each video in the sample, detects scenes, and splits the video into individual clips. The minimum length of a scene can be set, and progress can be shown during processing. The resulting clips are saved in the specified directory or the same directory as the input files if no save directory is provided. The operator also updates the text field in the sample to reflect the new video clips. If a video does not contain any scenes, it remains unchanged.

根据检测到的场景变化将视频分割成场景片段。

此算子使用指定的场景检测器来识别并分割视频场景。它支持三种类型的检测器:ContentDetector、ThresholdDetector 和 AdaptiveDetector。该算子处理样本中的每个视频,检测场景,并将视频分割成单独的片段。可以设置场景的最小长度,并在处理过程中显示进度。结果片段保存在指定目录中,如果没有提供保存目录,则保存在与输入文件相同的目录中。该算子还更新样本中的文本字段以反映新的视频片段。如果视频不包含任何场景,则保持不变。

Type 算子类型: mapper

Tags 标签: cpu, multimodal

🔧 Parameter Configuration 参数配置

name 参数名

type 类型

default 默认值

desc 说明

detector

<class ‘str’>

'ContentDetector'

Algorithm from scenedetect.detectors. Should be one

threshold

typing.Annotated[float, Ge(ge=0)]

27.0

Threshold passed to the detector.

min_scene_len

typing.Annotated[int, Ge(ge=0)]

15

Minimum length of any scene.

show_progress

<class ‘bool’>

False

Whether to show progress from scenedetect.

save_dir

<class ‘str’>

None

The directory where generated video files will be stored.

args

''

extra args

kwargs

''

extra args

📊 Effect demonstration 效果演示

test_ContentDetector

VideoSplitBySceneMapper(detector='ContentDetector', threshold=27.0, min_scene_len=15)

📥 input data 输入数据

Sample 1: 1 video
video1.mp4:
Sample 2: 1 video
video2.mp4:
Sample 3: 1 video
video3.mp4:

📤 output data 输出数据

Sample 1: empty
scene_num3
Sample 2: empty
scene_num1
Sample 3: empty
scene_num2

✨ explanation 解释

This example uses the ContentDetector to split videos into scenes. The operator splits each video into multiple clips based on detected scene changes, and the number of resulting scenes is counted. For instance, ‘video1.mp4’ is split into 3 scenes, ‘video2.mp4’ remains as a single scene, and ‘video3.mp4’ is split into 2 scenes. For clarity of presentation, the output data here shows the number of scenes per video, but the original output of the operator is the actual video clip. 这个例子使用了ContentDetector来将视频分割成场景。算子根据检测到的场景变化将每个视频分割成多个片段,并计算结果场景的数量。例如,’video1.mp4’被分割成3个场景,’video2.mp4’保持为一个场景,而’video3.mp4’被分割成2个场景。出于展示的清晰起见,此处输出数据显示每个视频的场景数量,但算子原始输出是实际的视频片段。

test_default_with_text

VideoSplitBySceneMapper()

📥 input data 输入数据

Sample 1: text | 1 video
<__dj__video> this is video1 <|__dj__eoc|>
video1.mp4:
Sample 2: text | 1 video
<__dj__video> this is video2 <|__dj__eoc|>
video2.mp4:
Sample 3: text | 1 video
<__dj__video> this is video3 <|__dj__eoc|>
video3.mp4:

📤 output data 输出数据

Sample 1: text
<__dj__video><__dj__video><__dj__video> this is video1 <|__dj__eoc|>
scene_num3
Sample 2: text
<__dj__video> this is video2 <|__dj__eoc|>
scene_num1
Sample 3: text
<__dj__video><__dj__video> this is video3 <|__dj__eoc|>
scene_num2

✨ explanation 解释

This example demonstrates the default behavior of the VideoSplitBySceneMapper, including updating the text field to reflect the new video clips. The operator splits each video into scenes and updates the text to include special tokens for each new video clip. For example, ‘video1.mp4’ is split into 3 scenes, so the text is updated to include three video tokens. Similarly, ‘video2.mp4’ remains as one scene, and ‘video3.mp4’ is split into 2 scenes, with the text updated accordingly. The output data shows the updated text and the number of scenes, but the actual raw output from the operator is the new video clips. 这个例子展示了VideoSplitBySceneMapper的默认行为,包括更新文本字段以反映新的视频片段。算子将每个视频分割成场景,并更新文本以包含每个新视频片段的特殊标记。例如,’video1.mp4’被分割成3个场景,因此文本被更新为包含三个视频标记。同样,’video2.mp4’保持为一个场景,而’video3.mp4’被分割成2个场景,文本也相应地进行了更新。输出数据显示了更新后的文本和场景数量,但算子的实际原始输出是新的视频片段。