Communitygithub.com

503496348-ops/mischief-production

對影片和音訊進行感知、理解與操作。支援從本地檔案、URL、RTSP/即時串流或桌面錄製進行擷取,提供即時上下文與可播放串流連結;建立視覺、語意與時間索引,並可搜尋片段,自動產出時間戳記與剪輯;支援轉碼與正規化、時間軸編輯、媒體資產生成,並可從即時串流或桌面錄製建立即時事件警示。

mischief-production 是什麼?

此技能為 AI 代理(如 Claude Code 或 Cursor)提供全面的影片與音訊處理能力,涵蓋感知、記憶與行動三大面向。**感知**層支援從本地檔案、URL、YouTube、RTSP 即時串流以及桌面螢幕與音訊錄製進行內容擷取,並即時回傳可播放的串流連結。**理解**層可對影片進行語音轉文字、場景索引、視覺語意搜尋,並返回精確的時間戳記與自動剪輯的證據片段。**行動**層則提供伺服器端轉碼(解析度、影格率、編碼格式)、時間軸編輯(字幕、文字/圖片疊加、配音、翻譯)、AI 生成媒體(圖片、聲音、音樂)以及即時事件觸發與警示。此技能支援多種平台與操作環境(macOS 桌面錄製、即時串流監控),並透過 VideoDB Python SDK 完成所有操作,免除本地 ffmpeg 或 moviepy 等工具需求。開發者可直接透過自然語言指令觸發影片處理工作流程,適合用於內容審查、即時監控、媒體資產自動化生產等場景。

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

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

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

時間軸編輯 + 生成

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

即時串流 (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=your-key
  • 專案 .env 檔案:在專案的 .env 檔案中儲存 VIDEO_DB_API_KEY=your-key

在 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 上裁剪影片,然後對較短的結果進行 reframe
from videodb import ReframeMode

# 始終優先對短片段進行 reframe:
reframed = video.reframe(start=0, end=60, target="vertical", mode=ReframeMode.smart)

# 非同步 reframe 用於全長影片(回傳 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.

相關技能