Communitygithub.com

VideoDB

觀看、理解、並對影片和音訊採取行動。支援從本地檔案、URL、RTSP/即時串流或桌面擷取輸入內容;即時返回上下文與可播放的串流連結,進而提取畫面、建立視覺/語意/時間索引、搜尋精確時刻並自動剪輯,以及進行轉碼、時間軸編輯、媒體生成和即時事件警示。

VideoDB 是什麼?

VideoDB 是一個專為開發者與 AI 代理設計的影片/音訊技能,提供完整的「感知 → 記憶 → 行動」工作流程。它支援:從本地檔案、公開 URL、YouTube 連結、RTSP 即時串流或桌面畫面/麥克風/系統音訊擷取內容;透過語意搜尋或場景搜尋(含時間戳與可播放證據連結)來索引與檢索;以及一系列伺服器端處理操作,包括轉碼(解析度、位元率、FPS、長寬比)、時間軸編輯(字幕、文字/圖片疊加、配音、背景音樂)與生成式媒體(影像、音訊、影片)。特別的桌面擷取功能可記錄工作階段的「情境記憶」,支援即時事件觸發與工作階段摘要。此技能主要在 Python 環境中運作(需 `videodb[capture]` SDK),並透過環境變數 `VIDEO_DB_API_KEY` 進行驗證。它支援 Cursor、Claude Code 與其他可執行 Python 的 AI 代理平台。其參考文件收藏於 `skills/videodb/reference/` 目錄下,涵蓋 API 參考、搜尋、編輯器、串流、生成式媒體與即時串流等主題。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

VideoDB 技能

感知 + 記憶 + 影片、即時串流與桌面工作階段的行動。

使用時機

桌面感知

  • 啟動/停止桌面工作階段,擷取螢幕、麥克風與系統音訊
  • 串流即時情境,並儲存情節性工作階段記憶
  • 對說出的內容與螢幕上發生的事執行即時警示/觸發
  • 產生工作階段摘要、可搜尋的時間軸,以及可播放的證據連結

影片擷取 + 串流

  • 擷取檔案或 URL,並回傳可播放的網路串流連結
  • 轉碼/正規化:編碼器、位元率、fps、解析度、長寬比

索引 + 搜尋(時間戳 + 證據)

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

時間軸編輯 + 生成

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

即時串流(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 中,並將「找不到結果」視為空。
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 工具來尋找。

請勿使用 ffmpeg、moviepy 或本機編碼工具,只要 VideoDB 支援該操作。以下所有操作均由 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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能