Communitygithub.com

VideoDB

查看、理解並操作影片與音訊。支援從本機檔案、網址、RTSP/即時串流或桌面錄製進行攝取,提供即時上下文與可播放的串流連結。可建立視覺、語意與時間索引,搜尋片段並回傳時間戳記與自動剪輯。支援轉碼、時間軸編輯、媒體素材生成,以及即時事件警報。

VideoDB 是什麼?

VideoDB 是一個專為 AI 代理與開發者設計的完整影片/音訊處理技能,提供感知、記憶與操作三大核心功能。它支援從本機檔案、公開 URL、YouTube、RTSP 即時串流或桌面畫面擷取(macOS)等多元來源進行攝取,返回可播放的網頁串流連結。透過建立視覺、語音與關鍵字索引,開發者可以精確搜尋特定時刻,並取得時間戳記與可播放的證據連結,還能自動剪輯片段。技能涵蓋轉碼與正規化(解析度、影格率、長寬比)、時間軸編輯(字幕產生/翻譯/燒錄、文字/圖片疊加、品牌標誌、音訊覆蓋、配音、翻譯),以及 AI 媒體素材生成(圖片、音訊、影片)。此外,即時串流監控功能可對即時畫面或桌面錄製內容設定事件警報。支援的平台包括 Claude Code、Cursor、Codex 等,透過 Python SDK(`videodb`)與 `dotenv` 環境變數設定 API 金鑰。技能文件同時明確指出哪些操作應由 VideoDB 伺服端處理,避免使用 ffmpeg 等本機工具。

相容平台✓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,並回傳可播放的網頁串流連結
  • 轉碼/正規化:編碼器、位元率、影格率、解析度、長寬比

索引與搜尋(時間戳記與證據)

  • 建立視覺、語音與關鍵字索引
  • 搜尋並回傳具備時間戳記和可播放證據的精確時刻
  • 從搜尋結果自動建立剪輯

時間軸編輯與生成

  • 字幕:產生、翻譯、燒錄
  • 疊加:文字/圖片/品牌標誌、動態字幕
  • 音訊:背景音樂、旁白、配音
  • 透過時間軸操作進行程式化組合與匯出

即時串流 (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 extras 的版本:

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 中,並將「未找到結果」視為空值處理。
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="The End", 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.

相關技能