videodb
视频与音频的查看、理解与行动。查看:从本地文件、URL、RTSP/直播源或实时录制桌面获取内容;返回实时上下文和可播放流链接。理解:提取帧,构建视觉/语义/时间索引,并通过时间戳和自动剪辑搜索片段。行动:转码和标准化(编解码器、帧率、分辨率、宽高比),执行时间线编辑(字幕、文本/图像叠加、品牌化、音频叠加、配音、翻译),生成媒体资源(图像、音频、视频),并为直播流或桌面捕获的事件创建实时警报。
SKILL.md 原文预览
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:
- 环境变量(如果已导出)
- 项目当前目录中的
.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"Videos: {len(coll.get_videos())}")
EOF设置
当用户要求“设置 videodb”或类似操作时:
1. 安装 SDK
pip install "videodb[capture]" python-dotenv如果在 Linux 上 videodb[capture] 失败,请安装不带捕获扩展的版本:
pip install videodb python-dotenv2. 配置 API 密钥
用户必须使用任一方法设置 VIDEO_DB_API_KEY:
- 在终端中导出(在启动 Claude 之前):
export VIDEO_DB_API_KEY=your-key - 项目
.env文件:将VIDEO_DB_API_KEY=your-key保存在项目的.env文件中
免费获取 API 密钥,请访问 console.videodb.io(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")
# Local file
video = coll.upload(file_path="/path/to/video.mp4")转录 + 字幕
# force=True skips the error if the video is already indexed
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() raises InvalidRequestError when no results are found.
# Always wrap in try/except and treat "No results found" as empty.
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() has no force parameter — it raises an error if a scene
# index already exists. Extract the existing index ID from the error.
try:
scene_index_id = video.index_scenes(
extraction_type=SceneExtractionType.shot_based,
prompt="Describe the visual content in this scene.",
)
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
# Use score_threshold to filter low-relevance noise (recommended: 0.3+)
try:
results = video.search(
query="person writing on a whiteboard",
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必须 <endend必须 <=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
# Change resolution, quality, or aspect ratio server-side
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
# Always prefer reframing a short segment:
reframed = video.reframe(start=0, end=60, target="vertical", mode=ReframeMode.smart)
# Async reframe for full-length videos (returns None, result via webhook):
video.reframe(target="vertical", callback_url="https://example.com/webhook")
# Presets: "vertical" (9:16), "square" (1:1), "landscape" (16:9)
reframed = video.reframe(start=0, end=60, target="square")
# Custom dimensions
reframed = video.reframe(start=0, end=60, target={"width": 1280, "height": 720})生成式媒体
image = coll.generate_image(
prompt="a sunset over mountains",
aspect_ratio="16评论
