clip 子段精确去重
更新时间:2026-11-23
简介
判断新 clip 是否与已有数据 100% 重复:新 clip 的逐帧指纹序列是某个已有 clip 的连续子段(含完全一致)即判重。在 GPU 上匹配,结果精确。
功能描述
- 「已有」包括持久化指纹库(
library_dir)和本批中更长的 clip update_library=True时把本批非重复 clip 追加进库- 可传起止帧,按帧区间切出 clip 再判重
- 全局算子:需
concurrency=1, batch_size=None,Ray 上先into_partitions(1);总行数超过 131072 时调大default_morsel_size
算子参数
输入
| 输入 | 含义 |
|---|---|
| clip_ids | clip 唯一标识 |
| fingerprints | 视频 / MCAP 逐帧精确指纹的输出 |
| start_frames(可选) | 起始帧(含) |
| end_frames(可选) | 结束帧(不含) |
输出
struct 列:
| 输出 | 含义 |
|---|---|
| is_duplicate | 是否重复 |
| duplicate_of | 被包含于哪个 clip |
| duplicate_source | library / batch |
| match_offset | 在 duplicate_of 中的起始帧 |
| match_kind | identical / subsegment |
| num_frames | clip 帧数 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| library_dir | str | "" | 指纹库目录(本地或 PFS);空则只做批内去重 |
| update_library | bool | False | 是否把本批非重复 clip 追加进库 |
| device | str | "auto" | auto / cuda / cpu |
| verify_chunk_frames | int | 134217728 | 逐帧比较每轮帧数上限 |
| max_frames_per_pass | int | 600000000 | 一次放进显存匹配的帧数上限 |
| fail_on_error | bool | False | 出错是否抛异常 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.cluster.clip_subsegment_dedup import ClipSubsegmentDedup
10from daft.aihc.functions.video.video_frame_fingerprint import VideoFrameFingerprint
11
12if __name__ == "__main__":
13 if os.getenv("DAFT_RUNNER", "native") == "ray":
14 import ray
15 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
16 daft.set_runner_ray()
17 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
18
19videos = ["/path/to/a.mp4", "/path/to/a_copy.mkv", "/path/to/a_cut.mp4", "/path/to/b.mp4"]
20 ds = daft.from_pydict({"clip_id": [os.path.basename(v) for v in videos], "video": videos})
21 ds = ds.with_column(
22 "fp",
23 aihc_udf(
24 VideoFrameFingerprint,
25 construct_args={"mode": "packet"},
26 num_cpus=1,
27 num_gpus=0,
28 concurrency=1,
29 batch_size=8,
30 )(col("video")),
31 )
32 ds = ds.into_partitions(1)
33 ds = ds.with_column(
34 "dedup",
35 aihc_udf(
36 ClipSubsegmentDedup,
37 construct_args={"library_dir": "/path/to/fp_library", "update_library": True},
38 num_cpus=4,
39 num_gpus=1,
40 concurrency=1,
41 batch_size=None,
42 )(col("clip_id"), col("fp")),
43 )
44 ds.select(
45 col("clip_id"),
46 col("dedup")["is_duplicate"],
47 col("dedup")["duplicate_of"],
48 col("dedup")["match_kind"],
49 col("dedup")["match_offset"],
50 ).show()
评价此篇文章
