AI 漫剧短剧不是“输入一句话,自动出片”。专业团队真正做的事,是把创意拆成可结构化、可复现、可批量的工程管线。核心环节包括:剧本结构化、角色一致性、分镜生成、配音字幕、视频合成、合规审核。下面给出一套可落地的技术方案与代码示例。
推荐流程:
用 JSON 描述剧本,方便程序读取和批量生成。
import json
script = {
"title": "最后一班地铁",
"episodes": [
{
"episode": 1,
"scenes": [
{
"scene_id": "S01",
"location": "深夜地铁站",
"shots": [
{
"shot_id": "S01-01",
"prompt": "cinematic, empty subway platform, cold light, wide shot",
"dialogue": "她:你终于来了。",
"duration": 3.5
},
{
"shot_id": "S01-02",
"prompt": "close-up, young woman, teary eyes, neon reflection",
"dialogue": "他:对不起,我来晚了。",
"duration": 3.0
}
]
}
]
}
]
}
with open("script.json", "w", encoding="utf-8") as f:
json.dump(script, f, ensure_ascii=False, indent=2)结构化的意义在于:后续分镜、配音、剪辑都能按 shot_id 自动串联,避免手工对不上。
以下代码调用本地 Stable Diffusion WebUI API,按镜头批量出图,并固定 seed 与角色提示词。
import requests, base64, json, os
API = "http://127.0.0.1:7860"
OUT = "shots"
os.makedirs(OUT, exist_ok=True)
STYLE = "anime style, cinematic lighting, vertical composition, high detail"
NEG = "low quality, watermark, text, extra fingers, deformed"
def txt2img(prompt, seed, path):
payload = {
"prompt": f"{prompt}, {STYLE}",
"negative_prompt": NEG,
"seed": seed,
"steps": 28,
"width": 768,
"height": 1344,
"cfg_scale": 7,
"sampler_name": "DPM++ 2M Karras"
}
r = requests.post(f"{API}/sdapi/v1/txt2img", json=payload, timeout=300)
r.raise_for_status()
img = r.json()["images"][0]
with open(path, "wb") as f:
f.write(base64.b64decode(img.split(",", 1)[-1]))
with open("script.json", encoding="utf-8") as f:
script = json.load(f)
for ep in script["episodes"]:
for scene in ep["scenes"]:
for shot in scene["shots"]:
seed = hash(shot["shot_id"]) % (2**31)
txt2img(shot["prompt"], seed, f"{OUT}/{shot['shot_id']}.png")专业提示:角色一致性不能只靠提示词。生产环境建议用 LoRA、ControlNet、IP-Adapter 或参考图锁定五官与服装。
用 MoviePy 将分镜图、配音、字幕合成为竖屏视频。
from moviepy.editor import ImageClip, AudioFileClip, concatenate_videoclips
import json
with open("script.json", encoding="utf-8") as f:
script = json.load(f)
clips = []
for ep in script["episodes"]:
for scene in ep["scenes"]:
for shot in scene["shots"]:
img = f"shots/{shot['shot_id']}.png"
audio = f"audio/{shot['shot_id']}.mp3"
duration = shot["duration"]
clip = ImageClip(img).set_duration(duration).resize(height=1920)
clip = clip.crop(x_center=clip.w/2, width=1080)
clip = clip.set_audio(AudioFileClip(audio))
clips.append(clip)
final = concatenate_videoclips(clips, method="compose")
final.write_videofile("episode01.mp4", fps=24, codec="libx264", audio_codec="aac")如果要加字幕,可用 TextClip 按时间轴叠加;如果要口型同步,可接入 Wav2Lip 等方案,但要注意肖像授权与合规。
AI 漫剧短剧的专业化,不是“一键出片”,而是把剧本、分镜、角色、配音、剪辑、审核做成可复现的管线。代码负责批量与稳定,创意负责打动观众。先跑通一个 30 秒镜头,再扩展成整集,才是最稳的路径。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。