AIで画像を動かして動画にする

# コード１行で動画を作れる
**HunyuanVideo**と**Wan2.1**を比較する。
この画像を動かしてみる。
![samurai.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/92fc9bcb-49cd-4d54-b4ee-912e9da590c1.jpeg)

補助文は

>"A girl bravely and beautifully swings a sword."
>少女が勇敢に美しく剣を振る。

**HunyuanVideo**
![Mar-14-2025 09-08-48.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/faa08034-732f-46cf-9add-87529415abad.gif)

**Wan2.1**
![Mar-14-2025 09-04-45.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/235259/01ed7155-08ec-4ab3-bfe6-1575db9bce1b.gif)

https://huggingface.co/Wan-AI/Wan2.1-I2V-14B-720P

https://huggingface.co/tencent/HunyuanVideo-I2V

# 使い方

## Wan2.1 I2V

#### インストール

```shell
git clone https://github.com/Wan-Video/Wan2.1.git
cd Wan2.1
# Ensure torch >= 2.4.0
pip install -r requirements.txt
pip install "huggingface_hub[cli]"
huggingface-cli download Wan-AI/Wan2.1-I2V-14B-720P --local-dir ./Wan2.1-I2V-14B-720P
```

#### 実行

```shell
python generate.py --task i2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-I2V-14B-720P --image examples/samurai.jpg --prompt "A young girl bravely and beautifully swings a sword."
```


## HunyuanVideo I2V

#### インストール

```shell
git clone https://github.com/tencent/HunyuanVideo-I2V
cd HunyuanVideo-I2V
# 1. Create conda environment
conda create -n HunyuanVideo-I2V python==3.11.9

# 2. Activate the environment
conda activate HunyuanVideo-I2V

# 3. Install PyTorch and other dependencies using conda
# For CUDA 12.4
conda install pytorch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 pytorch-cuda=12.4 -c pytorch -c nvidia

# 4. Install pip dependencies
python -m pip install -r requirements.txt

# 5. Install flash attention v2 for acceleration (requires CUDA 11.8 or above)
python -m pip install ninja
python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.6.3

python -m pip install "huggingface_hub[cli]"
# Switch to the directory named 'HunyuanVideo-I2V'
cd /workspace/HunyuanVideo-I2V
# Use the huggingface-cli tool to download HunyuanVideo-I2V model in HunyuanVideo-I2V/ckpts dir.
huggingface-cli download tencent/HunyuanVideo-I2V --local-dir ./ckpts
# The download time may vary from 10 minutes to 1 hour depending on network conditions.
cd /workspace/HunyuanVideo-I2V/ckpts

huggingface-cli download tencent/HunyuanVideo-I2V --local-dir ./ckpts
huggingface-cli download xtuner/llava-llama-3-8b-v1_1-transformers --local-dir ./text_encoder_i2v
huggingface-cli download openai/clip-vit-large-patch14 --local-dir ./text_encoder_2
```

```shell
cd /workspace/HunyuanVideo-I2V

python3 sample_image2video.py \
    --prompt "A young girl bravely and beautifully swings a sword." \
    --i2v-image-path samurai.jpg \
    --model HYVideo-T/2 \
    --i2v-mode \
    --i2v-resolution 720p \
    --infer-steps 50 \
    --video-length 129 \
    --flow-reverse \
    --flow-shift 17.0 \
    --seed 0 \
    --embedded-cfg-scale 6.0 \
    --use-cpu-offload \
    --save-path ./results
```

これだけ。

🐣
****
フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

[Twitter](https://twitter.com/JackdeS11)
[Medium](https://medium.com/@rockyshikoku)
[GitHub](https://github.com/john-rocky)