Skip to content

Drift 视频渲染服务 ​

Drift 接收视频、贴纸与效果参数,通过同一个 HTTP 响应交付 MP4。

启动 ​

使用 Docker Compose 部署时,加入 wangquan-network 的容器可访问 http://drift-api 和 http://drift-docs。启动准备和网络配置见架构与部署。

本地运行 ​

本地开发需要 Node.js 22 或更新版本、pnpm 8.7.0,以及包含 libx264 的 FFmpeg 和 FFprobe。

在仓库根目录安装与构建。

sh
corepack enable
pnpm install --frozen-lockfile
pnpm build

在独立终端启动 Worker 和 API。

sh
pnpm --filter @drift/render start:dev
pnpm --filter @drift/api start:dev

只提交原片 ​

以下示例使用本地运行的服务。在 Docker 共享网络内调用时,把 http://localhost:4000 替换为 http://drift-api。

sh
curl --fail-with-body http://localhost:4000/v1/video/render \
  -F 'source=@source.mp4' \
  -o rendered.mp4

使用运镜、浮尘和贴纸 ​

下面的配置把同一张贴纸放在两个位置,并添加一个顶部标题。将它保存为 config.json。

json
{
  "motion": {"rotationAmplitudeDeg": 0.5, "zoomAmplitude": 0.015, "periodSeconds": 2, "seed": 100},
  "dust": {"count": 72, "minRadiusPx": 10, "maxRadiusPx": 60, "speedPxPerSecond": 200, "directionDeg": 315, "opacity": 0.05},
  "layers": [
    {"type": "image", "assetId": "badge", "width": 100, "position": {"mode": "absolute", "x": 1, "y": 1}},
    {"type": "image", "assetId": "badge", "width": 100, "position": {"mode": "top-right"}},
    {"type": "text", "text": "视频调试", "position": {"mode": "top-center", "offset": {"y": 18}}}
  ]
}
sh
curl --fail-with-body http://localhost:4000/v1/video/render \
  -F 'source=@source.mp4' \
  -F 'config=<config.json' \
  -F 'asset.badge=@badge.png' \
  -o rendered.mp4

浏览器可以打开 http://localhost:4000/debug,选择素材和效果、复制请求 JSON,再播放或下载生成的视频。