使用通义万相Wan2.1进行视频生成

article/2025/7/29 5:30:29

使用通义万相Wan2.1进行视频生成

  • 源代码准备
  • 运行环境准备
    • 创建Python虚拟环境并激活
    • 安装依赖包
  • 模型下载
  • 生成视频
    • 官网的视频生成例子
    • 简单描述场景视频生成示例
    • 详细描述场景视频生成示例

最近通义万相开源了其视频生成模型。模型有两个版本,一个是1.3B的,一个是14B的。对于1.3B的版本,模型大小约17G,14B的版本模型大小约70G。由于显存限制,下面测试了1.3B版本的文生视频。

总体来说,1.3B的版本,实测的视频生成内容,还是有些粗糙,也许1.3B的版本,只是用于让大家熟悉和学习的。小伙伴们如果有条件的,可以测试一下14B的视频生成结果。

下面是我测试过程的一些记录,供大家参考。

源代码准备

git clone https://github.com/Wan-Video/Wan2.1.git
(base) ubuntu@ubuntu-server:~/code$ git clone https://github.com/Wan-Video/Wan2.1.git
Cloning into 'Wan2.1'...
remote: Enumerating objects: 89, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 89 (delta 13), reused 7 (delta 5), pack-reused 70 (from 1)
Receiving objects: 100% (89/89), 5.74 MiB | 1.68 MiB/s, done.
Resolving deltas: 100% (29/29), done.
(base) ubuntu@ubuntu-server:~/code$ 

运行环境准备

创建Python虚拟环境并激活

conda create -n wan python=3.10
conda activate wan

安装依赖包

pip install -r requirements.txt

安装后的依赖包信息

(wan) ubuntu@ubuntu-server:~$ pip list
Package                  Version
------------------------ -----------
accelerate               1.4.0
aiofiles                 23.2.1
aiohappyeyeballs         2.4.6
aiohttp                  3.11.13
aiosignal                1.3.2
annotated-types          0.7.0
anyio                    4.8.0
async-timeout            5.0.1
attrs                    25.1.0
certifi                  2025.1.31
charset-normalizer       3.4.1
click                    8.1.8
dashscope                1.22.1
diffusers                0.32.2
easydict                 1.13
einops                   0.8.1
exceptiongroup           1.2.2
fastapi                  0.115.8
ffmpy                    0.5.0
filelock                 3.17.0
flash_attn               2.7.4.post1
frozenlist               1.5.0
fsspec                   2025.2.0
ftfy                     6.3.1
gradio                   5.19.0
gradio_client            1.7.2
h11                      0.14.0
httpcore                 1.0.7
httpx                    0.28.1
huggingface-hub          0.29.1
idna                     3.10
imageio                  2.37.0
imageio-ffmpeg           0.6.0
importlib_metadata       8.6.1
Jinja2                   3.1.5
markdown-it-py           3.0.0
MarkupSafe               2.1.5
mdurl                    0.1.2
modelscope               1.23.1
mpmath                   1.3.0
multidict                6.1.0
networkx                 3.4.2
numpy                    1.26.4
nvidia-cublas-cu12       12.4.5.8
nvidia-cuda-cupti-cu12   12.4.127
nvidia-cuda-nvrtc-cu12   12.4.127
nvidia-cuda-runtime-cu12 12.4.127
nvidia-cudnn-cu12        9.1.0.70
nvidia-cufft-cu12        11.2.1.3
nvidia-curand-cu12       10.3.5.147
nvidia-cusolver-cu12     11.6.1.9
nvidia-cusparse-cu12     12.3.1.170
nvidia-cusparselt-cu12   0.6.2
nvidia-nccl-cu12         2.21.5
nvidia-nvjitlink-cu12    12.4.127
nvidia-nvtx-cu12         12.4.127
opencv-python            4.11.0.86
orjson                   3.10.15
packaging                24.2
pandas                   2.2.3
pillow                   11.1.0
pip                      25.0
propcache                0.3.0
psutil                   7.0.0
pydantic                 2.10.6
pydantic_core            2.27.2
pydub                    0.25.1
Pygments                 2.19.1
python-dateutil          2.9.0.post0
python-multipart         0.0.20
pytz                     2025.1
PyYAML                   6.0.2
regex                    2024.11.6
requests                 2.32.3
rich                     13.9.4
ruff                     0.9.7
safehttpx                0.1.6
safetensors              0.5.3
semantic-version         2.10.0
setuptools               75.8.0
shellingham              1.5.4
six                      1.17.0
sniffio                  1.3.1
starlette                0.45.3
sympy                    1.13.1
tokenizers               0.21.0
tomlkit                  0.13.2
torch                    2.6.0
torchvision              0.21.0
tqdm                     4.67.1
transformers             4.49.0
triton                   3.2.0
typer                    0.15.1
typing_extensions        4.12.2
tzdata                   2025.1
urllib3                  2.3.0
uvicorn                  0.34.0
wcwidth                  0.2.13
websocket-client         1.8.0
websockets               15.0
wheel                    0.45.1
yarl                     1.18.3
zipp                     3.21.0
(wan) ubuntu@ubuntu-server:~$ 

说明:

在安装flash_attn时,可能出现错误,多次尝试也不能完成。可以先在requirements.txt中先注释掉flash_attn,安装完成后,再单独安装flash_attn即可。

模型下载

下载地址

https://www.modelscope.cn/models/Wan-AI/Wan2.1-T2V-1.3B

使用modelscope客户端下载模型文件

pip install modelscopecd /home/ubuntu/code/Wan2.1modelscope download --model Wan-AI/Wan2.1-T2V-1.3B README.md --local_dir ./Wan2.1-T2V-1.3B

生成视频

官网的视频生成例子

python generate.py  --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."

python generate.py  --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --offload_model True --t5_cpu --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."

演示如下:

(wan) ubuntu@ubuntu-server:~/code/Wan2.1$ export CUDA_VISIBLE_DEVICES=1
(wan) ubuntu@ubuntu-server:~/code/Wan2.1$ python generate.py  --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage."
[2025-02-28 09:44:02,400] INFO: offload_model is not specified, set to True.
[2025-02-28 09:44:02,400] INFO: Generation job args: Namespace(task='t2v-1.3B', size='832*480', frame_num=81, ckpt_dir='./Wan2.1-T2V-1.3B', offload_model=True, ulysses_size=1, ring_size=1, t5_fsdp=False, t5_cpu=False, dit_fsdp=False, save_file=None, prompt='Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage.', use_prompt_extend=False, prompt_extend_method='local_qwen', prompt_extend_model=None, prompt_extend_target_lang='ch', base_seed=1470089367940419568, image=None, sample_solver='unipc', sample_steps=50, sample_shift=8.0, sample_guide_scale=6.0)
[2025-02-28 09:44:02,400] INFO: Generation model config: {'__name__': 'Config: Wan T2V 1.3B', 't5_model': 'umt5_xxl', 't5_dtype': torch.bfloat16, 'text_len': 512, 'param_dtype': torch.bfloat16, 'num_train_timesteps': 1000, 'sample_fps': 16, 'sample_neg_prompt': '色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量 ,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走', 't5_checkpoint': 'models_t5_umt5-xxl-enc-bf16.pth', 't5_tokenizer': 'google/umt5-xxl', 'vae_checkpoint': 'Wan2.1_VAE.pth', 'vae_stride': (4, 8, 8), 'patch_size': (1, 2, 2), 'dim': 1536, 'ffn_dim': 8960, 'freq_dim': 256, 'num_heads': 12, 'num_layers': 30, 'window_size': (-1, -1), 'qk_norm': True, 'cross_attn_norm': True, 'eps': 1e-06}
[2025-02-28 09:44:02,400] INFO: Input prompt: Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage.
[2025-02-28 09:44:02,400] INFO: Creating WanT2V pipeline.

视频生成时,大约占用20G的显存空间。
在这里插入图片描述

用时4分12秒,完成视频的生成。
在这里插入图片描述

视频内容如下:

CSDN对视频审核不过,不知道为什么,以gif显示。

在这里插入图片描述

截图如下:

在这里插入图片描述

简单描述场景视频生成示例

简单描述一个场景,使用百度翻译为英文。

一个人晚上开着保时捷在城市的道路上,周围是五光十色的广告和灯光。摄像头是驾驶员位置,光圈4.5,用于虚化周围的楼房和行人,汽车等。A person is driving a Porsche on the city road at night, surrounded by colorful advertisements and lights. The camera is located at the driver's position with an aperture of 4.5, used to blur surrounding buildings, pedestrians, cars, etc.

运行视频生成程序

python generate.py  --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "A person is driving a Porsche on the city road at night, surrounded by colorful advertisements and lights. The camera is located at the driver's position with an aperture of 4.5, used to blur surrounding buildings, pedestrians, cars, etc."

大概4分钟后,生成视频文件。
在这里插入图片描述

视频生成文件如下:

CSDN对视频审核不过,不知道为什么,使用GIF显示。

在这里插入图片描述

截图如下:

在这里插入图片描述

详细描述场景视频生成示例

使用大模型生成视频描述,加入更多细节。

使用deepseek,扩写生成视频的描述文字。

将下面的场景内容扩写到500字,加入更多的细节描述,并保持场景不变,用于视频生成的描述。场景内容如下:一个人晚上开着保时捷在城市的道路上,周围是五光十色的广告和灯光。摄像头是驾驶员位置,光圈4.5,用于虚化周围的楼房和行人,汽车等。

生成内容如下:

【视频场景描述 - 夜驰光影】镜头以第一人称视角透过保时捷911 Carrera的挡风玻璃展开。仪表盘泛着宝石蓝的冷光,数字时速表在87km/h轻微震颤,转速表红色指针在4000转区域规律摆动。驾驶者戴着黑色鳄鱼皮手套的双手虚搭在Alcantara麂皮方向盘三点九点位置,左腕的铂金腕表在仪表背光中偶尔闪过金属寒光。车窗外,霓虹光流在光圈f/4.5的虚化下融化成斑斓的星轨。右侧商业街的LED巨幕正轮播着香水广告,克里斯汀·斯图尔特的面容在动态模糊中化作粉色与银白的光瀑。后视镜里,追逐的出租车顶灯在浅景深中晕染成跳动的朱红色光斑,如同都市丛林里躁动的萤火虫群。皮革缝线座椅随着过弯微微变形,能清晰看见Nappa真皮表面细小的毛孔纹路。空调出风口飘散着雪松香氛,混着方向盘后侧杯架里半杯威士忌的泥煤气息。转速突然攀升时,水平对置六缸引擎的低吼透过碳纤维车架传来,像远处闷雷滚过云层。22:17分,驶入跨江隧道。隧道壁的条形灯在高速运动中拉成金色光带,顶棚通风口的气流将驾驶者额前碎发吹起,露出被阴影覆盖的眉骨。仪表盘亮度自动调暗的瞬间,后车远光灯在前挡风玻璃上折射出彩虹光晕,如同在暴雨后的挡风玻璃上划开一道棱镜。驶出隧道的刹那,挡风玻璃突然映满璀璨星河——实为金融区摩天楼的玻璃幕墙群,每扇窗户都化作发光的矩阵单元。左侧在建大厦的塔吊亮着警示红灯,在长曝光效果中拖曳出妖冶的光弧。驾驶者左手无意识地摩挲着门把手上保时捷盾徽的浮雕纹路,右手食指在换挡拨片留下转瞬即逝的指纹。特写镜头掠过转速表突然跃升的红色指针,挡风玻璃倒影中可见驾驶者黑色衬衫袖口露出1厘米的苍白手腕。后视镜挂着的平安符在加速度中扬起45度角,金线刺绣的"安全"二字在虚焦中化作两团跃动的光晕。此刻仪表台时钟跳至22:43,车载屏幕导航显示正驶向跨海大桥方向,地图上的蓝色路径线在黑夜中如一道激光切开霓虹海洋。

使用百度翻译,将提示词翻译为英文,并进行视频生成命令。

python generate.py  --task t2v-1.3B --size 832*480 --ckpt_dir ./Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "The camera unfolds through the windshield of the Porsche 911 Carrera from a first person perspective. The dashboard emits a cool gemstone blue light, the digital speedometer vibrates slightly at 87km/h, and the red pointer of the tachometer swings regularly in the 4000 rpm range. The driver's hands, wearing black crocodile leather gloves, were loosely resting on the Alcantara suede steering wheel at the 3:09 o'clock position, and the platinum wristwatch on the left wrist occasionally flashed a metallic cold light in the instrument backlight. Outside the car window, the neon light flow melts into a colorful star track under the blurring of the aperture f/4.5. The LED giant screen on the right side of the commercial street is broadcasting advertisements for perfume. Kristen Stewart's face turns into pink and silver waterfall in dynamic blur. In the rearview mirror, the chasing taxi's overhead lights blend into a pulsating crimson light spot in the shallow depth of field, like a restless firefly swarm in the urban jungle. The leather stitched seat slightly deforms as it bends, and the fine pore patterns on the Nappa leather surface can be clearly seen. The air conditioning vent is filled with the fragrance of cedar, mixed with the peat smell of half a glass of whiskey in the cup holder behind the steering wheel. When the engine speed suddenly increased, the low roar of the horizontally opposed six cylinder engine came through the carbon fiber frame, like thunder rolling through the clouds in the distance. At 22:17, enter the cross river tunnel. The strip lights on the tunnel walls create a golden light strip during high-speed movement, and the airflow from the ceiling vents blows up the driver's broken hair in front of their forehead, revealing the shaded brow bones. At the moment when the brightness of the instrument panel automatically dims, the rear high beam lamp refracts a rainbow halo on the front windshield, just like a prism on the windshield after a rainstorm. At the moment of exiting the tunnel, the windshield suddenly reflected a dazzling galaxy - actually a group of glass curtain walls of the financial district skyscraper, with each window turning into a luminous matrix unit. The tower crane of the building under construction on the left is displaying a warning red light, dragging a seductive arc of light in the long exposure effect. The driver unconsciously rubbed the relief pattern of the Porsche emblem on the door handle with their left hand, and left a fleeting fingerprint on the shift paddles with their right index finger. A close-up shot passes by the red pointer on the tachometer that suddenly jumps, revealing a pale wrist of 1 centimeter on the driver's black shirt sleeve in the reflection of the windshield. The safety symbol hanging on the rearview mirror rises at a 45 degree angle in acceleration, and the gold embroidered word "safety" turns into two jumping halos in virtual focus. At this moment, the dashboard clock jumps to 22:43, and the car screen navigation shows that it is heading towards the direction of the cross sea bridge. The blue path line on the map cuts through the neon ocean like a laser in the dark night."

在这里插入图片描述

视频生成文件:

CSDN对视频审核不过,不知道为什么,用GIF显示。

在这里插入图片描述

截图如下

在这里插入图片描述


http://www.hkcw.cn/article/SSXtxlJmLw.shtml

相关文章

最新扣子(Coze)案例教程:小红书爆款书单推荐视频工作流!3分钟10个爆款视频,文学赛道书籍推荐视频日更必备工具,完全免费教程

大家好,我是斜杠君。 最近,星球群里有做小红书文学赛道的博主咨询,每天都在为制作书单的视频找素材、配背景、配音效等,产出量很低。想看看是否可以通过扣子工作流的方式,只要定制好一个工作流的流程,就可…

uniapp [安卓苹果App端] - 实现获取手机摄像头权限+调用相机拍照或拍视频+保存图片视频到相册,检测权限手机摄像头功能是否开启并引导用户同意授权,uniApp app端调用本机开启摄像头授权

前言 网上的教程乱七八糟且兼容性太差,本文提供优质示例。 在 uni-app App端(安卓APP | 苹果APP)开发中,详解在app平台端实现获取手机摄像头权限查询,有权限则开启本机摄像头完成拍摄或录制视频+保存媒体文件到相册等操作,反之无权限则提示开启摄像头与引导用户授权操作,…

【人工智能】深度学习利用人工智能进行VRT视频修复

目录 一、前提二、VRT的重要性和研究背景2. 1 VRT的背景:2.2 VRT的重要性: 三、视频修复概述3.1 定义与目标3.2 与单图像修复的区别3.3 对时间信息利用的需求 四、VRT模型详解4.1 整体框架4.2 多尺度设计和模块功能4.3 关键创新点 五、实验结果5.1 VRT在…

2024年视频号生态洞察报告 | 友望数据发布

2024年视频号直播带货达人和直播销售数据同步增长,直播电商规模不断扩张。从友望数据品类大盘看,服饰内衣、美妆护肤品类高速增长,电商生态持续繁荣。 微信小店的升级,特别是【送礼物】功能的上线,进一步打通社交与电商…

OpenCV从入门到精通:OpenCV安装、配置、依赖安装、基本语法、常用方法详解

OpenCV从入门到精通:OpenCV安装、配置、依赖安装、基本语法、常用方法详解 引言 OpenCV(Open Source Computer Vision Library)是一个开源的跨平台计算机视觉库,提供了丰富的图像和视频处理算法接口,支持 Python、C、…

瑞芯微 RK 系列 RK3588 使用 ffmpeg-rockchip 实现 MPP 视频硬件编解码-代码版

前言 在上一篇文章中,我们讲解了如何使用 ffmpeg-rockchip 通过命令来实现 MPP 视频硬件编解码和 RGA 硬件图形加速,在这篇文章,我将讲解如何使用 ffmpeg-rockchip 用户空间库(代码)实现 MPP 硬件编解码。 本文不仅适…

【计算机视觉】OpenCV实战项目:基于OpenCV的车牌识别系统深度解析

基于OpenCV的车牌识别系统深度解析 1. 项目概述2. 技术原理与算法设计2.1 图像预处理1) 自适应光照补偿2) 边缘增强 2.2 车牌定位1) 颜色空间筛选2) 形态学操作3) 轮廓分析 2.3 字符分割1) 投影分析2) 连通域筛选 2.4 字符识别 3. 实战部署指南3.1 环境配置3.2 项目代码解析 4.…

2024电赛H题参考方案(+视频演示+核心控制代码)——自动行驶小车

目录 一、题目要求 二、参考资源获取 三、TI板子可能用到的资源 1、环境搭建及工程移植 2、相关模块的移植 四、控制参考方案 1、整体控制方案视频演示 2、视频演示部分核心代码 五、总结 一、题目要求 小编自认为:此次控制类类型题目的H题,相较于往年较…

【开源工具】PyQt6录音神器:高颜值多功能音频录制工具开发全解析

【开源工具】🎙️ PyQt6录音神器:高颜值多功能音频录制工具开发全解析 🌈 个人主页:创客白泽 - CSDN博客 🔥 系列专栏:🐍《Python开源项目实战》 💡 热爱不止于代码,热情…

在PPT中同时自动播放多个视频的方法

在PPT中同时自动播放多个视频的方法 文章目录 在PPT中同时自动播放多个视频的方法1 准备视频2 设置动画为“出现”3 设置所有视频为“自动播放”4 最终效果与其他设置 在PPT制作的过程中,我们经常遇到需要同时自动播放多个视频的情况。本文将详细介绍实现这种效果的…

【智能驱蚊黑科技】基于OpenCV的蚊子雷达追踪打击系统(附完整Python源码)

【智能驱蚊黑科技】基于OpenCV的蚊子雷达追踪打击系统(附完整Python源码) 🌈 个人主页:创客白泽 - CSDN博客 🔥 系列专栏:🐍《Python开源项目实战》 💡 热爱不止于代码,热…

打造沉浸式古诗欣赏页面:HTML5视频背景与音频的完美结合

个人名片 🎓作者简介:java领域优质创作者 🌐个人主页:码农阿豪 📞工作室:新空间代码工作室(提供各种软件服务) 💌个人邮箱:[2435024119qq.com] &#x1f4f1…

Python - 爬虫;Scrapy框架之插件Extensions(四)

阅读本文前先参考 https://blog.csdn.net/MinggeQingchun/article/details/145904572 在 Scrapy 中,扩展(Extensions)是一种插件,允许你添加额外的功能到你的爬虫项目中。这些扩展可以在项目的不同阶段执行,比如启动…

vscode 连接远程服务器

文章目录 1. 背景2. vscode 连接 服务器步骤2.1 安装 remote-ssh 插件2.2 配置 ssh 秘钥2.3 连接 server vscode 连接远程服务器 1. 背景 有服务器的同学,或许都有这样的感觉,服务器是 linux 系统,且只给个人提供一个终端进行连接&#xff0c…

JavaScript 模块系统:CJS/AMD/UMD/ESM

文章目录 前言一、CommonJS (CJS) - Node.js 的同步模块系统1.1 设计背景1.2 浏览器兼容性问题1.3 Webpack 如何转换 CJS1.4 适用场景 二、AMD (Asynchronous Module Definition) - 浏览器异步加载方案2.1 设计背景2.2 为什么现代浏览器不原生支持 AMD2.3 Webpack/Rollup 如何处…

乌称摧毁34%俄远程机队 俄媒否认 谎言蛛网行动

俄罗斯“与假新闻作战”网站发布文章称,通过分析乌克兰方面发布的视频可以确认,乌总统泽连斯基关于“已摧毁34%俄罗斯远程机队”的说法并不属实。俄方认为,乌克兰实际上可能仅摧毁了两架图-95战略轰炸机及一架安-12运输机,其余受损飞机在维修后均可恢复作战能力。乌克兰国家…

加沙停火协议为何一波三折 美斡旋遇阻

本周,美国就巴勒斯坦伊斯兰抵抗运动(哈马斯)和以色列的停火展开斡旋,提出一项为期60天的加沙地带停火方案。然而,围绕是否接受这份方案,哈马斯和以色列的态度不一,谈判频频出现变数。美国白宫5月29日表示,以色列已接受并签署美国提出的加沙地带临时停火方案。但该方案在…

基于springboot的宠物领养系统

博主介绍:java高级开发,从事互联网行业六年,熟悉各种主流语言,精通java、python、php、爬虫、web开发,已经做了六年的毕业设计程序开发,开发过上千套毕业设计程序,没有什么华丽的语言&#xff0…

中国王朝简史

文章目录 一、先秦时期:文明起点与制度雏形夏(约前2070年–前1600年)商(约前1600年–前1046年)周(前1046年–前256年) 二、大一统帝国的试验与成熟秦(前221年–前207年)汉…

Freefilesync配置windows与windows,windows与linux之间同步

说明 Freefilesync:用于windows与windows,windows与linux之间同步 linux 之间同步,使用系统的自带的 corn 软件,执行 sync 命名的脚本即可 一 、下载Freefilesync windows服务器上打开官网 https://freefilesync.org/&#xff0…