Communitygithub.com

503496348-ops/mischief-production

对视频和音频进行观察、理解与操作:从本地文件、URL、RTSP/直播源或桌面录制中摄取内容,提取帧、构建索引、搜索时刻并自动生成剪辑,执行转码、时间线编辑和实时告警。

mischief-production 是什么?

该技能是一个面向视频和音频的全栈处理工具,基于 VideoDB SDK 实现“感知+记忆+行动”的闭环。它支持从本地文件、URL、RTSP 直播流或桌面录制中摄取视频/音频,并通过视觉、语义和时间索引提供可搜索的时刻与可播放的证据链接。开发人员可以利用该技能执行转码(编解码器、帧率、分辨率、纵横比)、时间线编辑(字幕生成/翻译/烧录、文本/图像/品牌叠加、配音、背景音乐)、生成媒体资产(图像、音频、视频),以及针对直播流或桌面录制设置实时告警。该技能在 Claude Code、Cursor 等支持 SDK 的环境中使用,通过 Python 代码直接调用 VideoDB SDK,并提供了详细的错误处理指南和最佳实践,确保稳定性。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/503496348-ops/mischief-production/tree/HEAD/skills/ecc-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

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

pip install videodb python-dotenv

2. 配置 API 密钥

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

  • 在终端中导出(在启动 Claude 之前):export VIDEO_DB_API_KEY=your-key
  • 项目 .env 文件:将 VIDEO_DB_API_KEY=your-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 中,并将“No results found”视为空结果。
try:
    results = video.search("product demo")
    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 = [])
Reframe 超时长视频上无限阻塞使用 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 7 individual skills — each has its own dedicated page.

503496348-ops/mischief-production

Use this skill when inspecting Blender characters, rigs, poses, animation retargeting, ground contact, facing direction, or model-vs-motion alignment where screenshots alone are not enough.

503496348-ops/mischief-production

Build reusable Manim explainers for technical concepts, graphs, system diagrams, and product walkthroughs, then hand off to the wider HCP video stack if needed. Use when the user wants a clean animated explainer rather than a generic talking-head script.

503496348-ops/mischief-production

Advanced motion patterns for React / Next.js — drag & drop, gestures, text animations, SVG path drawing, custom hooks, imperative sequences (useAnimate), loaders, and the full API decision tree. Requires motion-foundations.

503496348-ops/mischief-production

Motion tokens, spring presets, performance rules, device adaptation, accessibility enforcement, and SSR safety for React / Next.js using motion/react. Foundation layer — all other motion skills depend on this.

503496348-ops/mischief-production

Production-ready animation patterns for React / Next.js — button, modal, toast, stagger, page transitions, exit animations, scroll, and layout — built on motion-foundations tokens and springs.

503496348-ops/mischief-production

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

503496348-ops/mischief-production

Best practices for Remotion - Video creation in React. 29 domain-specific rules covering 3D, animations, audio, captions, charts, transitions, and more.

相关技能