Communitygithub.com

VideoDB

感知、理解并对视频和音频执行操作。支持从本地文件、URL、RTSP/直播流或桌面录屏摄入内容,提供实时上下文和可播放的流链接;提取帧、构建视觉/语义/时间索引、搜索关键时刻并自动剪辑;进行转码与标准化、时间线编辑、生成媒体资产,以及为直播流或桌面捕捉设置实时告警。

VideoDB 是什么?

VideoDB 是一款专为 AI 助手设计的技能,它为视频、直播流和桌面会话提供了“感知 + 记忆 + 行动”的全栈能力。该技能支持从本地文件、URL、YouTube 链接、RTSP 流以及桌面屏幕录制摄入内容,返回可播放的流媒体链接和实时上下文。在理解层面,VideoDB 可以提取帧,建立视觉、语义和时间索引,并通过时间戳和自动剪辑功能高效搜索视频中的关键时刻。在操作层面,它支持转码与标准化(编解码器、帧率、分辨率、宽高比)、时间线编辑(字幕生成与翻译、文字/图片/品牌叠加、音频叠加与配音、背景音乐),以及图像、音频和视频的 AI 生成。此外,该技能还能为直播流或桌面捕捉设置实时事件告警。对于开发者而言,VideoDB 通过 Python SDK 提供简洁的 API,并涵盖了上传、索引、搜索、剪辑、转码、重新构图、生成式媒体和时间线编辑等常见用例,同时提供了详细的错误处理方案和常用陷阱规避指南。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/videodb

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

VideoDB 技能

视频、直播流和桌面会话的感知 + 记忆 + 行动。

使用场景

桌面感知

  • 启动/停止桌面会话,捕获屏幕、麦克风和系统音频
  • 流式传输实时上下文,并存储情景会话记忆
  • 针对屏幕内容及语音内容运行实时告警/触发器
  • 生成会话摘要、可搜索的时间线及可播放的证据链接

视频摄入 + 流

  • 摄入文件或 URL,返回可播放的 Web 流链接
  • 转码/标准化:编解码器、比特率、帧率、分辨率、宽高比

索引 + 搜索(时间戳 + 证据)

  • 构建视觉、语音和关键词索引
  • 搜索并返回带有时间戳和可播放证据的精确时刻
  • 从搜索结果中自动创建剪辑

时间线编辑 + 生成

  • 字幕:生成、翻译、内嵌烧录
  • 叠加:文字/图片/品牌、动态字幕
  • 音频:背景音乐、画外音、配音
  • 通过时间线操作进行程序化合成和导出

直播流 (RTSP) + 监控

  • 连接 RTSP/直播源
  • 运行实时视觉和语音理解,为监控工作流发送事件/告警

工作原理

常见输入

  • 本地文件路径、公共 URL 或 RTSP URL
  • 桌面捕获请求:开始 / 停止 / 总结会话
  • 所需操作:获取上下文以理解、转码规范、索引规范、搜索查询、剪辑范围、时间线编辑、告警规则

常见输出

  • 流 URL
  • 带有时间戳和证据链接的搜索结果
  • 生成的资源:字幕、音频、图片、剪辑
  • 直播流的事件/告警负载
  • 桌面会话摘要和记忆条目

运行 Python 代码

在运行任何 VideoDB 代码之前,请切换到项目目录并加载环境变量:

from dotenv import load_dotenv
load_dotenv(".env")

import videodb
conn = videodb.connect()

这会从以下位置读取 VIDEO_DB_API_KEY:

  1. 环境变量(如果已导出)
  2. 当前目录下的项目 .env 文件

如果密钥缺失,videodb.connect() 会自动引发 AuthenticationError。

当简短的命令行内命令即可完成时,不要编写脚本文件。

编写内联 Python (python -c "...") 时,始终使用格式正确的代码——使用分号分隔语句并保持可读性。如果代码超过约 3 条语句,请改用 heredoc:

python << 'EOF'
from dotenv import load_dotenv
load_dotenv(".env")

import videodb
conn = videodb.connect()
coll = conn.get_collection()
print(f"视频数量: {len(coll.get_videos())}")
EOF

设置

当用户要求“设置 videodb”或类似操作时:

1. 安装 SDK

pip install "videodb[capture]" python-dotenv

如果 videodb[capture] 在 Linux 上安装失败,请安装不带 capture 扩展的版本:

pip install videodb python-dotenv

2. 配置 API 密钥

用户必须使用任一方法设置 VIDEO_DB_API_KEY:

  • 在终端中导出(在启动 Claude 之前):export VIDEO_DB_API_KEY=你的密钥
  • 项目 .env 文件:将 VIDEO_DB_API_KEY=你的密钥 保存在项目的 .env 文件中

在 console.videodb.io 获取免费 API 密钥(50 次免费上传,无需信用卡)。

不要自行读取、写入或处理 API 密钥。始终让用户自行设置。

快速参考

上传媒体

# URL
video = coll.upload(url="https://example.com/video.mp4")

# YouTube
video = coll.upload(url="https://www.youtube.com/watch?v=VIDEO_ID")

# 本地文件
video = coll.upload(file_path="/path/to/video.mp4")

转录 + 字幕

# force=True 可跳过视频已索引时的错误
video.index_spoken_words(force=True)
text = video.get_transcript_text()
stream_url = video.add_subtitle()

在视频内搜索

from videodb.exceptions import InvalidRequestError

video.index_spoken_words(force=True)

# search() 在未找到结果时会引发 InvalidRequestError。
# 始终将其包装在 try/except 中,并将“未找到结果”视为空。
try:
    results = video.search("产品演示")
    shots = results.get_shots()
    stream_url = results.compile()
except InvalidRequestError as e:
    if "No results found" in str(e):
        shots = []
    else:
        raise

场景搜索

import re
from videodb import SearchType, IndexType, SceneExtractionType
from videodb.exceptions import InvalidRequestError

# index_scenes() 没有 force 参数——如果场景索引已存在会引发错误。
# 从错误信息中提取现有的索引 ID。
try:
    scene_index_id = video.index_scenes(
        extraction_type=SceneExtractionType.shot_based,
        prompt="描述此场景中的视觉内容。",
    )
except Exception as e:
    match = re.search(r"id\s+([a-f0-9]+)", str(e))
    if match:
        scene_index_id = match.group(1)
    else:
        raise

# 使用 score_threshold 过滤低相关性噪声(推荐:0.3 以上)
try:
    results = video.search(
        query="在白板上写字的人",
        search_type=SearchType.semantic,
        index_type=IndexType.scene,
        scene_index_id=scene_index_id,
        score_threshold=0.3,
    )
    shots = results.get_shots()
    stream_url = results.compile()
except InvalidRequestError as e:
    if "No results found" in str(e):
        shots = []
    else:
        raise

时间线编辑

重要提示: 在构建时间线之前,务必验证时间戳:

  • start 必须 >= 0(负值会被静默接受,但会产生损坏的输出)
  • start 必须 < end
  • end 必须 <= video.length
from videodb.timeline import Timeline
from videodb.asset import VideoAsset, TextAsset, TextStyle

timeline = Timeline(conn)
timeline.add_inline(VideoAsset(asset_id=video.id, start=10, end=30))
timeline.add_overlay(0, TextAsset(text="结束", duration=3, style=TextStyle(fontsize=36)))
stream_url = timeline.generate_stream()

转码视频(分辨率/质量更改)

from videodb import TranscodeMode, VideoConfig, AudioConfig

# 服务端更改分辨率、质量或宽高比
job_id = conn.transcode(
    source="https://example.com/video.mp4",
    callback_url="https://example.com/webhook",
    mode=TranscodeMode.economy,
    video_config=VideoConfig(resolution=720, quality=23, aspect_ratio="16:9"),
    audio_config=AudioConfig(mute=False),
)

调整宽高比(适用于社交媒体平台)

警告: reframe() 是一个耗时的服务端操作。对于长视频,可能需要几分钟甚至超时。最佳实践:

  • 尽可能使用 start/end 限制在短片段内
  • 对于全长视频,使用 callback_url 进行异步处理
  • 先在 Timeline 上裁剪视频,然后对较短的结果进行调整
from videodb import ReframeMode

# 始终优先调整短片段:
reframed = video.reframe(start=0, end=60, target="vertical", mode=ReframeMode.smart)

# 全长视频的异步调整(返回 None,结果通过 webhook 传递):
video.reframe(target="vertical", callback_url="https://example.com/webhook")

# 预设:"vertical" (9:16), "square" (1:1), "landscape" (16:9)
reframed = video.reframe(start=0, end=60, target="square")

# 自定义尺寸
reframed = video.reframe(start=0, end=60, target={"width": 1280, "height": 720})

生成式媒体

image = coll.generate_image(
    prompt="山脉上的日落",
    aspect_ratio="16:9",
)

错误处理

from videodb.exceptions import AuthenticationError, InvalidRequestError

try:
    conn = videodb.connect()
except AuthenticationError:
    print("请检查你的 VIDEO_DB_API_KEY")

try:
    video = coll.upload(url="https://example.com/video.mp4")
except InvalidRequestError as e:
    print(f"上传失败: {e}")

常见陷阱

场景错误信息解决方案
索引已索引过的视频Spoken word index for video already exists使用 video.index_spoken_words(force=True) 跳过已索引的视频
场景索引已存在Scene index with id XXXX already exists使用 re.search(r"id\s+([a-f0-9]+)", str(e)) 从错误中提取现有的 scene_index_id
搜索未找到匹配InvalidRequestError: No results found捕获异常并将其视为空结果 (shots = [])
调整超时长视频上无限阻塞使用 start/end 限制片段,或传递 callback_url 进行异步处理
时间线上的负时间戳静默产生损坏的流在创建 VideoAsset 之前始终验证 start >= 0
generate_video() / create_collection() 失败Operation not allowed 或 maximum limit计划限制的功能——告知用户计划限制

示例

规范提示

  • "启动桌面捕捉,并在密码字段出现时发出告警。"
  • "录制我的会话,并在结束时生成可操作的摘要。"
  • "摄入此文件并返回可播放的流链接。"
  • "为此文件夹建立索引,找到所有包含人物的场景,返回时间戳。"
  • "生成字幕,将其烧录进去,并添加轻量的背景音乐。"
  • "连接此 RTSP URL,并在有人进入区域时发出告警。"

屏幕录制(桌面捕获)

使用 ws_listener.py 捕获录制会话期间的 WebSocket 事件。桌面捕获仅支持 macOS。

快速开始

  1. 选择状态目录:STATE_DIR="${VIDEODB_EVENTS_DIR:-$HOME/.local/state/videodb}"
  2. 启动监听器:VIDEODB_EVENTS_DIR="$STATE_DIR" python scripts/ws_listener.py --clear "$STATE_DIR" &
  3. 获取 WebSocket ID:cat "$STATE_DIR/videodb_ws_id"
  4. 运行捕获代码(完整工作流请参阅 reference/capture.md)
  5. 事件写入到:$STATE_DIR/videodb_events.jsonl

每次开始新的捕获运行时,请使用 --clear,以便过时的转录和视觉事件不会泄漏到新会话中。

查询事件

import json
import os
import time
from pathlib import Path

events_dir = Path(os.environ.get("VIDEODB_EVENTS_DIR", Path.home() / ".local" / "state" / "videodb"))
events_file = events_dir / "videodb_events.jsonl"
events = []

if events_file.exists():
    with events_file.open(encoding="utf-8") as handle:
        for line in handle:
            try:
                events.append(json.loads(line))
            except json.JSONDecodeError:
                continue

transcripts = [e["data"]["text"] for e in events if e.get("channel") == "transcript"]
cutoff = time.time() - 300
recent_visual = [
    e for e in events
    if e.get("channel") == "visual_index" and e["unix_ts"] > cutoff
]

附加文档

参考文档位于此 SKILL.md 文件旁边的 reference/ 目录中。如有需要,请使用 Glob 工具定位它。

当 VideoDB 支持该操作时,不要使用 ffmpeg、moviepy 或本地编码工具。 以下操作均由 VideoDB 在服务端处理——裁剪、合并剪辑、叠加音频或音乐、添加字幕、文字/图像叠加、转码、分辨率更改、宽高比转换、根据平台要求调整大小、转录和媒体生成。仅在 reference/editor.md 的“限制”部分列出的操作(转场、变速、裁剪/缩放、调色、音量混音)下才回退到本地工具。

何时使用何种方式

问题VideoDB 解决方案
平台拒绝视频的宽高比或分辨率video.reframe() 或带 VideoConfig 的 conn.transcode()
需要为 Twitter/Instagram/TikTok 调整视频大小video.reframe(target="vertical") 或 target="square"
需要更改分辨率(例如 1080p → 720p)带 VideoConfig(resolution=720) 的 conn.transcode()
需要在视频上叠加音频/音乐在 Timeline 上使用 AudioAsset
需要添加字幕video.add_subtitle() 或 CaptionAsset
需要组合/裁剪剪辑在 Timeline 上使用 VideoAsset
需要生成画外音、音乐或音效coll.generate_voice()、generate_music()、generate_sound_effect()

来源

此技能的参考资料位于本地 skills/videodb/reference/ 目录下。请优先使用上述本地副本,而不是在运行时跟随外部仓库链接。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能