C-Drama 是一个基于AI的视频自动化生产平台,实现从剧本生成、角色设计、分镜制作到视频合成的全流程自动化。
C-Drama is an AI-powered short drama production platform that automates the entire workflow from script generation, character design, storyboarding to video composition.
- 🤖 AI驱动 / AI-Driven:使用大语言模型解析剧本,提取角色、场景和分镜信息 | Parse scripts using large language models to extract characters, scenes, and storyboards
- 🎨 智能创作 / Intelligent Creation:AI绘图生成角色形象和场景背景 | AI-generated character portraits and scene backgrounds
- 📹 视频生成 / Video Generation:基于文生视频和图生视频模型自动生成分镜视频 | Automatic storyboard video generation using text-to-video and image-to-video models
- 🔄 工作流 / Workflow:完整的视频制作工作流,从创意到成片一站式完成 | Complete production workflow from idea to final video
采用DDD领域驱动设计,清晰分层:
├── API层 (Gin HTTP)
├── 应用服务层 (Business Logic)
├── 领域层 (Domain Models)
└── 基础设施层 (Database, External Services)
体验 AI 视频生成效果:
- ✅ AI生成角色形象
- ✅ 批量角色生成
- ✅ 角色图片上传和管理
- ✅ 自动生成分镜脚本
- ✅ 场景描述和镜头设计
- ✅ 分镜图片生成(文生图)
- ✅ 帧类型选择(首帧/关键帧/尾帧/分镜板)
- ✅ 图生视频自动生成
- ✅ 视频合成和剪辑
- ✅ 转场效果
- ✅ 素材库统一管理
- ✅ 本地存储支持
- ✅ 资源导入导出
- ✅ 任务进度追踪
| 软件 | 版本要求 | 说明 |
|---|---|---|
| Go | 1.23+ | 后端运行环境 |
| Node.js | 18+ | 前端构建环境 |
| npm / yarn | 9+ / 1.22+ | 包管理工具(推荐使用yarn) |
| FFmpeg | 4.0+ | 视频处理(必需) |
| SQLite | 3.x | 数据库(已内置) |
macOS:
brew install ffmpegUbuntu/Debian:
sudo apt update
sudo apt install ffmpegWindows: 从 FFmpeg官网 下载并配置环境变量
验证安装:
ffmpeg -version复制并编辑配置文件:
cp configs/config.example.yaml configs/config.yaml
# Windows 使用:
copy configs\config.example.yaml configs\config.yaml编辑配置文件(使用记事本或其他编辑器):
notepad configs\config.yaml注意:默认配置已经将前后端集成在一起,访问地址为 http://localhost:8080,无需额外配置。
配置文件格式(configs/config.yaml):
app:
name: "C-Drama API"
version: "1.0.0"
debug: true # 开发环境设为true,生产环境设为false
server:
port: 8080
host: "0.0.0.0"
cors_origins:
- "http://localhost:8080"
read_timeout: 600
write_timeout: 600
database:
type: "sqlite"
path: "./data/drama_generator.db"
max_idle: 10
max_open: 100
storage:
type: "local"
local_path: "./data/storage"
base_url: "http://localhost:8080/static"
ai:
default_text_provider: "openai"
default_image_provider: "openai"
default_video_provider: "doubao"重要配置项:
app.debug: 调试模式开关(开发环境建议设为true)server.port: 服务运行端口(默认8080)server.cors_origins: 允许跨域访问的前端地址database.path: SQLite数据库文件路径storage.local_path: 本地文件存储路径storage.base_url: 静态资源访问URLai.default_*_provider: AI服务提供商配置(在Web界面中配置具体的API Key)
本项目采用前后端一体化架构:
- 后端:Go + Gin 框架,提供 API 服务和静态文件服务
- 前端:Vue 3 + TypeScript,构建为静态文件嵌入后端
- 访问方式:通过
http://localhost:8080统一访问前后端
- 前端构建:执行
yarn build后,前端代码编译到web/dist目录 - 静态服务:后端通过 Gin 框架的
Static()方法提供静态文件服务 - SPA 支持:使用
NoRoute中间件实现单页应用的路由 fallback - 端口统一:前后端共用 8080 端口,避免跨域问题
cdrama/
├── main.go # 后端入口
├── c-drama.exe # 编译后的可执行文件
├── web/
│ ├── dist/ # 前端构建产物(自动集成)
│ │ ├── index.html
│ │ ├── assets/ # JS/CSS/图片资源
│ │ └── ffmpeg/ # FFmpeg WASM 文件
│ ├── src/ # 前端源码
│ └── build.bat # 前端构建脚本
├── data/
│ ├── drama_generator.db # 数据库
│ └── storage/ # 上传的文件
├── configs/
│ └── config.yaml # 配置文件
├── build.bat # 一键构建脚本(前后端)
└── start.bat # 启动脚本
- 主界面:
http://localhost:8080→ 自动加载前端页面 - API 接口:
http://localhost:8080/api/v1/* - 静态资源:
http://localhost:8080/static/*(用户上传的文件) - 前端资源:
http://localhost:8080/assets/*(JS/CSS/图片)
# 创建Handler
vim api/handlers/your_handler.go
# 注册路由
vim api/routes/routes.go示例:
// api/handlers/your_handler.go
func (h *YourHandler) YourMethod(c *gin.Context) {
// 处理逻辑
response.Success(c, data)
}
// api/routes/routes.go
your := api.Group("/your")
{
your.GET("", yourHandler.List)
your.POST("", yourHandler.Create)
}// application/services/your_service.go
type YourService struct {
db *gorm.DB
log *logger.Logger
}
func NewYourService(db *gorm.DB, log *logger.Logger) *YourService {
return &YourService{db: db, log: log}
}
func (s *YourService) YourMethod() error {
// 业务逻辑
return nil
}# 创建页面组件
vim web/src/views/YourPage.vue
# 注册路由
vim web/src/router/index.ts
# 添加API调用
vim web/src/api/your-api.ts后端调试:
# 启用详细日志
export LOG_LEVEL=debug
go run main.go
# 使用dlv调试器
dlv debug main.go前端调试:
cd web
npm run dev
# 打开浏览器 DevTools数据库查询:
sqlite3 data/drama_generator.db
.tables
.schema dramas
SELECT * FROM dramas;# 🔧 开发模式
go run main.go # 启动后端服务(访问 http://localhost:8080)
cd web && yarn dev # 启动前端开发服务器(访问 http://localhost:3012)
# 📦 编译构建(前后端一体化)
./build.bat # 一键构建前后端(Windows)
# 或
./build.sh # 一键构建前后端(Linux/macOS)
# 🚀 运行程序
./start.bat # 启动程序(Windows)
# 或
./start.sh # 启动程序(Linux/macOS)
# 📁 手动分步构建
cd web && yarn install # 安装前端依赖
cd web && yarn build && cd .. # 构建前端
go build -o c-drama.exe . # 编译后端(Windows)
# 或
go build -o c-drama . # 编译后端(Linux/macOS)
# 📥 依赖管理
go mod download # 下载Go依赖
go mod tidy # 清理Go依赖
cd web && yarn install && cd .. # 安装前端依赖
# ✅ 代码检查
go fmt ./... # 格式化代码
go vet ./... # 代码检查
cd web && yarn lint && cd .. # 前端代码检查
# 🗑️ 清理
go clean # 清理Go构建缓存
rm -rf web/dist # 清理前端构建产物
rm -f c-drama* # 删除可执行文件
# 🧪 测试
go test ./... # 运行Go测试
cd web && yarn test && cd .. # 运行前端测试- 语言: Go 1.23+
- Web框架: Gin 1.9+
- ORM: GORM
- 数据库: SQLite
- 日志: Zap
- 视频处理: FFmpeg
- AI服务: 豆包 Doubao API
- 框架: Vue 3.4+
- 语言: TypeScript 5+
- 构建工具: Vite 5
- UI组件: Element Plus
- CSS框架: TailwindCSS
- 状态管理: Pinia
- 路由: Vue Router 4
- 包管理: Go Modules, npm
- 代码规范: ESLint, Prettier
- 版本控制: Git
A: 确保FFmpeg已安装并在PATH环境变量中。运行 ffmpeg -version 验证。
A: 检查后端是否启动,端口是否正确。开发模式下前端代理配置在 web/vite.config.ts。
A: GORM会在首次启动时自动创建表,检查日志确认迁移是否成功。
- 修复 视频生成 API 响应解析问题
- 修复视频生成客户端选择逻辑
- 添加 OpenAI Sora 视频端点配置(/videos 和 /videos/{taskId})
- 优化错误处理,支持 JSON 对象和字符串格式的错误响应
- 完善视频生成服务的 provider 识别
- 优化客户端请求格式(支持 Sora/Doubao 模型)
- 改进日志输出,便于调试
欢迎提交 Issue 和 Pull Request!
- Fork 本项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交改动 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request