CogVideoX 官方 Gallery 提示词深度解析:从 12 个示例到高质量视频生成 Prompt 工程实战
CogVideoX 官方 Gallery 提示词深度解析:从 12 个示例到高质量视频生成 Prompt 工程实战
导读
本文以 CogVideoX 开源仓库中 resources/galary_prompt.md 收录的 12 个官方示例提示词(CogVideoX-5B 8 条、CogVideoX-2B 4 条)为分析对象,系统拆解 CogVideoX 系列模型在文本到视频(T2V)生成中对提示词的格式、结构与内容要求,并结合仓库中的 推理脚本 与 提示词优化脚本 源码,给出从"看图写 Prompt"到"命令行跑通生成"的完整实战路径。读完本文,你将掌握:CogVideoX 长提示词的通用写作范式、官方示例的逐条拆解、如何用大模型自动扩写提示词,以及如何通过 CLI 参数(分辨率、帧数、guidance、seed)把这些提示词真正跑成视频。
一、galary_prompt.md 是什么:官方视频画廊的"提示词对照表"
在仓库 README.md 的 Gallery(视频作品)章节中,官方展示了 CogVideoX-5B 与 CogVideoX-2B 共 12 个代表性生成视频(README 中通过 HTML video 标签嵌入),并在页脚明确说明:
"To view the corresponding prompt words for the gallery, please click here"(查看画廊的对应提示词,请点击 这里)
也就是说,resources/galary_prompt.md 是官方作品集的提示词索引文件:它按模型分组、按编号一一对应画廊中的每个视频,是研究 CogVideoX"什么样的提示词能生成什么样视频"的第一手官方资料。文件结构非常简单:
## CogVideoX-5B:Videos 1-8,共 8 条长提示词;## CogVideoX-2B:Videos 1-4,共 4 条长提示词。
同时,仓库 resources/videos 目录下还保留了 1.mp4 ~ 4.mp4 四个示例视频文件,可以配合提示词对照观看。这份文件本身虽然只有提示词,但结合仓库源码(README 中的模型规格表、cli_demo.py 的参数体系、convert_demo.py 的扩写逻辑),可以完整还原"提示词 -> 模型 -> 视频"的整个链路。
二、先读懂 CogVideoX 对提示词的三条硬性约束
在拆解示例之前,必须先明确模型本身对输入文本的约束,这些约束直接决定了为什么官方画廊里的提示词都长成"整段英文细节描述"的样子。以下信息均来自 README.md 的模型介绍表格与 推理脚本 源码:
| 约束项 | CogVideoX1.5-5B / 1.5-5B-I2V | CogVideoX-2B / 5B / 5B-I2V |
|---|---|---|
| 提示词语言 | 仅支持 English | 仅支持 English |
| 提示词 Token 上限 | 224 Tokens | 226 Tokens |
| 训练/推荐输入 | 长提示词(long prompts) | 长提示词 |
| 帧数要求 | 16N + 1(N ≤ 10,默认 81) |
8N + 1(N ≤ 6,默认 49) |
| 分辨率 | 1360 × 768(I2V 支持 Min=768、Max 在 768~1360 且 %16=0) | 720 × 480 |
| 视频长度 / 帧率 | 5s 或 10s / 16fps | 6s / 8fps |
对应到 推理脚本 中的 RESOLUTION_MAP:
RESOLUTION_MAP = {
"cogvideox1.5-5b-i2v": (768, 1360),
"cogvideox1.5-5b": (768, 1360),
"cogvideox-5b-i2v": (480, 720),
"cogvideox-5b": (480, 720),
"cogvideox-2b": (480, 720),
}
而 README.md 的"Prompt Optimization(提示词优化)"一节更是开宗明义:模型是在长提示词下训练的,一个好的提示词直接决定了视频生成质量。官方在推理前建议先用 GLM-4(或 GPT-4 等)大模型把用户短输入扩写成与训练分布一致的长文本(详见 convert_demo.py)。因此,galary_prompt.md 中每条提示词都是 50~120 词的英文长句,正是模型最喜欢的输入形态——这是解读下文所有示例的总前提。
三、CogVideoX-5B 官方示例提示词全文(Videos 1-8)
以下是 galary_prompt.md 中 CogVideoX-5B 部分 8 条提示词的完整原文,一条未删,供直接复制使用:
Video 1 —— 花园蝴蝶(动静结合的自然场景)
A garden comes to life as a kaleidoscope of butterflies flutters amidst the blossoms, their delicate wings casting shadows on the petals below. In the background, a grand fountain cascades water with a gentle splendor, its rhythmic sound providing a soothing backdrop. Beneath the cool shade of a mature tree, a solitary wooden chair invites solitude and reflection, its smooth surface worn by the touch of countless visitors seeking a moment of tranquility in nature's embrace.
Video 2 —— 暴雨中奔跑的男孩(人物 + 极端天气 + 情绪叙事)
A small boy, head bowed and determination etched on his face, sprints through the torrential downpour as闪电 crackles and 雷鸣 rumbles in the distance. The relentless rain pounds the ground, creating a chaotic dance of water droplets that mirror the Dramatic sky's anger. In the far background, the silhouette of a cozy home beckons, a faint beacon of safety and warmth amidst the fierce weather. The scene is one of perseverance and the unyielding spirit of a child braving the elements.
Video 3 —— 火星上的握手(科幻题材)
A suited astronaut, with the red dust of Mars clinging to their boots, reaches out to shake hands with an alien being, their skin a shimmering blue, under the pink-tinged sky of the fourth planet. In the background, a sleek silver rocket, a beacon of human ingenuity, stands tall, its engines powered down, as the two representatives of different worlds exchange a historic greeting amidst the desolate beauty of the Martian landscape.
Video 4 —— 海边作画的老人(人物 + 光影 + 创作过程)
An elderly gentleman, with a serene expression, sits at the water's edge, a steaming cup of tea by his side. He is engrossed in his artwork, brush in hand, as he renders an oil painting on a canvas that's propped up against a small, weathered table. The sea breeze whispers through his silver hair, gently billowing his loose-fitting white shirt, while the salty air adds an intangible element to his masterpiece in progress. The scene is one of tranquility and inspiration, with the artist's canvas capturing the vibrant hues of the setting sun reflecting off the tranquil sea.
Video 5 —— 酒吧沉思(近景特写 + 氛围光)
In a dimly lit bar, purplish light bathes the face of a mature man, his eyes blinking thoughtfully as he ponders in close-up, the background artfully blurred to focus on his introspective expression, the ambiance of the bar a mere suggestion of shadows and soft lighting.
Video 6 —— 戴墨镜的金毛(动物 + 运动镜头)
A golden retriever, sporting sleek black sunglasses, with its lengthy fur flowing in the breeze, sprints playfully across a rooftop terrace, recently refreshed by a light rain. The scene unfolds from a distance, the dog's energetic bounds growing larger as it approaches the camera, its tail wagging with unrestrained joy, while droplets of water glisten on the concrete behind it. The overcast sky provides a dramatic backdrop, emphasizing the vibrant golden coat of the canine as it dashes towards the viewer.
Video 7 —— 湖畔天鹅(风景 + 反射 + 静谧)
On a brilliant sunny day, the lakeshore is lined with an array of willow trees, their slender branches swaying gently in the soft breeze. The tranquil surface of the lake reflects the clear blue sky, while several elegant swans glide gracefully through the still water, leaving behind delicate ripples that disturb the mirror-like quality of the lake. The scene is one of serene beauty, with the willows' greenery providing a picturesque frame for the peaceful avian visitors.
Video 8 —— 哄睡婴儿的中国母亲(人物 + 光影 + 温馨氛围)
A Chinese mother, draped in a soft, pastel-colored robe, gently rocks back and forth in a cozy rocking chair positioned in the tranquil setting of a nursery. The dimly lit bedroom is adorned with whimsical mobiles dangling from the ceiling, casting shadows that dance on the walls. Her baby, swaddled in a delicate, patterned blanket, rests against her chest, the child's earlier cries now replaced by contented coos as the mother's soothing voice lulls the little one to sleep. The scent of lavender fills the air, adding to the serene atmosphere, while a warm, orange glow from a nearby nightlight illuminates the scene with a gentle hue, capturing a moment of tender love and comfort.
值得注意的数据细节:第 2 条提示词原文中混入了中文词"闪电""雷鸣"(
as闪电 crackles and 雷鸣 rumbles),这是官方数据文件中的原样内容。鉴于 README 明确说明模型仅支持英文输入、提示词经过 LLM 润色时会被翻译成英文,这条示例恰好提醒我们:在正式使用前应通过 convert_demo.py 将这类混入非英文 token 的提示词清洗、重写为纯英文,避免占用有限 token 预算或干扰文本编码器。
四、CogVideoX-2B 官方示例提示词全文(Videos 1-4)
同样来自 galary_prompt.md 的 CogVideoX-2B 部分,4 条提示词全文如下:
Video 1 —— 玩具船"航行"在地毯上(静物 + 拟真运动)
A detailed wooden toy ship with intricately carved masts and sails is seen gliding smoothly over a plush, blue carpet that mimics the waves of the sea. The ship's hull is painted a rich brown, with tiny windows. The carpet, soft and textured, provides a perfect backdrop, resembling an oceanic expanse. Surrounding the ship are various other toys and children's items, hinting at a playful environment. The scene captures the innocence and imagination of childhood, with the toy ship's journey symbolizing endless adventures in a whimsical, indoor setting.
Video 2 —— 山路上飞驰的 SUV(跟拍运镜 + 地形地貌)
The camera follows behind a white vintage SUV with a black roof rack as it speeds up a steep dirt road surrounded by pine trees on a steep mountain slope, dust kicks up from its tires, the sunlight shines on the SUV as it speeds along the dirt road, casting a warm glow over the scene. The dirt road curves gently into the distance, with no other cars or vehicles in sight. The trees on either side of the road are redwoods, with patches of greenery scattered throughout. The car is seen from the rear following the curve with ease, making it seem as if it is on a rugged drive through the rugged terrain. The dirt road itself is surrounded by steep hills and mountains, with a clear blue sky above with wispy clouds.
Video 3 —— 街头涂鸦艺术家(人物 + 动作 + 城市环境)
A street artist, clad in a worn-out denim jacket and a colorful bandana, stands before a vast concrete wall in the heart, holding a can of spray paint, spray-painting a colorful bird on a mottled wall.
Video 4 —— 战火中的女孩(纪实叙事 + 特写情绪)
In the haunting backdrop of a war-torn city, where ruins and crumbled walls tell a story of devastation, a poignant close-up frames a young girl. Her face is smudged with ash, a silent testament to the chaos around her. Her eyes glistening with a mix of sorrow and resilience, capturing the raw emotion of a world that has lost its innocence to the ravages of conflict.
五、逐条拆解:官方提示词的通用写作范式
把 12 条提示词放在一起横向比较,可以提炼出 CogVideoX 长提示词的五个高频组件。这套范式同样可以直接迁移到你的业务提示词写作中。
5.1 结构范式:主体 → 动作 → 环境 → 细节 → 氛围收尾
几乎每一条官方提示词都遵循"总分总"的段落节奏,例如 Video 7(湖畔天鹅):
- 开篇交代主体与时间:
On a brilliant sunny day, the lakeshore is lined with an array of willow trees...(时间 + 地点 + 场景主干); - 中段铺陈动作与物理细节:
the tranquil surface of the lake reflects the clear blue sky、swans glide gracefully... leaving behind delicate ripples(反射、涟漪这类物理交互是视频模型最容易被 prompt 唤醒的动态信号); - 收尾给出镜头/情绪基调:
The scene is one of serene beauty... providing a picturesque frame(把"安静的美"这种抽象氛围转译为具体构图描述)。
Video 8(母亲哄睡)是另一个典型:人物(mother + baby)→ 动作(rocks back and forth、lulls)→ 环境(nursery、mobiles、dimly lit bedroom)→ 感官细节(lavender scent、orange glow)→ 情感定调(tender love and comfort)。
5.2 细节密度:用"可拍摄的语言"代替抽象形容词
对比 Video 3 与 Video 1 可以看出官方偏好的细节颗粒度:
- 抽象词必须被"翻译"成可视觉化的实体:
historic greeting被落实为shake hands、pink-tinged sky、red dust clinging to their boots、engines powered down; - 光与影被显式书写:Video 4 的
the vibrant hues of the setting sun reflecting off the tranquil sea、Video 8 的a warm, orange glow from a nearby nightlight; - 触觉/嗅觉等跨模态信息也会写入(
smooth surface worn by the touch、The scent of lavender fills the air)——虽然模型只能生成画面,但这类描写会连带出更丰富的环境上下文。
5.3 时间轴与动态表达:让静止的画面"动起来"
CogVideoX 是视频扩散模型,提示词需要给出运动动机。官方示例中典型的动态写法包括:
- 动作动词 + 进行时:
flutters、cascades、sprints、glide gracefully、rocks back and forth; - 前后状态变化:Video 8 中
the child's earlier cries now replaced by contented coos(哭声被安抚声替代)——这种"状态迁移"描述为视频提供了剧情弧线; - 镜头运动提示:Video 6 的
The scene unfolds from a distance, the dog's energetic bounds growing larger as it approaches the camera(由远及近)、Video 2(2B)的The camera follows behind a white vintage SUV。注意 Video 6 这类"由远及近"在 i2v 场景下是被严格禁止的(见下文 convert_demo 规则),但在 t2v 提示词中可用于引导镜头推近。
5.4 环境分层:前景 / 主体 / 背景的三层构图
多数示例都显式区分了景深层次:
- 前景细节:Video 1 的
their delicate wings casting shadows on the petals below; - 主体:始终放在第二句以前出现;
- 背景交代:统一用
In the background或In the far background引出(Video 1、3 都是如此),Video 5 更是明确要求the background artfully blurred(背景虚化),用一句话同时指定了光圈效果与景深。
5.5 情绪与主题收束句
Video 2(5B)、Video 4(2B)等在末尾追加一句主题句(The scene is one of perseverance and...、capturing the raw emotion of...)。这类句子虽不直接对应画面元素,但在扩写流程中承担"保持叙事一致性"的作用,可作为提示词结尾的惯例组件。
5.6 5B 与 2B 提示词的差异观察
从源码证据看,两者面向的模型规格不同:2B 模型帧数为 8N+1(默认 49 帧、6 秒、8fps),5B 系列为 16N+1(默认 81 帧、16fps),且 README 指出 2B 采用 3d_sincos_pos_embed 位置编码、5B 采用 3d_rope_pos_embed。体现在提示词上:5B 的 8 条示例普遍更长、细节更密(平均 70~110 词),2B 的 4 条示例中出现了 Video 3(涂鸦)这样仅 40 词左右的"短提示"——说明提示词长度上限(224/226 tokens)是硬约束,但长文本并非唯一正确解,场景简单时精炼提示词同样在官方示例之列。
六、把这些提示词跑成视频:CLI 参数全解析
有了提示词,下一步就是按 推理脚本 实际生成。安装依赖请严格按 requirements.txt 执行(diffusers>=0.35.2、transformers>=4.57.1、torch>=2.8.0 等),并以 THUDM/CogVideoX1.5-5b、THUDM/CogVideoX-5b、THUDM/CogVideoX-2b 等作为 --model_path。以 CogVideoX-5B 画廊第 1 条提示词为例:
python inference/cli_demo.py \
--prompt "A garden comes to life as a kaleidoscope of butterflies flutters amidst the blossoms..." \
--model_path THUDM/CogVideoX-5b \
--generate_type "t2v" \
--num_frames 49 \
--guidance_scale 6.0 \
--num_inference_steps 50 \
--seed 42 \
--output_path "./garden.mp4"
6.1 参数表(来自 cli_demo.py 与命令行解析部分)
| 参数 | 默认值 | 说明 |
|---|---|---|
--prompt |
必填 | 视频内容描述,即本文给出的画廊提示词 |
--model_path |
THUDM/CogVideoX1.5-5B |
预训练模型路径 |
--generate_type |
t2v |
t2v / i2v / v2v,分别对应文生视频、图生视频、视频续写 |
--image_or_video_path |
None |
i2v 的参考图片路径 / v2v 的参考视频路径 |
--num_frames |
81 |
帧数;CogVideoX 1.0 为 49(6s@8fps),1.5 为 81/161(5s/10s@16fps) |
--width / --height |
由 RESOLUTION_MAP 决定 |
仅 i2v 允许自定义;其余模型会自动回退到推荐分辨率 |
--num_inference_steps |
50 |
采样步数,越多质量越好、耗时越长 |
--guidance_scale |
6.0 |
无分类器引导强度,越大越贴合提示词 |
--seed |
42 |
随机种子,保证可复现 |
--fps |
16 |
输出视频帧率 |
--lora_path / --lora_rank |
None / 128 |
加载微调 LoRA 权重 |
--dtype |
bfloat16 |
bfloat16 / float16 |
6.2 源码层面的四个关键实现细节
-
分辨率自动回退逻辑(cli_demo.py):脚本先根据模型名从
RESOLUTION_MAP取推荐分辨率;当用户传入的宽高与推荐值不符时,i2v 模型会保留用户值并给出警告,t2v/v2v 则强制回退到推荐分辨率。因此对画廊这类 t2v 提示词,直接不传--width/--height即可。 -
Scheduler 选择:脚本默认使用
CogVideoXDPMScheduler.from_config(..., timestep_spacing="trailing"),且调用时开启use_dynamic_cfg=True(cli_demo.py 与 L166)。注释明确指出:CogVideoX-2B 推荐CogVideoXDDIMScheduler,5B/5B-I2V 推荐 DPM Scheduler;若改用 DDIM,use_dynamic_cfg需置为False。 -
显存优化:默认开启
pipe.enable_sequential_cpu_offload()与pipe.vae.enable_slicing()、pipe.vae.enable_tiling()(cli_demo.py)。README 数据说明指出:多 GPU 推理时须关闭enable_sequential_cpu_offload();若关闭全部优化,峰值显存约为表中数值的 3 倍,但推理速度提升约 3~4 倍。 -
可复现性:
generator=torch.Generator().manual_seed(seed)在每个生成分支中被显式传入,配合固定--seed 42即可复现官方示例的生成结果(注意不同 seed 会产生不同视频,画廊视频使用的具体 seed 未在文档中公开,这一点不能臆断)。
七、提示词工程链路:从短句到官方长提示词
galary_prompt.md 中的长提示词并非必须手写。仓库提供了 convert_demo.py,用于把用户短输入交给大语言模型(默认 GLM-4,可替换为 GPT-4 等)扩写成符合训练分布的长提示词。这正好解释了官方示例为何都长这样——它们本质上是"LLM 扩写范式"的产物。
7.1 T2V 扩写规则(sys_prompt_t2v)
源码 convert_demo.py 内置的系统提示词规定了:
- 每次只输出一条视频描述;
- 用户要求修改时,不是简单加长,而是整体重构整段描述以融合建议;
- 描述长度必须与示例相当("Video descriptions must have the same num of words as examples below. Extra words will be ignored")——这与模型 224/226 token 上限以及官方示例的篇幅高度一致。
调用参数为 temperature=0.01、top_p=0.7、max_tokens=250,并使用 few-shot 示例("a girl is on the beach"、"A man jogging on a football field" 等)引导输出格式。
命令行用法(t2v):
python inference/convert_demo.py --prompt "A girl riding a bike." --type "t2v"
7.2 I2V 扩写规则(sys_prompt_i2v)
图生视频的扩写约束更严格(convert_demo.py):
- 输入图片是视频首帧,输出 caption 必须描述"从当前画面开始的运动";
- 用户输入为空时也可扩写;用户输入非空则需按其扩展;
- 禁止镜头切换、禁止画面切换、禁止视角变化("Don't contain camera transitions!!! Don't contain screen switching!!! Don't contain perspective shifts!!!");
- 回答必须用完整句子、以英文输出、直接以动作开头(如 "A woman is on a beach",禁止 "The image shows..." 这类引导语)。
命令行用法(i2v,图片会经 base64 编码随请求发送):
python inference/convert_demo.py --prompt "the cat is running" --type "i2v" --image_path "/path/to/your/image.jpg"
7.3 对写作的启示
把这两套规则与画廊示例对照,可以得到可直接落地的检查清单:
- 单条输出、长度对标示例(约 50~120 词,别超过 token 上限);
- 动作前置、进行时动词驱动,为视频提供运动线索;
- t2v 可用镜头语言(由远及近、跟随镜头),i2v 必须禁用;
- 非英文输入务必先翻译/清洗(README 明确"模型仅支持英语输入");
- 修改需求通过"整体重写"而非"追加段落"实现。
八、从官方示例出发的提示词自检清单
结合前文拆解,可提炼出一份用于自测提示词质量的清单:
- [ ] 语言为英文,总长控制在 224/226 tokens 以内;
- [ ] 结构上覆盖"主体 + 动作 + 环境/背景 + 光影细节 + 氛围收尾"五要素;
- [ ] 至少包含 2~3 个进行时动词以提供运动动机;
- [ ] 抽象形容词(美丽、悲伤、宏伟)都有对应的可视觉化实体支撑;
- [ ] 背景信息用
In the background等显式结构词分层; - [ ] 若用于 i2v,已删除全部镜头切换与视角变化类描述;
- [ ] 帧数与分辨率符合目标模型规格(2B:49 帧/720×480;1.5-5B:81 帧/1360×768)。
九、延伸阅读
- 提示词来源:galary_prompt.md,画廊展示与模型规格表见 README.md;
- 推理参数与分辨率映射:inference/cli_demo.py;
- 短提示词扩写工具:inference/convert_demo.py;
- 图生视频/视频续写场景与微调 LoRA 加载:finetune/README.md;
- 量化推理与低显存方案:inference/cli_demo_quantization.py,量化细节见 README 数据说明;
- 示例视频文件:resources/videos。
补充说明:本文所有提示词均逐字来自 galary_prompt.md;模型规格(分辨率、帧数、token 上限、精度推荐)来自 README.md 模型介绍表;命令行参数与扩写规则分别来自 cli_demo.py 与 convert_demo.py 源码,未引入任何外部数据。画廊视频使用的具体随机种子与生成参数未在仓库公开,读者可自行调节
--seed与--guidance_scale复现同题材的不同效果。