Communitygithub.com

autocut-story

End-to-end 5-step short-drama story editing and rendering pipeline (probe episodes, Agent-driven series title & Agent-generated cover with local layout_v2 visual deviation verification, Agent-driven opening episode selection & continuous whole-episode playback-duration DP planning, whole-series assembly/vocal separation/ASR/CAM++ speaker diarization/subtitle-aligned slicing, and peak-safe MP4 rendering with 8-track Shotcut MLT export and full delivery manifest). Use when the user provides a directory of short-drama episode videos and wants to produce multi-part original-dialogue story cuts with covers, subtitles, 8-track projects, and complete delivery metadata without any external LLM or image API keys.

Qu'est-ce que autocut-story ?

autocut-story is a Claude Code agent skill that end-to-end 5-step short-drama story editing and rendering pipeline (probe episodes, Agent-driven series title & Agent-generated cover with local layout_v2 visual deviation verification, Agent-driven opening episode selection & continuous whole-episode playback-duration DP planning, whole-series assembly/vocal separation/ASR/CAM++ speaker diarization/subtitle-aligned slicing, and peak-safe MP4 rendering with 8-track Shotcut MLT export and full delivery manifest). Use when the user provides a directory of short-drama episode videos and wants to produce multi-part original-dialogue story cuts with covers, subtitles, 8-track projects, and complete delivery metadata without any external LLM or image API keys.

Compatible avec✓Claude Code✓Codex CLI✓Cursor
npx skills add https://github.com/anxu-collab/autocut-skills/tree/HEAD/skills/autocut-story

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

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):

    1. Step 2A — Series Title & Genre Suggestion: Propose 3 natural short-drama title candidates + cover_style genre.
    2. 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_prompt if local layout_v2 visual deviation < 0.50.
    3. Step 3A — Opening Episode Selection: Read candidate episodes' ASR dialogue brief (opening_brief.md) and select the strongest hook episode + one-sentence reason.
  • Local Scripts own (deterministic & local GPU models):

    • FFprobe scanning, majority canvas selection (step1_probe.py)
    • Title validation, hallucinated-surname guard, series_v1 revision tracking, reference frame extraction, layout_v2 deviation check (step2_title_cover.py)
    • Candidate Whisper ASR, evidence_sha256 verification, playback_dp_v2 whole-episode DP grouping (step3_plan.py)
    • Whole-series merged.mkv, vocal_remover / demucs separation, 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.mp4 rendering, AAC decode-peak verification with auto step-down retry, timeline_map.json, frame-verified 8-track shotcut_NNN.mlt, and delivery_manifest.json (step5_render.py)
  • 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_remover CascadedNet UNet, faster-whisper-medium ASR, campplus_cn_common CAM++ diarization) runs inside a short-lived isolated subprocess (lib/runtime.py::run_isolated with Windows JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE / POSIX start_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-lived ffmpeg subprocesses that release NVENC sessions immediately on exit.
    • Before every GPU stage, require_gpu_ready() checks nvidia-smi thresholds (story.gpu.max_memory_mib / max_utilization_pct) to avoid colliding with concurrent GPU jobs.

Detailed rules and schemas:


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. Check remediation warnings (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-run doctor.py until ready: true.

Agent-Assisted Setup Loop (Follow remediation[] Item by Item)

  1. Confirm Runtime Environment (execution_context.likely_sandbox == true):
    • If doctor.py flags execution_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.
  2. 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 home models/, 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 by package_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_layout and download_hint from remediation[], ask the user either for their existing local path or permission to download/install, and persist once ready.
  3. Python Dependencies (python_packages_missing):
    • Confirm whether the user has a dedicated venv / conda environment 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.
  4. GPU / CPU Fallback Advisory (gpu_fallback_advisory & gpu_busy):
    • If gpu.cuda_available == false or gpu.h264_nvenc == false, explicitly inform the user that GPU acceleration is unavailable and CPU/libx264 rendering will be significantly slower. Ask whether to enable and persist CPU fallback defaults:
      python scripts/doctor.py --cpu-fallback --save-local
      
      (--cpu-fallback writes separate/asr/diarize device=cpu, asr.compute_type=int8, and render.codec=libx264 into configs/local.yaml.)
    • If gpu.nvidia_smi.gate_ok == false (gpu_busy), advise the user to free VRAM/GPU utilization before starting Step 3–5.
  5. Disk Space Warning (disk_space_low):
    • If disk.ok == false (default threshold 5.0 GB, tunable via --min-disk-gb), suggest picking a --work-root on a drive with more free space.
  6. Re-Verify Gate:
    • Re-run python scripts/doctor.py --work-root "<WORK_ROOT>" with no extra flags (it automatically merges configs/default.yaml → configs/local.yaml → --config → CLI/env overrides). Proceed to Step 1 only when ready == true.

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

  1. 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: true and the user does not request a rename or cover regeneration, skip directly to Step 3.

  2. 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_style from neutral | 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>"
      
  3. 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, and min_deviation (0.5).
    • Call the host Agent's image generation tool/model (e.g. image-generator) with reference as the reference image, vertical 9:16 aspect ratio, and prompt. 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 using stronger_prompt (changing pose, crop, outfit, backdrop, and color palette while preserving recognizable faces) and re-run commit-cover --attempt 2 --used-stronger-prompt.

Step 3: Agent Opening Selection & Whole-Episode DP Planning

  1. 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>"]
    
  2. Agent reads brief_md_path and 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.
  3. Commit opening & generate timeline/plan.json:
    python 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]
    
    Review outputs_summary (especially if grouping_relaxed: true or any item has needs_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-accurate merged.mkv, vocals.wav, background.wav, remapped.srt, speakers_raw.json, track_assignments.json, source_plan.json, and global_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:

  1. batch_status.status == "technical_checks_passed_pending_review" and incomplete == [].
  2. Every outputs[i].video.path (story_NNN.mp4) exists with valid sha256 and decoded_samples_above_full_scale == 0.
  3. Every outputs[i].files.shotcut_mlt exists (unless --skip-shotcut) and passed frame-quantized verification.
  4. series.cover_image is copied into <DELIVERY_DIR> with cover_deviation >= 0.50.
  5. Report the paths to <DELIVERY_DIR>/delivery_manifest.json, all rendered story_NNN.mp4 files, cover image, and 8-track .mlt projects.

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:

  1. 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) from delivery_manifest.json (plus series.cover_image preview and evidence_timeline_png / evidence_frames_jpg), and open it in the browser (--open or native viewer).
  2. 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-html and write the structured delivery draft (title, cover metrics, opening hook rationale, output grouping table, audio peak verification, file paths) so its am CLI renders and opens the browser page.
  3. Host-native / Zero-dependency fallback (if neither public skill is installed yet):
    • Offer the one-line npx skills add install 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.html referencing the local cover image and manifest metrics and open it with the system default browser (Start-Process on Windows / open on macOS / xdg-open on Linux).

What the Visual Delivery Window Must Display

  • Series Header: Final series title (series.title), title_revision, adopted 9:16 cover image (series.cover_image), and layout_v2 deviation 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 all outputs[] (output_id, episode range, duration, cut_adjusted, needs_review).
  • Quality & Safety Verification: batch_status.status, outputs_ok / outputs_planned, per-output render_profile, gain_db, decoded_stereo_peak, and decoded_samples_above_full_scale == 0 badge.
  • Deliverable Links / Paths: Quick-access list of every story_NNN.mp4, shotcut_NNN.mlt, remapped.srt, and delivery_manifest.json.

Skills associés