跳到正文
DEV Community· MAGI-2 AI Web Studio·· 2 小時前AI 評分55

MAGI-2 影片生成開源工具包支援最多 20 項參考素材的規劃與驗證

Show DEV: An Open 20-Asset Prompt Planner & Validation Toolkit for MAGI-2 Video Generation

AI 導讀

MAGI-2 AI Web Studio 展示一套面向 MAGI-2 影片生成的開源提示詞規劃與驗證工具包,可整理最多 20 個參考素材並匯出 JSON。參考素材限於 10 張圖片、5 段影片及 5 段音訊,腳本預算為 20,000 個字元;作者指出,這是工具包限制,生成端實際接受條件需另行確認。

正文

I wanted to be able to reopen a video job and see exactly which picture defined a character, which clip supplied a camera move, and when a sound was supposed to land. A prompt pasted into a browser only gave me part of that record. I settled on a small JSON job file that I can read in a diff and validate from a terminal before opening the generation interface.

The problem

A MAGI-2 omni-reference job can use up to 20 references, split across ten images, five videos, and five audio clips. That split matters. Six clips of camera movement exceed the video allowance even when every other slot is empty. The planner also has a 20,000-character script budget. I treat that number as a toolkit constraint and check separately what the generation endpoint actually accepts.

The less obvious failures are semantic. A shot might refer to “the close-up” when the asset list contains three of them. A dialogue line can survive a rewrite while its audio cue disappears. Neither problem necessarily makes the JSON invalid. I keep the cue beside the action it belongs to, and I use the same filename in the script and asset list until I map the job to the upload interface. When I swap in a new asset, the filename change gives me somewhere concrete to look in the diff.

What I built

  • The Hugging Face Prompt Studio is a static browser planner. I can choose a preset, edit the timeline, add reference slots by modality, choose audio categories, and export JSON. The slots hold names. That lets me plan a scene before deciding which media to upload to a generation provider.
  • The GitHub toolkit includes a sample job, prompt templates, and a Python validator. The validator uses the standard library, reports malformed input and over-budget jobs, and returns a nonzero exit status on failure.
  • magi-2-ai.com is the independent hosted workbench for browser-based generation. This is where I would set the model and output options and attach the actual media. I keep the exported job alongside the output so I can tell which version of the script I sent.

I keep these steps separate so planning and validation can happen before I spend a render. The JSON is the interchange format for the planner and validator. A provider can have its own upload IDs, labels, and request fields, so copy the planned settings into the workbench or translate them in a provider-specific adapter.

Quick code walkthrough

The important part of the check is to count the references both by category and across the whole job. This excerpt takes a decoded job object and mirrors the budget checks. The CLI also checks the root and reference types, unknown categories, numeric duration, and blank filenames.

LIMITS = {"images": 10, "videos": 5, "audio": 5}


def check_budget(job):
    errors = []
    script = job.get("script")
    if not isinstance(script, str) or not script.strip() or len(script) > 20_000:
        errors.append("Use 1–20,000 characters of nonblank script.")

    references = job.get("references", {})
    total = 0
    for kind, limit in LIMITS.items():
        count = len(references.get(kind, []))
        total += count
        if count > limit:
            errors.append(f"{kind}: {count} assets exceeds the limit of {limit}.")
    if total > 20:
        errors.append(f"Total: {total} assets exceeds the limit of 20.")
    return errors

After downloading a job, run this from the repository root:

python scripts/validate_magi2_payload.py path/to/magi-2-job.json

The browser uses Array.from(text).length and the CLI uses Python's len, so both count Unicode code points. The planner counts raw text before it trims the exported script. Trailing whitespace can therefore hit the browser limit even when the saved script fits. A backend could count bytes or tokens instead. I keep a margin when I know the prompt will pick up reference labels or wrapper text during ingestion.

The validator trusts asset identifiers as strings. It can't check that the named video actually contains a camera move, that a dialogue recording belongs to the intended speaker, or that any cue survives generation. I do those checks against the media and timeline. A clean validation result means the local job passed the schema checks.

A long-script format I can revise

I describe the visible action, camera, and sound in each interval. I put global continuity notes at the top and use a cut only when I want a framing change. Here's a 24-second block to copy into the script field. In the planner, set the duration to 24 seconds and add the named references in their corresponding slots.

Global: Night workshop. Keep the courier's coat consistent with courier-front.png.
Keep the blue door on screen right. No music.

[00:00–00:08] Wide setup
Picture: The courier crosses the workshop carrying a sealed envelope.
Camera: Locked wide. Use workshop-wide.mp4 for composition.
Sound: Start room-tone.wav at 00:00. Footsteps end when the courier stops.
End state: The courier stands beside the door with the envelope still sealed.

[00:08–00:16] Envelope insert
Picture: Cut to the courier's hands. The left hand holds the envelope.
Camera: Locked insert. Use envelope.png for the seal design.
Sound: One paper tear when the wax breaks at about 00:13. Keep room tone.
End state: The torn flap is open. The left hand still holds the envelope.

[00:16–00:24] Return to wide
Picture: Back in the original framing. The courier opens the door at 00:19.
Camera: Locked wide. Maintain screen direction.
Sound: Use latch.wav at visible latch release. Hold room tone through the end.

On review I'd look for the cut at 00:08, the torn flap after 00:16, and the sound at the latch release. If a cut drops the envelope from the courier's hand, my first edit would be to repeat the end state at the start of the next shot. If the latch doubles up, I'd leave one sound cue and temporarily drop other audio references to see whether the behavior persists. I can rerun a single changed job and keep the earlier version for comparison.

Feedback welcome

If you have a tighter camera instruction or a case the validator misses, I'd welcome a PR against the templates or sample jobs. A short fixture with expected behavior is enough to discuss a validation bug. For a prompt comparison, I'd like the model variant, duration, minimum reference set, and the moment where the output diverged from the brief.

Disclosure: magi-2-ai.com is an independent third-party online workbench based on Sand.ai's MAGI-2 model. It is not officially affiliated with Sand.ai. This article was drafted with AI assistance.

來源:DEV Community · dev.to