AutoCut Story 5-Step Production Skill (Standalone)
This is a self-contained, externally portable 5-step video production skill.
All deterministic media/GPU operations run locally via scripts/; all LLM reasoning and image generation are taken over directly by the host Agent (zero external text/image API keys required).
Responsibility Split
-
Host Agent owns (3 creative points):
- Step 2A — Series Title & Genre Suggestion: Propose 3 natural short-drama title candidates +
cover_stylegenre. - Step 2B — AI Cover Generation: Generate the vertical 9:16 cover image using the host Agent's own image generation tool/model (required) from the script-prepared reference image and prompt, retrying with
stronger_promptif locallayout_v2visual deviation< 0.50. - Step 3A — Opening Episode Selection: Read candidate episodes' ASR dialogue brief (
opening_brief.md) and select the strongest hook episode + one-sentence reason.
- Step 2A — Series Title & Genre Suggestion: Propose 3 natural short-drama title candidates +
-
Local Scripts own (deterministic & local GPU models):
- FFprobe scanning, majority canvas selection (
step1_probe.py) - Title validation, hallucinated-surname guard,
series_v1revision tracking, reference frame extraction,layout_v2deviation check (step2_title_cover.py) - Candidate Whisper ASR,
evidence_sha256verification,playback_dp_v2whole-episode DP grouping (step3_plan.py) - Whole-series
merged.mkv,vocal_remover/demucsseparation, full ASR, CAM++ speaker clustering & 3-track assignment, subtitle-boundary cut shifting, frame-exact slicing (step4_analyze.py) - Peak-safe mix gain derivation,
picture.mp4+story_NNN.mp4rendering, AAC decode-peak verification with auto step-down retry,timeline_map.json, frame-verified 8-trackshotcut_NNN.mlt, anddelivery_manifest.json(step5_render.py)
- FFprobe scanning, majority canvas selection (
-
GPU Resource Policy (On-Demand & Immediate Release):
- Zero resident GPU memory: No daemon, server, or persistent model process is ever kept alive between stages.
- Every heavy local GPU model (
vocal_removerCascadedNet UNet,faster-whisper-mediumASR,campplus_cn_commonCAM++ diarization) runs inside a short-lived isolated subprocess (lib/runtime.py::run_isolatedwith WindowsJOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE/ POSIXstart_new_session+killpg). - As soon as each stage finishes (or fails/times out), models are explicitly deleted (
del model,gc.collect(),torch.cuda.empty_cache()) and the worker process exits immediately so the OS reclaims 100% of VRAM before the next stage or external GPU workload starts. - Video encoding (
h264_nvenc) runs inside short-livedffmpegsubprocesses that release NVENC sessions immediately on exit. - Before every GPU stage,
require_gpu_ready()checksnvidia-smithresholds (story.gpu.max_memory_mib/max_utilization_pct) to avoid colliding with concurrent GPU jobs.
Detailed rules and schemas:
- Complete orchestration & interaction diagrams: workflow-diagram.md
- Creative prompts & style matrix: prompts-and-rules.md
- Step 1–5 JSON contracts & delivery manifest schema: json-contracts.md
Complete 5-Step Orchestration Flowchart
flowchart TD
START(["User Provides Source Episode Directory"]) --> DOC["Pre-flight Gate: scripts/doctor.py --work-root WORK_ROOT"]
DOC -->|"ready = false (exit 1)"| FIX[["AGENT ASSISTED SETUP: Verify Host vs Sandbox, Resolve Remediation, Persist via --save-local"]]
FIX --> DOC
DOC -->|"ready = true (exit 0)"| S1["Step 1: scripts/step1_probe.py (Scan Episodes, FFprobe, Majority Even Canvas)"]
S1 --> J1[("timeline/sources.json")]
J1 --> S2_INS["Step 2: scripts/step2_title_cover.py inspect (Check series_v1 Gate)"]
S2_INS -->|"gate_ok = true"| S3_PREP
S2_INS -->|"need = title"| A_TITLE[["AGENT TAKEOVER 1: Propose 3 Titles + cover_style Genre"]]
A_TITLE --> S2_TITLE["scripts/step2_title_cover.py commit-title (Validate, Surname Guard, Revision +1)"]
S2_TITLE --> J2_REC[("series/record.json (series_v1)")]
J2_REC --> S2_PREP
S2_INS -->|"need = cover / cover_stale"| S2_PREP["scripts/step2_title_cover.py prepare-cover (Extract Ep1 Frame + Prompt Brief)"]
S2_PREP --> J2_BRIEF[("cover_brief_id.json")]
J2_BRIEF --> A_IMG[["AGENT TAKEOVER 2: Host Agent Image Model Generates 9:16 Cover"]]
A_IMG --> S2_COM["scripts/step2_title_cover.py commit-cover (Fit 1080x1920 + Local layout_v2 Deviation Check)"]
S2_COM -->|"deviation < 0.50 (exit 2: rejected_low_deviation)"| A_IMG_RETRY[["AGENT RETRY: Regenerate Cover Using stronger_prompt"]]
A_IMG_RETRY --> S2_COM
S2_COM -->|"deviation >= 0.50 (adopted)"| J2_COV[("series_cover_id.jpg + .json + record.json")]
J2_COV --> S3_PREP["Step 3: scripts/step3_plan.py prepare-opening (Local Whisper ASR on Candidate Episodes)"]
S3_PREP --> J3_BRIEF[("local_planning/opening_brief.md + evidence_sha256")]
J3_BRIEF --> A_OPEN[["AGENT TAKEOVER 3: Read Candidate Dialogue and Pick Opening Episode + Reason"]]
A_OPEN --> S3_COM["scripts/step3_plan.py commit-opening (Verify evidence_sha256 + playback_dp_v2 DP Grouping)"]
S3_COM --> J3_PLAN[("selection/result.json + timeline/plan.json (run_params_v3)")]
J3_PLAN --> S4_ASM["Step 4: scripts/step4_analyze.py — Whole-Series Assemble (merged.mkv) + Vocal Separation (vocal_remover / demucs)"]
S4_ASM --> S4_ASR["Whole-Series Local Whisper ASR (remapped.srt) + CAM++ Speaker Clustering & 3-Track Assignment"]
S4_ASR --> S4_CUT["Subtitle-Boundary Cut Shift (adjust_cuts) + Frame-Exact Slicing per output_NNN"]
S4_CUT --> J4_MAP[("main_new/result.json + frozen_plan.json + output_NNN/{merged.mkv, vocals/bg.wav, remapped.srt, source_plan, track_assignments, global_mapping}")]
J4_MAP --> S5_MIX["Step 5: scripts/step5_render.py — Derive Peak-Safe Mix Profile (mix_v2) + Render picture.mp4"]
S5_MIX --> S5_ENC["Mix & Render story_NNN.mp4 + Full AAC Decode-Peak Check"]
S5_ENC -->|"Peak Exceeded / Clipping"| S5_RETRY["Auto Step-Down gain_db (-step_db, up to max_attempts)"]
S5_RETRY --> S5_ENC
S5_ENC -->|"Zero Clipping Passed"| S5_SC["Build timeline_map.json + Generate & Frame-Verify 8-Track shotcut_NNN.mlt"]
S5_SC --> J5_OUT[("FINAL DELIVERY: delivery/story_NNN.mp4 + series_cover.jpg + shotcut_NNN.mlt + status/stages/batch_status.json + delivery_manifest.json")]
J5_OUT --> VIS[["VISUAL DELIVERY POPUP: Open Interactive HTML Showcase via visual-explainer / answer-me-with-html / Fallback"]]
VIS --> DONE(["Done: Complete Rendered Videos, Visual Showcase & Full Metadata Manifest"])
Pre-Flight Environment Gate & Agent-Assisted Setup Protocol (MANDATORY)
Hard Gate: Before running ANY of Step 1–5 (especially on a new machine, new Agent, or new workspace), the host Agent MUST run scripts/doctor.py first:
python scripts/doctor.py [--work-root "<WORK_ROOT>"] [--models-dir "<MODELS_DIR>"]
- Exit code
0(ready: true): FFmpeg, FFprobe, all 9 required Python packages, and all 3 local models are ready. Checkremediationwarnings (e.g., GPU busy, CPU fallback, low disk space) before proceeding to Step 1. - Exit code
1(ready: false): STOP — DO NOT proceed to Step 1–5. Enter the Agent-Assisted Setup Loop below and re-rundoctor.pyuntilready: true.
Agent-Assisted Setup Loop (Follow remediation[] Item by Item)
- Confirm Runtime Environment (
execution_context.likely_sandbox == true):- If
doctor.pyflagsexecution_environment(Docker / cloud sandbox), ask the user whether source episode videos, GPU, and local models live on their local desktop machine. Switch to local device execution if available before installing anything in a temporary sandbox.
- If
- Locate Before Installing (
ffmpeg_missing/model_missing_*):- Never ask the user to manually hand-edit YAML or environment variables first, and never run global installs (
winget/apt/brew/pip) without explicit user confirmation. - First search common local paths (workspace parent directories,
tools/, user homemodels/, existing FFmpeg bundles) to see if binaries or weights already exist on disk. - If found, persist them automatically to the machine-local config (
configs/local.yaml, auto-excluded bypackage_skill.py):python scripts/doctor.py \ [--ffmpeg "<FFMPEG_PATH>"] [--ffprobe "<FFPROBE_PATH>"] \ [--models-dir "<MODELS_DIR>"] \ [--vocal-remover-weights "<PTH>"] [--asr-model "<ASR_DIR>"] [--diarize-model "<DIARIZE_DIR>"] \ --save-local - If not found locally, show the exact
expected_layoutanddownload_hintfromremediation[], ask the user either for their existing local path or permission to download/install, and persist once ready.
- Never ask the user to manually hand-edit YAML or environment variables first, and never run global installs (
- Python Dependencies (
python_packages_missing):- Confirm whether the user has a dedicated
venv/condaenvironment with PyTorch/CUDA already installed; if so, switch to that Python executable. - Otherwise present
remediation[].suggested_command(pip install -r requirements.txt) and obtain user confirmation before installing.
- Confirm whether the user has a dedicated
- GPU / CPU Fallback Advisory (
gpu_fallback_advisory&gpu_busy):- If
gpu.cuda_available == falseorgpu.h264_nvenc == false, explicitly inform the user that GPU acceleration is unavailable and CPU/libx264rendering will be significantly slower. Ask whether to enable and persist CPU fallback defaults:
(python scripts/doctor.py --cpu-fallback --save-local--cpu-fallbackwritesseparate/asr/diarize device=cpu,asr.compute_type=int8, andrender.codec=libx264intoconfigs/local.yaml.) - If
gpu.nvidia_smi.gate_ok == false(gpu_busy), advise the user to free VRAM/GPU utilization before starting Step 3–5.
- If
- Disk Space Warning (
disk_space_low):- If
disk.ok == false(default threshold5.0 GB, tunable via--min-disk-gb), suggest picking a--work-rooton a drive with more free space.
- If
- Re-Verify Gate:
- Re-run
python scripts/doctor.py --work-root "<WORK_ROOT>"with no extra flags (it automatically mergesconfigs/default.yaml→configs/local.yaml→--config→ CLI/env overrides). Proceed to Step 1 only whenready == true.
- Re-run
All scripts accept --models-dir <dir> (or env AUTOCUT_MODELS_DIR) and emit UTF-8 structured JSON to stdout (logs go to stderr).
5-Step Execution Procedure
Define two reusable paths at the start:
<INPUT_DIR>: Directory of source episode videos (e.g.ep01.mp4 ... ep80.mp4).<WORK_ROOT>: Workspace root for intermediate work, shared_series/registry, and delivery outputs.
Step 1: Probe Episodes & Canvas
python scripts/step1_probe.py --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" [--episodes 1,2,...]
Record the returned job_id, episode_count, canvas, and sources_path.
Step 2: Series Title & Agent-Generated Cover
-
Inspect existing series state:
python scripts/step2_title_cover.py inspect --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>"If
gate_ok: trueand the user does not request a rename or cover regeneration, skip directly to Step 3. -
Agent generates & commits title (if
need == "title"):- Read prompts-and-rules.md (§1 Title Rules).
- Propose 3 distinct, natural Chinese short-drama titles (1–40 chars, single line, no fabricated surnames/facts, no cliché bait phrases) and pick a
cover_stylefromneutral | modern | historical | suspense | romance | action. - Ask the user to confirm (or pick the strongest candidate if running autonomously) and commit:
python scripts/step2_title_cover.py commit-title \ --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \ --title "<CHOSEN_TITLE>" \ --candidates "<CAND1>" "<CAND2>" "<CAND3>" \ --cover-style "<GENRE>"
-
Prepare cover brief & generate cover using Agent's image model (if
need in ("cover", "cover_stale")):python scripts/step2_title_cover.py prepare-cover \ --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \ [--reference "<USER_REF_IMAGE>"] [--medium cel|painterly|watercolor|guofeng] [--style auto|<GENRE>]- The script returns
reference(auto-extracted from episode 1 if omitted),prompt,stronger_prompt,brief_path, andmin_deviation(0.5). - Call the host Agent's image generation tool/model (e.g.
image-generator) withreferenceas the reference image, vertical9:16aspect ratio, andprompt. Save the generated image to<RAW_COVER_PATH>. - Validate & adopt cover locally:
python scripts/step2_title_cover.py commit-cover \ --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \ --brief "<BRIEF_PATH>" --image "<RAW_COVER_PATH>" --agent-model "<MODEL_NAME>" --attempt 1 - Retry rule: If exit code is
2(status: "rejected_low_deviation"), the visual similarity to the reference frame is too high (deviation < 0.50). Re-invoke the Agent's image generator usingstronger_prompt(changing pose, crop, outfit, backdrop, and color palette while preserving recognizable faces) and re-runcommit-cover --attempt 2 --used-stronger-prompt.
- The script returns
Step 3: Agent Opening Selection & Whole-Episode DP Planning
- Transcribe candidate episodes & emit dialogue brief:
python scripts/step3_plan.py prepare-opening \ --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \ [--candidates 3,4,5,6] [--models-dir "<MODELS_DIR>"] - Agent reads
brief_md_pathand selects the opening episode:- Follow prompts-and-rules.md (§2 Opening Selection Rules): choose the single candidate episode with the clearest hook and self-contained conflict.
- Commit opening & generate
timeline/plan.json:Reviewpython scripts/step3_plan.py commit-opening \ --input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \ --episode <EP_NUM> --reason "<ONE_SENTENCE_REASON>" \ [--min-playback-sec 300 --max-playback-sec 480 --playback-speed 1.3 --picture-scale 1.1]outputs_summary(especially ifgrouping_relaxed: trueor any item hasneeds_review: true).
Step 4: Whole-Series Assembly, Vocal Separation, ASR, CAM++ Clustering & Slicing
python scripts/step4_analyze.py \
--input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \
[--models-dir "<MODELS_DIR>"] [--codec h264_nvenc|libx264]
This step is fully resumable via main_new/mapping_progress.json. It outputs:
main_new/result.json(main_new_mapping_v1)main_new/timeline/frozen_plan.json- Per-output directories
main_new/output_NNN/containing frame-accuratemerged.mkv,vocals.wav,background.wav,remapped.srt,speakers_raw.json,track_assignments.json,source_plan.json, andglobal_mapping.json.
Step 5: Render Final MP4s, Export 8-Track Shotcut MLT & Complete Delivery Manifest
python scripts/step5_render.py \
--input-dir "<INPUT_DIR>" --work-root "<WORK_ROOT>" --job-id "<JOB_ID>" \
[--delivery-dir "<DELIVERY_DIR>"] [--max-output 0] [--skip-shotcut] [--codec h264_nvenc|libx264]
Verification Checklist
Before reporting completion to the user, verify the JSON output of step5_render.py and <DELIVERY_DIR>/delivery_manifest.json:
batch_status.status == "technical_checks_passed_pending_review"andincomplete == [].- Every
outputs[i].video.path(story_NNN.mp4) exists with validsha256anddecoded_samples_above_full_scale == 0. - Every
outputs[i].files.shotcut_mltexists (unless--skip-shotcut) and passed frame-quantized verification. series.cover_imageis copied into<DELIVERY_DIR>withcover_deviation >= 0.50.- Report the paths to
<DELIVERY_DIR>/delivery_manifest.json, all renderedstory_NNN.mp4files, cover image, and 8-track.mltprojects.
Visual Delivery Showcase (Cross-Agent Popup Binding)
After Step 5 passes the verification checklist, invoke a public visual-window skill (when available in the host Agent/orchestrator) to open an interactive browser showcase for the user summarizing <DELIVERY_DIR>/delivery_manifest.json — so the user can visually inspect the cover, opening episode decision, episode grouping timeline, audio peak safety (decoded_samples_above_full_scale == 0), and clickable output deliverables across any Agent or orchestrator.
Public Skill Binding Order (Agent-Agnostic)
Check which public visual skill is installed in the current host environment and invoke the first match:
- Primary public skill —
visual-explainer(nicobailon/visual-explainer, MIT, 11k+ ★):- Install anywhere (Claude Code, Codex, Cursor, OpenClaw, LobeHub, etc.):
npx skills add https://github.com/nicobailon/visual-explainer --skill visual-explainer - Trigger: Activate
visual-explainer, generate a single self-contained visual delivery page (.src.html→.html) fromdelivery_manifest.json(plusseries.cover_imagepreview andevidence_timeline_png/evidence_frames_jpg), and open it in the browser (--openor native viewer).
- Install anywhere (Claude Code, Codex, Cursor, OpenClaw, LobeHub, etc.):
- Secondary public skill —
answer-me-with-html(qingyuna/answer-me-with-html, 6.6k+ ★):- Install anywhere:
npx skills add https://github.com/qingyuna/answer-me-with-html --skill answer-me-with-html - Trigger: Activate
answer-me-with-htmland write the structured delivery draft (title, cover metrics, opening hook rationale, output grouping table, audio peak verification, file paths) so itsamCLI renders and opens the browser page.
- Install anywhere:
- Host-native / Zero-dependency fallback (if neither public skill is installed yet):
- Offer the one-line
npx skills addinstall command above if the user wants the full interactive skill, or use the host's built-in visual surface (e.g.artifacts/lobe-canvas/open-design/browser-preview) — or write a standalone<DELIVERY_DIR>/delivery_preview.htmlreferencing the local cover image and manifest metrics and open it with the system default browser (Start-Processon Windows /openon macOS /xdg-openon Linux).
- Offer the one-line
What the Visual Delivery Window Must Display
- Series Header: Final series title (
series.title),title_revision, adopted 9:16 cover image (series.cover_image), andlayout_v2deviation score (series.cover_deviation >= 0.50). - Opening & Grouping Overview: Chosen opening episode (
plan.opening.episode) + one-sentence rationale (plan.opening.reason), canvas (width x height @ fps), playback speed, and visual timeline bar of alloutputs[](output_id, episode range, duration,cut_adjusted,needs_review). - Quality & Safety Verification:
batch_status.status,outputs_ok / outputs_planned, per-outputrender_profile,gain_db,decoded_stereo_peak, anddecoded_samples_above_full_scale == 0badge. - Deliverable Links / Paths: Quick-access list of every
story_NNN.mp4,shotcut_NNN.mlt,remapped.srt, anddelivery_manifest.json.