手把手:把 Remotion 封装成 DeepSeek Harness 插件,一句话让 AI 出视频

导语

DeepSeek Harness 的口号是"一切皆插件"。昨天我写了篇教程教大家给 Harness 写文字插件,有朋友问:能不能让 AI 直接出视频?

答案是可以。本文从零开始,把 Remotion (React 视频渲染框架)封装成一个 Harness 插件,注册 render_video 工具,让 AI 在对话里说一句话就能渲染出 MP4。

读完你将掌握:Harness 插件开发完整流程、Remotion 命令行渲染调用、插件打包发布,以及 Windows 环境下的兼容性坑。

一、原理:为什么 Remotion 能接到 Harness 上

两个工具能对接,关键在于它们都"命令行友好":

组件 定位 关键能力
Remotion React 视频框架 每帧 = React 组件,支持 npx remotion render 命令行渲染
DeepSeek Harness 模型执行层 基于 Cordis 框架,一切皆插件,工具注册后 AI 可调用

对接路径:写一个插件 → 注册 render_video 工具 → 工具内部 execSync 调用 Remotion CLI → MP4 输出到本地。

目前 GitHub 上还没有现成的 dsh-remotion 官方插件(Harness 于 8 月 13 日才开源)。社区主流是 Claude Code / Codex + Remotion,官方 remotion-dev/skills 已有 20 万+ 次安装。本文教你造一个,而不是安利现成货。

二、环境准备

2.1 Harness 工作台

bash 复制代码
npx @deepseek-ai/dsh web

浏览器访问 http://127.0.0.1:3080

2.2 Remotion 项目

bash 复制代码
npx create-video@latest --yes --blank my-video
cd my-video
npm i

:Remotion 渲染时会下载无头浏览器,国内网络可能不稳定,多试几次或挂代理。

三、核心:插件代码

typescript 复制代码
// dsh-remotion.ts
import { defineTool } from '@deepseek-ai/dsh-tools'
import { execSync } from 'child_process'
export const name = 'dsh-remotion'
export const inject = ['tools']
export function apply(ctx) {
  ctx.tools.register(defineTool({
    name: 'render_video',
    description: '根据传入的标题和文案,调用 Remotion 渲染一条短视频',
    parameters: {
      title: { type: 'string', required: true, description: '视频主标题' },
      caption: { type: 'string', required: true, description: '视频正文文案' },
      projectDir: { type: 'string', required: true, description: 'Remotion 项目绝对路径' }
    },
    output: { schema: { type: 'object', additionalProperties: false, properties: { path: { type: 'string', required: true } } },
    render: (_a, v) => [{ type: 'text', text: `视频已生成,${v.path}` }] },
    async execute(args) {
      const data = JSON.stringify({ title: args.title, caption: args.caption })
      const out = `${args.projectDir}/out/${Date.now()}.mp4`
      execSync(
        `npx remotion render src/index.ts Main out/video.mp4 --props='${data}'`,
        { cwd: args.projectDir, stdio: 'inherit' }
      )
      return { path: out }
    }
  }))
}

踩坑清单

  1. 具名导出 :必须 export const name,写 export default 注入声明会被静默丢弃,插件"看着加载了其实不干活"。
  2. Schema 约束 :对象类型输出必须带 additionalProperties: false,否则注册直接报错。
  3. 注入顺序inject: ['tools'] 表示等工具注册表就绪再执行。
  4. Windows 专属坑 :PowerShell 会把 ${Date.now()} 预解析。解决方案:
    • 改用 PowerShell 语法
    • 或写死输出路径 out/video.mp4

四、配置挂载

创建 cordis.yml

yaml 复制代码
- insert:
  - id: dsh-remotion
    name: '/绝对路径/你的目录/dsh-remotion.ts'

路径必须绝对路径,Cordis 不认相对路径。

带补丁启动:

bash 复制代码
pnpm dsh web --patch ./cordis.yml

对话中触发:「用 render_video 做一条视频,标题写 AI 周报,文案写本周五个重要进展」。

五、提升视频质量:接入 Remocn 组件库

bash 复制代码
npx shadcn@latest add @remocn/blur-reveal

Remocn 是面向 solo 开发者/一人公司的组件库,一条命令引入现成的标题动画、转场、背景,避免从零写弹簧效果。

六、打包发布

package.json 声明插件:

json 复制代码
{
  "name": "dsh-remotion",
  "type": "module",
  "main": "dsh-remotion.ts",
  "dsh": { "bundle": { "patch": "./cordis.patch.yml" } }
}

发布安装:

bash 复制代码
dsh plugin --profile web add github:你的账号/你的仓库

Vibe Coding 提示:DSH 插件结构(单文件 + apply 入口 + YAML)天生适合 AI 生成,可直接把规范丢给 Cursor 等工具秒级产出。

七、局限与安全

维度 说明
版本 Harness 0.1.0 预发布版,接口会变,先尝鲜别上生产
性能 Remotion 渲染吃 CPU/内存,老机器谨慎;批量出片用官方 Lambda 方案
安全 插件 = 本机可执行代码,只装官方或高星插件
门槛 需 TypeScript + React 基础,比学剪辑软件简单

总结

  • 核心链路:Harness 插件 → render_video 工具 → Remotion CLI → MP4
  • 关键踩坑:具名导出、additionalProperties: false、Windows 路径解析
  • 下一步:把日报插件 + 视频插件串联,实现文字草稿自动转视频成片

金句:真正的自动化不是你学会了剪辑,而是你只需要说一句话,视频引擎自己就把片子渲出来了。

相关推荐
吴佳浩 Alben11 小时前
Agent 安全红线:越狱防御、间接注入与数据防泄漏实战
人工智能·安全·语言模型·架构·ai编程
全栈弄潮儿11 小时前
一条高质量编程 Prompt,应该包含什么?
aigc·openai·ai编程
wangruofeng12 小时前
120+ 个 Agent Skill 管不过来?我造了套「包管理器」:仓库是源,链接是安装
github·aigc·ai编程
七牛云行业应用12 小时前
Cursor Origin发布:同一天GitHub宕机,AI原生代码托管来了
人工智能·github·agent·ai编程·ai-native
SkyWalking中文站12 小时前
看清 Claude Code 的用量与文件变更
人工智能·ai编程·claude
飞哥数智坊13 小时前
TraeCode 180积分帮我做了一套系统,全程我感觉自己有点多余
人工智能·ai编程
Flynt16 小时前
两天传了 2000 个包:OpenAI 的 Agent 是怎么把 RubyGems 当硬盘用的
安全·openai·ai编程
爱学习的小白柏17 小时前
同城双活的核心不是双活,是逼着数据别出机房
大数据·人工智能·算法·langchain·ai编程
全栈技术负责人18 小时前
AI 效能工具建设:Agent 可观测性技能技术方案与实践
前端·ai·ai编程
零依赖极客18 小时前
《30 天手搓 ARM 架构零依赖纯 C 推理引擎》课程介绍与大纲
c语言·开发语言·arm开发·人工智能·嵌入式硬件·ai编程