> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/shi-pin-sheng-cheng/hunyuan-video.md).

# Hunyuan Video

在 Clore.ai 上使用腾讯的 Hunyuan Video 生成高质量视频

使用腾讯开源的 Hunyuan Video 生成高质量视频。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 在 CLORE.AI 上租用

1. 访问 [CLORE.AI 市场](https://clore.ai/marketplace)
2. 按 GPU 类型、VRAM 和价格筛选
3. 选择 **按需** （固定费率）或 **竞价** （出价）
4. 配置你的订单：
   * 选择 Docker 镜像
   * 设置端口（SSH 用 TCP，Web UI 用 HTTP）
   * 如有需要，添加环境变量
   * 输入启动命令
5. 选择支付方式： **CLORE**, **BTC**，或 **USDT/USDC**
6. 创建订单并等待部署

### 访问你的服务器

* 在以下位置查找连接信息 **我的订单**
* Web 界面：使用 HTTP 端口 URL
* SSH： `ssh -p <port> root@<proxy-address>`

## 什么是 Hunyuan Video？

腾讯的 Hunyuan Video 提供：

* 高质量文本生成视频
* 5 秒以上的视频片段
* 720p 分辨率
* 开源且可商用

## 资源

* **模型：** [tencent/HunyuanVideo](https://huggingface.co/tencent/HunyuanVideo)
* **GitHub：** [Tencent/HunyuanVideo](https://github.com/Tencent/HunyuanVideo)
* **论文：** [HunyuanVideo 论文](https://arxiv.org/abs/2412.03603)

## 推荐硬件

| 组件  | 最低            | 推荐         | 最佳         |
| --- | ------------- | ---------- | ---------- |
| GPU | RTX 4090 24GB | A100 40GB  | A100 80GB  |
| 显存  | 24GB          | 40GB       | 80GB       |
| CPU | 8 核           | 16 核       | 32 核       |
| 内存  | 32GB          | 64GB       | 128GB      |
| 存储  | 100GB NVMe    | 200GB NVMe | 500GB NVMe |
| 网络  | 500 Mbps      | 1 Gbps     | 1 Gbps     |

## 在 CLORE.AI 上快速部署

**Docker 镜像：**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**端口：**

```
22/tcp
7860/http
```

**命令：**

```bash
git clone https://github.com/Tencent/HunyuanVideo.git && \
cd HunyuanVideo && \
pip install -r requirements.txt && \
python sample_video.py --prompt "一只猫在花园里散步"
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 安装

```bash
git clone https://github.com/Tencent/HunyuanVideo.git
cd HunyuanVideo
pip install -r requirements.txt

# 下载模型
python download_models.py
```

## 你可以创建什么

### 营销内容

* 产品展示视频
* 社交媒体短视频
* 宣传动画

### 创意项目

* 音乐视频概念
* 短片原型
* 艺术装置

### 教育与培训

* 讲解视频草稿
* 培训材料概念
* 概念可视化

## 基础用法

```python
import torch
from diffusers import HunyuanVideoPipeline
from diffusers.utils import export_to_video

pipe = HunyuanVideoPipeline.from_pretrained(
    "tencent/HunyuanVideo",
    torch_dtype=torch.float16
)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()

prompt = "一只雄伟的鹰翱翔在白雪覆盖的群山之上，电影级光照，4K"

video_frames = pipe(
    prompt=prompt,
    num_frames=45,
    num_inference_steps=50,
    guidance_scale=7.0
).frames[0]

export_to_video(video_frames, "eagle.mp4", fps=15)
```

## 高级生成

```python
import torch
from diffusers import HunyuanVideoPipeline
from diffusers.utils import export_to_video

pipe = HunyuanVideoPipeline.from_pretrained(
    "tencent/HunyuanVideo",
    torch_dtype=torch.float16
)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()

video_frames = pipe(
    prompt="花朵绽放的延时摄影，微距摄影，细节丰富的花瓣",
    negative_prompt="模糊、低质量、失真、难看",
    num_frames=45,
    height=544,
    width=960,
    num_inference_steps=50,
    guidance_scale=7.0,
    generator=torch.Generator("cuda").manual_seed(42)
).frames[0]

export_to_video(video_frames, "flower_bloom.mp4", fps=15)
```

## 提示词示例

### 自然与风景

```python
prompts = [
    "极光在冰封湖面上翩翩起舞，延时摄影，空灵",
    "海浪拍打火山黑沙滩，慢动作",
    "麦田上空的雷暴，戏剧性光照，4K",
    "樱花飘落在日本庭园中，春天，宁静"
]
```

### 科幻与奇幻

```python
prompts = [
    "一艘宇宙飞船从未来城市发射升空，电影感，细节丰富",
    "巨龙在日落时分穿过云层飞行，史诗感，奇幻",
    "机器人行走在霓虹灯照亮的街道上，赛博朋克，雨中",
    "古老森林中开启的魔法传送门，神秘光芒"
]
```

### 抽象与艺术

```python
prompts = [
    "墨滴在水中扩散，微距，色彩斑斓，抽象",
    "几何形状变形与转换，动态图形",
    "黑暗中的光绘，长曝光效果，绚丽"
]
```

## 批量生成

```python
import os
import torch
from diffusers import HunyuanVideoPipeline
from diffusers.utils import export_to_video

pipe = HunyuanVideoPipeline.from_pretrained("tencent/HunyuanVideo", torch_dtype=torch.float16)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()

prompts = [
    "色彩斑斓的鱼群在水下珊瑚礁中游动",
    "夜晚城市交通延时摄影，光轨",
    "蝴蝶破茧而出，自然纪录片"
]

output_dir = "./videos"
os.makedirs(output_dir, exist_ok=True)

for i, prompt in enumerate(prompts):
    print(f"正在生成 {i+1}/{len(prompts)}: {prompt[:50]}...")

    video_frames = pipe(
        prompt=prompt,
        num_frames=45,
        num_inference_steps=50,
        guidance_scale=7.0
    ).frames[0]

    export_to_video(video_frames, f"{output_dir}/video_{i:03d}.mp4", fps=15)
```

## Gradio 界面

```python
import gradio as gr
import torch
from diffusers import HunyuanVideoPipeline
from diffusers.utils import export_to_video
import tempfile

pipe = HunyuanVideoPipeline.from_pretrained("tencent/HunyuanVideo", torch_dtype=torch.float16)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()

def generate(prompt, negative_prompt, num_frames, steps, guidance, seed):
    generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None

    video_frames = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_frames=num_frames,
        num_inference_steps=steps,
        guidance_scale=guidance,
        generator=generator
    ).frames[0]

    with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f:
        export_to_video(video_frames, f.name, fps=15)
        return f.name

demo = gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label="提示词", lines=3),
        gr.Textbox(label="反向提示词", value="模糊，低质量"),
        gr.Slider(16, 60, value=45, step=1, label="帧数"),
        gr.Slider(20, 100, value=50, step=5, label="步数"),
        gr.Slider(3, 12, value=7, step=0.5, label="引导"),
        gr.Number(value=-1, label="种子")
    ],
    outputs=gr.Video(label="生成的视频"),
    title="Hunyuan Video - CLORE.AI 上的文本生成视频"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## 性能

| 分辨率      | 帧数 | GPU       | 时间     |
| -------- | -- | --------- | ------ |
| 544x960  | 45 | RTX 4090  | \~5 分钟 |
| 544x960  | 45 | A100 40GB | \~3 分钟 |
| 544x960  | 45 | A100 80GB | \~2 分钟 |
| 720x1280 | 45 | A100 80GB | \~4 分钟 |

## 常见问题与解决方案

### 内存不足

**问题：** 24GB GPU 上 CUDA 显存不足

**解决方案：**

```python

# 启用所有内存优化
pipe.enable_model_cpu_offload()
pipe.enable_sequential_cpu_offload()  # 更激进
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()

# 减少帧数和分辨率
video = pipe(prompt, num_frames=24, height=480, width=720).frames[0]
```

### 生成缓慢

**问题：** 生成耗时过长

**解决方案：**

* 减少 `推理步数` （30-40 仍能获得良好结果）
* 减少 `num_frames` （24 帧 = 15fps 下 1.6 秒）
* 使用 A100 GPU 以加快处理速度
* 确保你有用于模型加载的 NVMe 存储

### 视频质量差

**问题：** 模糊或不连贯的运动

**解决方案：**

* 增大 `推理步数` 到 75-100
* 调整 `guidance_scale` （6-8 效果最佳）
* 编写更详细的提示词
* 添加反向提示词以避免问题

### 视频伪影

**问题：** 闪烁或时间一致性问题

**解决方案：**

* 使用一致的种子以确保可复现
* 避免使用包含快速运动的提示词
* 通过视频稳定化进行后处理

## 故障排查

{% hint style="danger" %}
**内存不足**
{% endhint %}

* Hunyuan 至少需要 24GB+ VRAM
* 使用 A100 40GB/80GB 以获得最佳效果
* 降低视频长度/分辨率

### 视频生成失败

* 检查所有模型文件是否已正确下载
* 确保有足够的磁盘空间（100GB+）
* 验证 CUDA 与 PyTorch 的兼容性

### 视频质量差

* 增加推理步数
* 使用更具描述性的提示词
* 检查输入分辨率是否符合预期

### 生成缓慢

* 视频生成计算开销很大
* 使用 A100/H100 以获得更快结果
* 先考虑较短的片段

## 成本估算

CLORE.AI 市场常见费率（截至 2024 年）：

| GPU       | 小时费率    | 日费率     | 4 小时会话  |
| --------- | ------- | ------- | ------- |
| RTX 3060  | \~$0.03 | \~$0.70 | \~$0.12 |
| RTX 3090  | \~$0.06 | \~$1.50 | \~$0.25 |
| RTX 4090  | \~$0.10 | \~$2.30 | \~$0.40 |
| A100 40GB | \~$0.17 | \~$4.00 | \~$0.70 |
| A100 80GB | \~$0.25 | \~$6.00 | \~$1.00 |

*价格因提供商和需求而异。请查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *以获取当前费率。*

**节省费用：**

* 使用 **竞价** 可中断工作市场——约三分之一的服务器将现货价格定得低于按需价格（中位数约优惠 13%），其余则与按需价格持平
* 使用 **CLORE** 代币支付
* 比较不同提供商的价格

## 下一步

* CogVideoX - 其他文本生成视频方案
* Wan2.1 Video - 另一种文本生成视频选项
* AnimateDiff - 图像动画


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
