feat:优化架构

This commit is contained in:
Daniel
2026-03-25 13:43:00 +08:00
parent 8991f2a2d7
commit a2f224d01f
7 changed files with 509 additions and 5 deletions

View File

@@ -13,9 +13,13 @@ from moviepy import ImageClip
from PIL import Image, ImageDraw, ImageFont
from engine.audio_gen import synthesize_scenes
from engine.assembler import assemble_clips
from engine.comfy_client import ComfyClient
from engine.config import AppConfig
from engine.director import scenes_to_shots
from engine.shot_executor import render_shot
from engine.script_gen import generate_scenes, refine_scene
from engine.task_store import create_task, update_shot_status, update_task_status
from engine.types import Scene
from engine.video_editor import Segment, render_final
@@ -65,6 +69,10 @@ def _prog(p: float, msg: str) -> None:
_emit("PROG " + json.dumps({"p": p2, "msg": msg}, ensure_ascii=False))
def _prog_shot(shot_id: str, status: str) -> None:
_emit(f"PROG_SHOT {shot_id} {status}")
def _normalize_style(style: str | None) -> str:
s = (style or "").strip()
if not s:
@@ -308,13 +316,43 @@ def step_refine(
def step_render(prompt: str, cfg: AppConfig, mock: bool, *, style: str | None, character: str | None, out_dir: Path) -> int:
payload = _read_stdin_json()
scenes = _parse_scenes_from_obj(payload)
scenes_raw = _parse_scenes_from_obj(payload)
scenes = [
Scene(
image_prompt=_decorate_image_prompt(s.image_prompt, style=style, character=character),
video_motion=s.video_motion,
narration=s.narration,
)
for s in scenes_raw
]
shots = scenes_to_shots(scenes)
out_dir.mkdir(parents=True, exist_ok=True)
task_id = out_dir.name
create_task(task_id, shots)
update_task_status(task_id, "running")
_prog(0.05, "Start render")
out = asyncio.run(_render_from_scenes(prompt, scenes, cfg, mock=mock, style=style, character=character, out_dir=out_dir))
_prog(1.0, "Render finished")
_emit("RENDER_DONE " + json.dumps({"output": str(out)}, ensure_ascii=False))
return 0
clips: list[str] = []
total = max(1, len(shots))
try:
for idx, shot in enumerate(shots, start=1):
shot_id = str(shot.get("shot_id", f"shot_{idx:02d}"))
update_shot_status(task_id, shot_id, "running")
_prog_shot(shot_id, "running")
clip_path = render_shot(shot, out_dir, cfg, mock=mock)
clips.append(clip_path)
update_shot_status(task_id, shot_id, "done")
_prog_shot(shot_id, "done")
_prog(0.05 + 0.8 * idx / total, f"Rendered shot {idx}/{total}")
final_out = out_dir / "final.mp4"
out = assemble_clips(clips, final_out)
update_task_status(task_id, "done")
_prog(1.0, "Render finished")
_emit("RENDER_DONE " + json.dumps({"output": str(out)}, ensure_ascii=False))
return 0
except Exception:
update_task_status(task_id, "failed")
raise
def main() -> int: