视频生成服务器

基于OpenAI Sora 2 API的视频生成服务器,支持文本转视频、图像转视频、视频混剪、批量处理和成本估算功能。

  • by ex-takashima
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 ex-takashima/openai-sora2-mcp-server

使用说明

OpenAI Sora 2 MCP服务器

用于使用OpenAI Sora 2 API生成视频的模型上下文协议(MCP)服务器。

特性

  • 文本转视频:根据文本提示生成视频
  • 图像转视频:将图像动画化为视频
  • 混音:使用新提示修改现有视频
  • 批处理:执行多个具有并发控制的视频生成作业
  • 成本估算:在执行批处理作业之前估算成本

需求

  • Node.js 18.0.0或更高版本
  • 具有第2+级访问权限的OpenAI API密钥(Sora需要10美元以上的信用购买)

安装

npm install openai-sora2-mcp-server

或者克隆并在本地构建:

git clone https://github.com/your-repo/openai-sora2-mcp-server.git
cd openai-sora2-mcp-server
npm install
npm run build

配置

创建 .env 项目根目录中的文件:

OPENAI_API_KEY=sk-...
DEBUG=false
OUTPUT_DIR=./output
VIDEO_POLL_INTERVAL=15000
VIDEO_MAX_POLL_ATTEMPTS=120

用法

MCP 服务器

添加到您的Claude Desktop配置(claude_desktop_config.json):

{
  "mcpServers": {
    "sora2": {
      "command": "npx",
      "args": ["sora2-mcp-server"],
      "env": {
        "OPENAI_API_KEY": "sk-..."
      }
    }
  }
}

可用工具

生成视频

从文本提示或图像生成视频。

Parameters:
- prompt (required): Description of the video to generate
- model: "sora-2" (default) or "sora-2-pro"
- size: "1280x720" (default), "1920x1080", "1080x1920", etc.
- seconds: 4/8/12 for sora-2, 10/15/25 for sora-2-pro
- input_reference: Image URL or base64 for image-to-video
- output_path: Path to save the video file

混音视频

将现有视频与新提示进行混音。

Parameters:
- prompt (required): New description for the remixed video
- remix_video_id (required): ID of the video to remix
- output_path: Path to save the remixed video

获取_视频_状态

检查视频生成作业的状态。

Parameters:
- video_id (required): ID of the video to check

列表_视频

列出以前生成的视频。

Parameters:
- limit: Maximum number of videos to return (default: 20)

批处理CLI

从配置文件执行多个视频生成作业:

sora2-batch config.json [options]

选项

选项 描述
--output-dir <path> 生成视频的输出目录
--format text|json 输出格式(默认:文本)
--timeout <ms> 批处理总超时时间(毫秒)
--max-concurrent <n> 最大并发作业数(1-5,默认值:2)
--poll-interval <ms> 轮询间隔(默认值:15000)
--estimate-only 仅估算成本而不执行
--help 显示帮助

示例

# Estimate cost
sora2-batch examples/batch-simple.json --estimate-only

# Execute batch
sora2-batch examples/batch-simple.json --output-dir ./output --max-concurrent 3

批量配置

{
  "jobs": [
    {
      "prompt": "A cat playing piano in a jazz bar",
      "seconds": 8,
      "size": "1280x720"
    },
    {
      "prompt": "Ocean waves at sunset",
      "seconds": 4,
      "size": "1920x1080"
    }
  ],
  "output_dir": "./output",
  "max_concurrent": 2,
  "default_model": "sora-2",
  "default_size": "1280x720",
  "default_seconds": 4,
  "retry_policy": {
    "max_retries": 2,
    "retry_delay_ms": 1000,
    "retry_on_errors": ["rate_limit", "timeout", "429", "503"]
  }
}

型号和定价

sora-2(标准)

持续时间 分辨率 价格
4秒 720便士 0.40美元
8秒 720p 0.80美元
12秒 720便士 1.20美元

sora-2-pro(高品质)

持续时间 分辨率 价格
10秒 720p 3.00美元
15秒 720p 4.50美元
25秒 720p 7.50美元
10秒 1024p 5.00美元
25秒 1024p 12.50美元

支持的决议

宽高比 分辨率
16:9(横向) 1920x1080、1280x720
9:16(肖像) 1080x1920、720x1280
1:1(正方形) 1080x1080、480x480

api参考

端点

操作 端点
生成视频 POST https://api.openai.com/v1/videos
混音视频 POST https://api.openai.com/v1/videos/{id}/remix
获取状态 GET https://api.openai.com/v1/videos/{id}
视频列表 GET https://api.openai.com/v1/videos
下载中心 GET https://api.openai.com/v1/videos/{id}/content

视频状态

状态 描述
queued 排队等候
in_progress 目前正在处理
completed 生成已完成
failed 生成失败
cancelled 作业已取消

许可证

麻省理工学院