# FramePack 视频生成

FramePack 是 AI 视频生成方面的突破：它可以使用 **仅 6GB 显存**创建长达 2 分钟的视频。基于混元视频（HunyuanVideo）架构，FramePack 的关键创新是高效地打包帧，使 GPU 内存与视频长度无关地保持恒定。这使得以前显存不足的入门级显卡也能进行 AI 视频生成。

## 主要特性

* **最低 6GB 显存**：可在 RTX 3060、RTX 3070，甚至 GTX 1060 上运行！
* **最多 2 分钟视频**：无论视频长度，显存占用恒定
* **图像到视频**：使用文本提示为任何图像制作动画
* **包含 Web 界面**：基于 Gradio 的界面，易于使用
* **基于 HunyuanVideo 构建**：利用腾讯的视频扩散架构
* **开源**：GitHub 上有活跃开发

## 要求

| 组件     | 最低           | 推荐            |
| ------ | ------------ | ------------- |
| GPU    | GTX 1060 6GB | RTX 4090 24GB |
| 显存     | 6GB          | 12GB+         |
| 内存     | 16GB         | 32GB          |
| 磁盘     | 30GB         | 50GB          |
| CUDA   | 11.8+        | 12.0+         |
| Python | 3.10+        | 3.11          |

**推荐的 Clore.ai GPU**：RTX 3080 10GB（约 $0.2–0.5/天）— 低成本下的高质量选择！

### 速度参考

| GPU           | 每帧时间   | 60 帧视频（约 30fps 时 \~2 秒） |
| ------------- | ------ | ----------------------- |
| RTX 3060 12GB | \~30 秒 | \~30 分钟                 |
| RTX 3080 10GB | \~18 秒 | \~18 分钟                 |
| RTX 4080 16GB | ≈12 秒  | \~12 分钟                 |
| RTX 4090 24GB | ≈8 秒   | \~8 分钟                  |
| RTX 5090 32GB | \~5 秒  | 约 5 分钟                  |

## 安装

```bash
# 克隆仓库
git clone https://github.com/lllyasviel/FramePack.git
cd FramePack

# 创建 conda 环境（推荐）
conda create -n framepack python=3.11 -y
conda activate framepack

# 安装依赖
pip install -r requirements.txt

# 安装带 CUDA 的 PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
```

### Docker 设置

```bash
docker run --gpus all -p 7860:7860 \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  -v ./outputs:/app/outputs \
  ghcr.io/lllyasviel/framepack:latest
```

## 快速开始 — Web 界面

使用 FramePack 的最简单方法：

```bash
cd FramePack
python app.py --port 7860

# 对于低显存（6GB）：
python app.py --port 7860 --low-vram

# 在 http://localhost:7860 访问
```

**Web 界面工作流程：**

1. 上传一张源图像（作为第一帧）
2. 输入描述动作的文本提示（“相机慢慢拉近”、“人物向前走”）
3. 设置视频长度（帧数）
4. 点击生成
5. 下载 MP4

## 用法

FramePack 是一个 **Gradio 网络应用**，不是一个 Python 库。主要界面是网页 UI。

### Web 界面工作流程

1. 打开 `http://localhost:7860` 启动后
2. 上传一张源图像（将作为第一帧）
3. 输入描述所需动作的文本提示
4. 设置帧数（更多 = 更长的视频）
5. 点击 **生成** → 等待 → 下载 MP4

### 通过 Gradio Client 访问 API

你可以使用 Gradio API 以编程方式调用 FramePack：

```python
from gradio_client import Client

# 连接到正在运行的 FramePack 实例
client = Client("http://localhost:7860")

# 从图像 + 提示生成视频
result = client.predict(
    "input_photo.jpg",                              # 源图像
    "the person smiles and turns their head slowly", # 提示
    60,                                              # 帧数
    7.5,                                             # 引导尺度
    30,                                              # 推理步数
    42,                                              # 随机种子
    api_name="/generate"
)
print(f"Video saved to: {result}")
```

### 使用 Gradio Client 批处理

```python
from gradio_client import Client
import glob

client = Client("http://localhost:7860")

prompts = [
    ("photo1.jpg", "gentle camera zoom with soft lighting"),
    ("photo2.jpg", "wind blowing through hair, clouds moving"),
    ("photo3.jpg", "slow zoom out revealing the full scene"),
]

for img_path, prompt in prompts:
    result = client.predict(img_path, prompt, 60, 7.5, 30, -1, api_name="/generate")
    print(f"Done: {img_path} → {result}")
```

## 分辨率指南

| 显存   | 最大分辨率    | 质量     |
| ---- | -------- | ------ |
| 6GB  | 512×512  | 适合社交媒体 |
| 8GB  | 640×640  | 更好细节   |
| 10GB | 512×768  | 竖向/横向  |
| 12GB | 768×768  | 高质量    |
| 24GB | 1024×768 | 最佳质量   |

## 给 Clore.ai 用户的提示

* **预算友好**：这是少数可在低价显卡上运行的视频 AI 模型之一（RTX 3060 每天约 $0.15–0.3！）
* **使用 `--low-vram` 标志**：对 6–8GB 显卡至关重要 — 自动启用 CPU 卸载
* **512×512 就可以**：对于社交媒体（TikTok、Reels），512px 完全可接受
* **更长 ≠ 更高显存**：与其他视频模型不同，FramePack 保持显存恒定 — 可自由生成更长的视频
* **预先下载模型**：首次运行会下载约 15GB。运行一次后，你的 Colab 会话将缓存模型
* **与放大结合使用**：先以 512×512 生成，然后使用 Real-ESRGAN 放大到 2K/4K

## 提示技巧

好的提示应描述 **动作**，而不仅仅是外观：

```
✅ "相机慢慢向右平移，展现山地风光"
✅ "此人眨眼并微笑，风吹动他们的头发"
✅ "慢慢缩小画面，展示整栋建筑"

❌ "一幅美丽的日落"（未描述动作）
❌ "高质量、4K、细节丰富"（风格词对动作帮助不大）
```

## # 使用固定种子以获得一致结果

| 问题                       | 解决方案                                                |
| ------------------------ | --------------------------------------------------- |
| CUDA 内存不足（out of memory） | 使用 `--low-vram` 标志，降低分辨率到 512×512                   |
| 生成非常慢                    | 对 6GB 显卡是正常的（\~30s/帧）。使用 RTX 4090 可提速 4 倍           |
| 黑屏/损坏的帧                  | 更新 PyTorch： `pip install torch --upgrade`           |
| 模型下载卡住                   | 检查磁盘空间（需要 30GB 可用）。尝试 `HF_HUB_ENABLE_HF_TRANSFER=1` |
| Web 界面无法启动               | 检查端口 7860 是否空闲： `lsof -i :7860`                     |

## 延伸阅读

* [GitHub 仓库](https://github.com/lllyasviel/FramePack)
* [混元视频（HunyuanVideo，基础模型）](https://github.com/Tencent/HunyuanVideo)
* [Clore.ai GPU 对比](/guides/guides_v2-zh/kai-shi-shi-yong/gpu-comparison.md) — 找到最适合你需求的最便宜显卡


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/shi-pin-sheng-cheng/framepack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
