Skip to main content

Drama Fingerprint

输入第一集视频,提取最多 24 个帧指纹,先通过内容 ID 精确查找,再通过帧指纹模糊匹配已有剧。 命中后保存对应关系;没有候选时,用本次内容 ID 创建新剧。

安装与运行

需要 Python 3.12+,并在系统中安装 FFmpeg 和 ffprobe。当前持久化使用 POSIX 文件锁,支持 macOS / Linux。

python -m pip install drama-fingerprint
drama-fingerprint '/绝对路径/第一集.mp4' --database data/registry.json --json

普通查询会创建新剧或学习已命中版本的对应关系。只查询、不修改登记内容:

drama-fingerprint '/绝对路径/第一集.mp4' --database data/registry.json --lookup-only --json

也可使用 python -m drama_fingerprint。省略 --json 输出简洁文本。

返回字段 含义
content_id 本次视频保留帧指纹序列生成的确定性 ID;空内容为 null
drama_id 最终归属的剧 ID;无法确定时为 null
match_method exact 精确命中、fuzzy 模糊命中,或 null
sampled_frames 本次保留的帧指纹数,最多 24
computed_hashes 实际计算的指纹数量,含临时时间搜索,可能大于 24

退出码:0 表示匹配或创建成功;1 表示只读查询无匹配;2 表示歧义、内容不足或 CLI 参数错误,检查 JSON 的 status 或错误输出区分。--lookup-only 不改变登记记录,但仍会创建目录和锁文件。

识别流程

  1. 在开头最多 120 秒内均匀取样,跳过黑白屏等低信息画面,重复画面只保留一张;不足时按整秒补选,最多保留 24 帧。
  2. 固定缩放、裁剪和中央遮罩,每帧计算 256 位 PDQ 感知指纹。
  3. 按时间顺序序列化指纹与算法版本,用 SHA-256 生成 content_v1_…。路径、时间戳、时长和质量分不参与。
  4. 查参考内容 ID 和已保存的对应关系;唯一精确命中就返回已有剧 ID。
  5. 没有精确命中时,粗搜时间偏移,再局部细搜验证。唯一明确匹配后保存 内容 ID → 剧 ID。
  6. 没有任何候选时创建新剧;部分匹配、竞争候选或空内容不写入。有效剧情即使只剩一帧,也允许匹配或登记。

每部剧保留最初的参考指纹,额外版本只增加 ID 对应关系。相同指纹序列可以无状态计算同一内容 ID;不同画质、片头偏移等版本归到同一剧,仍需要参考库和对应关系。

数据库是 JSON,通过文件锁和原子替换保存。固定遮罩仅覆盖特定区域,不保证识别任意水印;变速、大面积遮挡和跨剧共享画面也不在已验证保证范围内。这是小规模本地实验实现,模糊搜索会逐部比较参考库。

Python 调用

from pathlib import Path
from drama_fingerprint import identify

result = identify(
    Path('/绝对路径/第一集.mp4'),
    Path('data/registry.json'),
)
print(result.content_id, result.drama_id, result.match_method)

只计算内容 ID,无需数据库:

from pathlib import Path
from drama_fingerprint.content import extract
from drama_fingerprint.registry import content_id

fingerprint = extract(Path('/绝对路径/第一集.mp4')).signature
print(content_id(fingerprint))

开发与验证

在源码目录中使用 uv 安装锁定的开发依赖:

uv sync --locked
uv run pytest -q
uv run mypy
uv build
  • src/drama_fingerprint/content.py:当前选帧、去重、补帧和局部时间搜索。
  • src/drama_fingerprint/registry.py:内容 ID、两级匹配与持久化。
  • src/drama_fingerprint/cli.py:命令参数和结果输出。
  • tests/:当前方案的行为测试,包括单帧、末尾空帧、内容 ID、已有登记库、命令行和并发写入。
  • docs/validation.md:验证基线和迁移范围。

fingerprint.py 保存基础模型和指纹距离计算;temporal.py 保存帧序列模型和时间对齐。库中 strategy: "content-search" 是固定存储格式标记,不是调用参数;已有当前方案登记库可直接使用。

修改取样、裁剪、遮罩、去重或 ID 序列化策略时,应明确内容 ID 的版本变化。运行数据放在 data/,本地检查产物放在 artifacts/,均不纳入 Git。

Metadata

Release files for drama-fingerprint 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drama-fingerprint 0.1.0
File Size Uploaded Provenance Actions
drama_fingerprint-0.1.0.tar.gz 63.4 kB Without provenance Details for drama_fingerprint-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drama-fingerprint 0.1.0
File Interpreter ABI Platform Actions
drama_fingerprint-0.1.0-py3-none-any.whl Python 3 none any Details for drama_fingerprint-0.1.0-py3-none-any.whl

Total release size: 75.4 kB

Release files / drama_fingerprint-0.1.0.tar.gz

Download URL drama_fingerprint-0.1.0.tar.gz
Size 63.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5d4b6f5aa6c07e91e07ad6fd758e8bd22550c34b480cbc1837b560b3b367b9b2
BLAKE2b-256 checksum
How to use checksums
b6e9431a75a4e9c3d4876f62f0d31fc7b87ea346e2002d370bcb5485ad1d3ac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / drama_fingerprint-0.1.0-py3-none-any.whl

Download URL drama_fingerprint-0.1.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6181238be4735ee04f24eb1718cf1b0933fe057bce645f0390131bf4e9a60d45
BLAKE2b-256 checksum
How to use checksums
694272afeb5fd09e24af47e6e73658a91c0ba2cb15d6f5500c04494ba8debdfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for drama-fingerprint 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page