AI Short Video Factory (ai-short-video-factory)
One sentence: Humans do only three things—choose the topic, revise the script, and approve the final video; everything else is handled by the agent.
This workflow has been iterated over 20+ real WeChat Video productions. The single biggest lesson learned: "Static standing" is a completion rate killer. Early template videos had 66–73% static frames, with the longest freeze lasting 5.5 seconds; after switching to "one micro-motion every 1–1.4 seconds + full-video static frame detection gate," static frames dropped to 0–5%.
flowchart LR
A[1 Topic] --> B{{Gate 1 Human: Topic + Angle}}
B --> C[2 Voiceover Script] --> D{{Gate 2 Human: Revise Script + Storyboard}}
D --> E[3 TTS + timeline.json]
E --> F[4 HyperFrames Motion Coding]
E --> G[5 SFX + BGM Mix -14 LUFS]
F --> H[6 Cover Burned into First Frame + Render]
G --> H
H --> I[7 Auto QA x3]
I -->|FAIL| F
I --> J{{Gate 3 Human: Final Review}}
J --> K[9 Publish Copy] --> L[10 Deploy to Cloud Run Mobile Delivery Page]
L --> M[Data Review]
0. One-Time Environment Setup
| Dependency | Purpose | Install / Verify |
|---|---|---|
gcloud + ADC | Call Vertex AI (TTS / Lyria / QA models) | gcloud auth application-default login |
| GCP Project | Must enable Vertex AI, access gemini-3.8-flash-tts, lyria-3-pro-preview | export GCP_PROJECT=<your-project-id> |
| Node ≥ 20 | HyperFrames rendering | node -v; npx hyperframes --help |
| ffmpeg / ffprobe | Video editing, mixing, encoding | ffmpeg -version |
| Python 3 + numpy + scipy | Sound effect synthesis, QA | pip install numpy scipy |
| Cloud Run (Step 10) | Mobile delivery page | Enable Cloud Run + Cloud Build APIs; you need Owner or Cloud Run Admin |
| Chinese Fonts | Text rendering | Noto Sans SC Bold (body), ZCOOL KuaiLe / LXGW WenKai (handwritten style) |
| HyperFrames skill (recommended) | Let coding agent master HTML→MP4 | git clone https://github.com/heygen-com/hyperframes, copy skills to your skills directory |
| impeccable (optional) | Anti-AI-design pattern detection | git clone https://github.com/pbakaus/impeccable, place CLI in PATH as impeccable |
[!IMPORTANT] All scripts read project ID from environment variables. Never hardcode anyone's project ID or personal assets into the skill.
Working directory convention (one folder per episode):
episodes/<slug>/
script.json # Voiceover script (post-Gate 2 version)
shared/ # TTS sentence wavs, voice.wav, timeline.json, bgm.mp3
p9x16/index.html # HyperFrames composition page (generated by work/*.py)
p9x16/assets/ # Fonts, images, audio/mix.wav
work/ # Modular generators base.py / s1_6.py / s7_12.py / tail.py
out/cover_9x16.png # Cover image
out/<slug>_9x16.mp4 # Final video
publish.json # Title + WeChat Video description + Moments caption (used in Step 10)
1. Topic Selection (Agent Research → Gate 1 Human Approval)
- Scan 10 candidates daily (5 international + 5 domestic): HackerNews, GitHub Trending, YouTube, X, industry media, company official blogs.
- For each candidate, provide: Event facts (with original links) + counterintuitive points + 3 angles A/B/C + ≤15-character hook.
- Topic scoring priority: Shareability (an "image conclusion" sharable in work groups) > Counterintuitive > Timeliness.
- 🛑 Gate 1: Present candidates to the user; wait for user to select "topic + angle + visual style" before writing the script.
[!CAUTION] Factual accuracy is a red line: Every number, company, and product capability must be traceable to a primary source; never attribute A's capability to B. When adapting/repurposing external videos, strip the original creator's ads in the background. Write the script 100% from a first-person, original perspective. Never use phrases like "from the original video" or "translated from."
2. Voiceover Script (→ Gate 2 Human Confirmation)
See references/script_formula.md for details. Hard requirements:
- 12–14 sentences, each 18–26 Chinese characters, spoken in ≤ 3–4.2 seconds, total 45–65 seconds.
- Structure:
Hook (L1-L2) → Evidence/Numbers (L3-L5) → Underlying Logic (L6-L9) → 3 Screenshot-Worthy Conclusions (L10-L12) → Personal IP Ending (final sentence). - The first second must contain conflict or numbers, zero warm-up; end with a "one-image summary table" to drive screenshots and sharing.
- Each sentence must have 2–4
keywords(for visual emphasis and sound effect timing). - Output
script.json(format in templates/script.example.json), and provide 2 alternative hooks. - 🛑 Gate 2: Present the script + storyboard to the user for sentence-by-sentence confirmation. Do not generate TTS or render video until the user explicitly says "start production."
3. Storyboard (Passes Gate 2 Along with Script)
See references/storyboard_motion.md for details. Core rules:
- One focus per screen: At any time, ≤ 12–15 Chinese characters on screen, whitespace ≥ 60%.
- Zero static standing: Break each sentence into 3 micro-beats (start / +36% / +68%), with a visible change every 1.0–1.4 seconds (fly-in, highlighter stroke, red line strikethrough, number counter, stamp slam, camera zoom).
- Safe area: 1080×1920 canvas, critical content only in
y = 290–1640px(avoid Dynamic Island, platform top bars, and bottom caption areas). - Light backgrounds (cream / paper / light blue), avoid dark dashboards; change style template per topic, don't repeat the same one every episode.
- No bottom scrolling captions; key words appear as large text in the center of the screen.
4. Voiceover: Gemini TTS + timeline.json
export GCP_PROJECT=<your-project-id>
python3 scripts/synth_voice.py episodes/<slug>/script.json episodes/<slug>/shared
# Optional env vars: TTS_VOICE=Orus ATEMPO=1.26 GAP=0.14
- Synthesize sentence by sentence → Verify with
gemini-2.5-flashdictation (auto-retry up to 3 times for missing/incorrect words) → Trim leading/trailing silence → Speed up withatempo→ Concatenate. - Output
voice.wav+timeline.json(each sentence'sstart_s/end_sand keyword timings) + Lyria 3 Pro custom BGM (bgm.mp3). - Speed recommendations: Male voice
OrusatATEMPO=1.26(steady); for faster pace, go to 1.40–1.48. Inter-sentence pause 0.12–0.14s, inter-paragraph pause 0.20–0.28s. - timeline.json is the single timeline for all subsequent animations and sound effects. If the script changes, re-run this step.
5. Motion Graphics Coding: HyperFrames (Use the Best Coding Model)
- Engine selection: In blind tests HyperFrames (HTML + GSAP → PNG sequence) was preferred over Remotion; use it as the default engine.
- Delegate coding to a dedicated worker agent (use your agent's sub-agent / multi-agent feature to spawn a strong coding model worker, e.g., Claude Code subagent); brief template in references/worker_brief.md. The brief must include: complete storyboard, timeline.json, safe area, color palette, QA gate thresholds.
- The generator must be modular:
base.py(CSS/SVG utility functions) +s1_6.py+s7_12.py+tail.py(assembly + GSAP timeline), each file < 300 lines.- Reason: Having the model write 1000+ lines in one go can cause streaming timeouts; designing 3 scenes at once burns output tokens on thinking. Write only 1 scene per write.
- All animations attach to a single GSAP
tl, with timings read from timeline.json. Every micro-beat is aligned to a voiceover keyword.
6. Sound Effects + BGM Mix
python3 scripts/sfx_mix.py --timeline episodes/<slug>/shared/timeline.json \
--bgm episodes/<slug>/shared/bgm.mp3 --out episodes/<slug>/p9x16/assets/audio/mix.wav
- Procedurally synthesize sfx using numpy: whoosh, pop, handwriting scratch, hammer drop, chime, click, automatically tiled per "3 micro-beats per sentence + 1 click per keyword."
- Duck BGM by cutting 400–2600Hz vocal frequency band + sidechain compression (automatically lower by 9.5dB when voice is active).
- All three tracks must be present: voice + SFX + BGM, final loudness -14 LUFS / ≤ -1.5 dBTP (universal platform standard).
7. Cover + Rendering
Cover rules in references/cover_rules.md: light background, exaggerated facial expression, ≤10 giant characters, subject within WeChat Video's 6:7 crop safe area (1080×1920's y=330–1590).
Burn the cover directly into the first frame of the final video, no separate upload.
bash scripts/build.sh episodes/<slug> # Render PNG sequence → Replace first frame with cover → Mix in mix.wav → x264 encode → motion_qa
Encoding parameters: -crf 23 -maxrate 2200k -bufsize 4400k -pix_fmt yuv420p -movflags +faststart, ~15–19 MB for a 60s video, suitable for mobile transfer and web hosting (many serverless platforms have a 32 MiB response limit).
8. Three Automated QA Gates (All Must PASS Before Showing to User)
| Gate | Command / Method | Pass Criteria |
|---|---|---|
| ① Full video static detection | python3 scripts/motion_qa.py out.mp4 | Static frames ≤ 40%, longest freeze ≤ 1.5s (achieved 0–5% in practice) |
| ② Anti-AI design pattern detection | python3 scripts/impeccable_qa.py p9x16/index.html | 0 major anti-patterns (color stripe borders, glow shadows, cards within cards, low-contrast gray text, gradient text, bounce animations…) |
| ③ Independent reviewer agent | Spawn another agent that can only see the MP4, review frame by frame per references/qa_checklist.md | 0 blockers |
[!WARNING] Grabbing a few keyframe screenshots and saying "looks good" does not count as QA—that's exactly how early videos hid 5-second freezes. You must run the full motion_qa and have an agent that hasn't seen the code and only watches the final video watch it from start to finish. The reviewer agent once caught issues motion_qa missed: missing title on frame 0, an empty 1.35s gap, an almost entirely empty frame, and the ending title blocked by a CTA.
🛑 Gate 3: After QA passes, give the final video to the user; proceed to publishing only after user approval.
9. Publishing Copy + Data Review
- WeChat Video description: 1–2 sentences + 4–5 #tags, short and punchy; Moments caption ≤ 12 characters, as if talking to a friend.
- YouTube: No internal links, no "comment with keyword to get materials"; pin a comment written as a technical discussion between peers.
- Review (T+24h / T+72h / T+7d): North star = Share rate × Completion rate; also track 3-second retention, average watch percentage, likes, saves, followers. Viral hit = Views ≥ median of last 10 × 5 and share rate ≥ 3%. Real experience: 3-second retention depends on a strong hook on frame 0 (no fade-in); share rate depends on the "one-image comparison table" at the end; average watch time for 60-second videos is only 23 seconds → 45 seconds is optimal.
- Save to
episodes/<slug>/publish.json:{"title": "...", "description": "...", "moments": "..."}, Step 10 reads it directly.
10. One-Click Deploy to Cloud Run Mobile Delivery Page (Default Delivery Method)
Don't leave the final video only on the agent's machine—deploy it to a page that mobile users can open directly, watch, save to their camera roll, and copy captions with one tap.
export GCP_PROJECT=<your-project-id> # Required
export ACCESS_KEY=<any-passphrase> # Recommended: page requires ?k=password to open (remembered for 90 days after first visit)
bash scripts/publish.sh episodes/<slug>
# → ✅ Open on phone: https://short-video-hub-xxxx.a.run.app/<slug>/?k=password
Page content (scripts/deliver/, Flask + gunicorn, ~100 lines):
- Video player (supports Range requests, draggable progress on iPhone Safari)
- 📲 Save to phone album: Page preloads MP4 in background on open; tap button invokes system share menu → select "Save Video" directly to camera roll (not to Files app)
- ⬇️ Direct MP4 download (for desktop)
- 📋 One-tap copy description / 📋 One-tap copy Moments caption
- Homepage
/lists all published episodes (usesSITE_DIRlocal directory to retain history; adds one episode per deploy, then redeploys everything)
Optional env vars: REGION (default asia-east1), SERVICE (default short-video-hub), SITE_DIR (default ./video-hub-site), SITE_TITLE, PUBLIC_MODE=iam.
After publishing, the agent must self-test before sending the link to the user: the script automatically checks if the page returns 200 and the video Range request returns 206; if you have a browser tool, also simulate tapping play, dragging progress, and tapping each button.
[!WARNING]
- 32 MiB limit: Cloud Run non-streaming responses cannot exceed 32 MiB; exceeding it will cause 500 errors on play/save.
publish.shrejects files > 30 MiB; with Step 7 encoding parameters, a 60s video is ~15–19 MB.- Public access: The script defaults to
--no-invoker-iam-check(no need to grant allUsers access—many companies' organization policies forbid allUsers). However, it requiresrun.services.setIamPolicypermission on the project (project Owner / Cloud Run Admin have it). If you getrequire run.services.setIamPolicy: ask your project admin to grant permissions, or move thatgcloud run services update <SERVICE> --no-invoker-iam-checkinto Cloud Build with the Cloud Build service account. If organization policy forbidsingress=all(smoke check returns 403/404), deploy to a personal project instead.- Anyone with the link can view, do not put confidential content; set
ACCESS_KEYto block casual strangers.
Gotchas (Already Encountered)
- When running ffmpeg in a background shell, always add
-nostdin(orstdin=DEVNULL), otherwise it will hang forever. - HyperFrames directly outputting MP4 can cause the rightmost 8px to turn black, and AAC get compressed to -24 LUFS on some ffmpeg versions → use
--format png-sequenceand mux yourself. - Don't output with
-movflags +faststartdirectly on a network file system (FUSE); write to local disk first, then copy. - If the coding agent opens any image with either dimension > 2000px, it can cause a 400 error that permanently corrupts the chat → keep preview images ≤ 2000px.
- When assigning work to a background worker, also start a 5–6 minute timer to check the worker's status; auto-replace the worker if it crashes due to quota issues.
- Handwriting fonts (e.g., ZCOOL KuaiLe) are missing some glyphs (e.g., digit
0); render digits using a bold sans-serif font separately. npx skills add ... --yeswithout a TTY may hang on interactive prompts; just git clone and copy.
Customization (Must Change When Sharing)
Configure your own in the brand field of script.json: account name, one-sentence positioning, ending voiceover line, avatar/cartoon character path.
The final voiceover sentence and the personal IP ending card on screen must appear together—do not only have a silent ending card.