# document2video **Repository Path**: tengyundong_admin/document2video ## Basic Information - **Project Name**: document2video - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-18 - **Last Updated**: 2026-07-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Document2Video — 本地 PDF/PPTX 上传,AI 生成讲解视频 > 上传本地 PDF 文档 + PPTX 模板 → AI 自动分析文档内容 → 生成讲解幻灯片 → 合成带语音的讲解视频 > > 从 [PresentAgent-2](https://github.com/AIGeeksGroup/PresentAgent-2) 提取的独立项目,专注于**本地文档到视频**的最小化流程。 --- ## 功能概览 | 功能 | 说明 | |------|------| | PDF 解析 | 本地 marker-pdf 模型,将 PDF 转为结构化 Markdown | | 文档分析 | LLM 识别章节、提取关键点、生成图片描述 | | 模板学习 | ViT 聚类分析 PPTX 模板布局,提取内容 Schema | | PPT 生成 | 多 Agent 协作(双引擎:旧引擎 + 🆕 Presentation-First 新引擎) | | 🆕 智能布局 | 20 种策略(显示/表格/图表),7 维度质量评分,自动重试 | | 🆕 表格分析 | 纯启发式 8 种表格类型分类,智能列选择 + 分页 + 图表转换 | | 演讲备注 | LLM 自动生成演讲备注(支持单人/双人讨论模式) | | 语音合成 | MegaTTS3 零样本 TTS,将备注转为自然语音 | | 视频合成 | ffmpeg 合成幻灯片图片 + 语音 = 讲解视频 | --- ## 快速开始 ### 1. 环境准备 ```bash # Python 3.11+ conda create -n doc2video python=3.11 conda activate doc2video # 系统工具 # Linux: sudo apt-get install -y libreoffice ffmpeg # macOS: brew install libreoffice ffmpeg # Windows: 手动安装 LibreOffice + ffmpeg (conda install -c conda-forge ffmpeg) ``` ### 2. 安装依赖 ```bash cd Document2Video pip install -r requirements.txt # Windows 额外步骤: conda install -y -c conda-forge pynini==2.1.5 pip install WeTextProcessing==1.0.3 ``` ### 3. 配置环境变量 ```bash cp .env.example .env # 编辑 .env,填入 API_BASE 和 OPENAI_API_KEY ``` 最少只需要 2 个环境变量: ```bash export API_BASE="https://api.openai.com/v1" export OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ``` ### 4. 下载 TTS 模型(可选,不下载则视频无语音) 从 [HuggingFace — ByteDance/MegaTTS3](https://huggingface.co/ByteDance/MegaTTS3/tree/main) 下载模型权重,放到 `server/MegaTTS3/checkpoints/` 目录下。 详见 [DEPLOYMENT.md](DEPLOYMENT.md) 第 3 节。 ### 5. 启动服务 **后端 (端口 9297):** ```bash export PYTHONPATH="$(pwd):$(pwd)/server/MegaTTS3:$PYTHONPATH" cd server && python backend.py ``` **前端 (端口 8088):** ```bash cd frontend npm install npm run serve ``` 打开浏览器访问 `http://localhost:8088` ### 6. 使用流程 ``` 第一步:上传 PDF 文档 + PPTX 模板 → 生成 PPTX 1. 打开 http://localhost:8088 2. 上传 PPTX 模板(样式参考) 3. 上传 PDF 文档(内容来源) 4. 选择目标页数,点击 "Generate Slides" 5. 等待进度到 100%,下载生成的 PPTX 第二步:PPT → 视频 6. 切换到 "PPT2Presentation" 页面 7. 上传刚才下载的 PPTX 8. 等待三阶段完成,下载 MP4 视频 ``` --- ## 命令行方式 不需要 Web 界面时,可直接用命令行: ```bash python scripts/run_document_to_video.py \ --pdf /path/to/document.pdf \ --template-pptx resource/templates/default_template.pptx \ --output-dir /path/to/output \ --num-slides 8 \ --notes-mode single_presentation ``` --- ## API 方式 ```bash # Step 1: 上传文件生成 PPT curl -X POST http://localhost:9297/api/upload \ -F "pptxFile=@template.pptx" \ -F "pdfFile=@document.pdf" \ -F "numberOfPages=8" # Step 2: 下载 PPTX curl -o output.pptx "http://localhost:9297/api/download?task_id=..." # Step 3: PPT 转视频 curl -X POST http://localhost:9297/api/ppt-to-video \ -F "pptFile=@output.pptx" # Step 4: 下载视频 curl -o output.mp4 "http://localhost:9297/api/ppt-to-video/download/{task_id}" ``` --- ## 项目结构 ``` Document2Video/ ├── pptagent/ # 核心 PPT 生成引擎 │ ├── agent.py # Agent 抽象层 │ ├── apis.py # PPT 编辑 API + CodeExecutor │ ├── induct.py # 模板分析/归纳 │ ├── llms.py # LLM 接口层 │ ├── model_utils.py # 模型管理 + PDF 解析 │ ├── multimodal.py # 多模态图片分析 │ ├── pptgen.py # PPT 生成器(双引擎支持) │ ├── utils.py # 工具函数 │ ├── document/ # 文档模型 (Document/Section/SubSection/Media) │ ├── presentation/ # 幻灯片模型 + 旧布局引擎(兼容保留) │ │ └── layout_engine.py # 旧引擎:7 种布局模式事后调整 │ ├── layout/ # 🆕 Presentation-First 布局引擎(新) │ │ ├── analyzer.py # ContentAnalyzer — 内容分类 │ │ ├── table_analyzer.py # TableAnalyzer — 8 种表格类型 │ │ ├── slide_planner.py # SlidePlanner — 分页/拆分/合并 │ │ ├── decision_engine.py # DecisionEngine — 策略选择 │ │ ├── strategy.py # 10 种显示策略 │ │ ├── table_strategy.py # 7 种表格策略 │ │ ├── chart_strategy.py # 3 种图表策略 │ │ ├── summary_strategy.py # LLM 文本摘要 │ │ ├── adaptive_layout.py # 自适应布局 + 质量评分 │ │ ├── density_analyzer.py # 视觉密度分析 │ │ ├── layout_score.py # 7 维度质量评分 │ │ ├── container.py # Block 容器体系(流式布局) │ │ ├── spacing.py # 统一间距系统 │ │ └── types.py # 核心数据类型 │ ├── research/ # 内容研究子系统 │ ├── roles/ # Agent 角色配置(15 + 4 个新布局角色) │ └── prompts/ # 提示词模板 ├── server/ # 后端服务 │ ├── backend.py # FastAPI 服务器(WebSocket + REST API) │ └── MegaTTS3/ # TTS 语音合成引擎 ├── frontend/ # Vue 3 前端 │ ├── src/ │ │ ├── components/ # Upload, Generate, PptToVideo │ │ └── router/ # 路由配置 │ └── package.json ├── scripts/ # 命令行工具 │ └── run_document_to_video.py ├── resource/templates/ # PPT 模板 ├── test/ # 测试套件 └── docs/ # 文档 ``` --- ## 从 PresentAgent-2 的变更 | 移除 | 保留 | |------|------| | DeepResearch (URL 深度研究) | pptagent 核心引擎 | | InteractionGUI (交互式 Q&A) | 后端 PPT/视频 API | | Stable Diffusion 3 | MegaTTS3 语音合成 | | 外部搜索/抓取服务依赖 | Vue 3 前端界面 | | 评估/基准测试代码 | 命令行流水线 | | 论文子项目代码 | PPT 模板资源 | --- ## 系统要求 | 项目 | 最低配置 | 推荐配置 | |------|---------|---------| | CPU | 8 核 | 16 核+ | | RAM | 32 GB | 64 GB+ | | GPU | NVIDIA 8GB VRAM | NVIDIA 24GB+ VRAM | | 磁盘 | 20 GB | 50 GB+ SSD | | Python | 3.11+ | 3.11+ | | Node.js | 18+ | 20+ | --- ## 文档索引 - [DEPLOYMENT.md](DEPLOYMENT.md) — 完整部署指南 - [API.md](API.md) — API 接口文档 - [ARCHITECTURE.md](ARCHITECTURE.md) — 系统架构与数据流 --- ## License 本项目基于 PresentAgent-2 (Apache 2.0) 提取。原项目引用: ```bibtex @article{wu2026presentagent2, title={PresentAgent-2: Towards Generalist Multimodal Presentation Agents}, author={Wu, Wei and Xu, Ziyang and Zhang, Zeyu and Zhao, Yang and Tang, Hao}, journal={arXiv preprint arXiv:2605.11363}, year={2026} } ```