# Hunyuan Video

Generate high-quality videos with Tencent's open-source Hunyuan Video.

{% hint style="success" %}
All examples can be run on GPU servers rented through [CLORE.AI Marketplace](https://clore.ai/marketplace).
{% endhint %}

## Renting on CLORE.AI

1. Visit [CLORE.AI Marketplace](https://clore.ai/marketplace)
2. Filter by GPU type, VRAM, and price
3. Choose **On-Demand** (fixed rate) or **Spot** (bid price)
4. Configure your order:
   * Select Docker image
   * Set ports (TCP for SSH, HTTP for web UIs)
   * Add environment variables if needed
   * Enter startup command
5. Select payment: **CLORE**, **BTC**, or **USDT/USDC**
6. Create order and wait for deployment

### Access Your Server

* Find connection details in **My Orders**
* Web interfaces: Use the HTTP port URL
* SSH: `ssh -p <port> root@<proxy-address>`

## What is Hunyuan Video?

Hunyuan Video from Tencent offers:

* High-quality text-to-video generation
* 5+ second video clips
* 720p resolution
* Open-source and commercially usable

## Resources

* **Model:** [tencent/HunyuanVideo](https://huggingface.co/tencent/HunyuanVideo)
* **GitHub:** [Tencent/HunyuanVideo](https://github.com/Tencent/HunyuanVideo)
* **Paper:** [HunyuanVideo Paper](https://arxiv.org/abs/2412.03603)

## Recommended Hardware

| Component | Minimum       | Recommended | Optimal    |
| --------- | ------------- | ----------- | ---------- |
| GPU       | RTX 4090 24GB | A100 40GB   | A100 80GB  |
| VRAM      | 24GB          | 40GB        | 80GB       |
| CPU       | 8 cores       | 16 cores    | 32 cores   |
| RAM       | 32GB          | 64GB        | 128GB      |
| Storage   | 100GB NVMe    | 200GB NVMe  | 500GB NVMe |
| Internet  | 500 Mbps      | 1 Gbps      | 1 Gbps     |

## Quick Deploy on CLORE.AI

**Docker Image:**

```
pytorch/pytorch:2.5.1-cuda12.4-cudnn9-devel
```

**Ports:**

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

**Command:**

```bash
git clone https://github.com/Tencent/HunyuanVideo.git && \
cd HunyuanVideo && \
pip install -r requirements.txt && \
python sample_video.py --prompt "A cat walking in a garden"
```

## Accessing Your Service

After deployment, find your `http_pub` URL in **My Orders**:

1. Go to **My Orders** page
2. Click on your order
3. Find the `http_pub` URL (e.g., `abc123.clorecloud.net`)

Use `https://YOUR_HTTP_PUB_URL` instead of `localhost` in examples below.

## Installation

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

# Download models
python download_models.py
```

## What You Can Create

### Marketing Content

* Product showcase videos
* Social media clips
* Promotional animations

### Creative Projects

* Music video concepts
* Short film prototypes
* Art installations

### Education & Training

* Explainer video drafts
* Training material concepts
* Visualization of concepts

## Basic Usage

```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 = "A majestic eagle soaring over snow-capped mountains, cinematic lighting, 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)
```

## Advanced Generation

```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="Time-lapse of a flower blooming, macro photography, detailed petals",
    negative_prompt="blurry, low quality, distorted, ugly",
    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)
```

## Prompt Examples

### Nature & Landscapes

```python
prompts = [
    "Aurora borealis dancing over a frozen lake, time-lapse, ethereal",
    "Ocean waves crashing on volcanic black sand beach, slow motion",
    "Thunderstorm over a wheat field, dramatic lighting, 4K",
    "Cherry blossoms falling in a Japanese garden, spring, peaceful"
]
```

### Sci-Fi & Fantasy

```python
prompts = [
    "Spaceship launching from a futuristic city, cinematic, detailed",
    "Dragon flying through clouds at sunset, epic, fantasy",
    "Robot walking through neon-lit streets, cyberpunk, rain",
    "Magical portal opening in an ancient forest, mystical lights"
]
```

### Abstract & Artistic

```python
prompts = [
    "Ink drops diffusing in water, macro, colorful, abstract",
    "Geometric shapes morphing and transforming, motion graphics",
    "Light painting in darkness, long exposure effect, vibrant"
]
```

## Batch Generation

```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 = [
    "Underwater coral reef with colorful fish swimming",
    "City traffic time-lapse at night, light trails",
    "Butterfly emerging from cocoon, nature documentary"
]

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

for i, prompt in enumerate(prompts):
    print(f"Generating {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 Interface

```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="Prompt", lines=3),
        gr.Textbox(label="Negative Prompt", value="blurry, low quality"),
        gr.Slider(16, 60, value=45, step=1, label="Frames"),
        gr.Slider(20, 100, value=50, step=5, label="Steps"),
        gr.Slider(3, 12, value=7, step=0.5, label="Guidance"),
        gr.Number(value=-1, label="Seed")
    ],
    outputs=gr.Video(label="Generated Video"),
    title="Hunyuan Video - Text to Video on CLORE.AI"
)

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

## Performance

| Resolution | Frames | GPU       | Time    |
| ---------- | ------ | --------- | ------- |
| 544x960    | 45     | RTX 4090  | \~5 min |
| 544x960    | 45     | A100 40GB | \~3 min |
| 544x960    | 45     | A100 80GB | \~2 min |
| 720x1280   | 45     | A100 80GB | \~4 min |

## Common Problems & Solutions

### Out of Memory

**Problem:** CUDA out of memory on 24GB GPU

**Solutions:**

```python

# Enable all memory optimizations
pipe.enable_model_cpu_offload()
pipe.enable_sequential_cpu_offload()  # More aggressive
pipe.vae.enable_tiling()
pipe.vae.enable_slicing()

# Reduce frames and resolution
video = pipe(prompt, num_frames=24, height=480, width=720).frames[0]
```

### Slow Generation

**Problem:** Takes too long to generate

**Solutions:**

* Reduce `num_inference_steps` (30-40 still gives good results)
* Reduce `num_frames` (24 frames = 1.6s at 15fps)
* Use A100 GPU for faster processing
* Ensure you have NVMe storage for model loading

### Poor Video Quality

**Problem:** Blurry or inconsistent motion

**Solutions:**

* Increase `num_inference_steps` to 75-100
* Adjust `guidance_scale` (6-8 works best)
* Write more detailed prompts
* Add negative prompts to avoid issues

### Video Artifacts

**Problem:** Flickering or temporal inconsistencies

**Solutions:**

* Use consistent seed for reproducibility
* Avoid prompts with rapid motion
* Post-process with video stabilization

## Troubleshooting

{% hint style="danger" %}
**Out of memory**
{% endhint %}

* Hunyuan requires 24GB+ VRAM minimum
* Use A100 40GB/80GB for best results
* Reduce video length/resolution

### Video generation fails

* Check all model files downloaded correctly
* Ensure enough disk space (100GB+)
* Verify CUDA and PyTorch compatibility

### Poor video quality

* Increase inference steps
* Use more descriptive prompts
* Check input resolution matches expected

### Slow generation

* Video generation is compute-intensive
* Use A100/H100 for faster results
* Consider shorter clips first

## Cost Estimate

Typical CLORE.AI marketplace rates (as of 2024):

| GPU       | Hourly Rate | Daily Rate | 4-Hour Session |
| --------- | ----------- | ---------- | -------------- |
| 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        |

*Prices vary by provider and demand. Check* [*CLORE.AI Marketplace*](https://clore.ai/marketplace) *for current rates.*

**Save money:**

* Use **Spot** market for flexible workloads (often 30-50% cheaper)
* Pay with **CLORE** tokens
* Compare prices across different providers

## Next Steps

* CogVideoX - Alternative T2V
* Wan2.1 Video - Another T2V option
* AnimateDiff - Image animation
