videogen/ugc-video-tool-build-plan.md
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

166 lines
10 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UGC Video Generator — Production Build Plan
**Base:** Fork of [MoneyPrinterTurbo](https://github.com/harry0703/MoneyPrinterTurbo) (MIT license)
**Goal:** Production-grade pipeline that turns an app screen recording + optional prompt into a viral-style UGC video: AI avatar presenter (lip-synced), hook-driven script (TR/EN), CapCut-style word-by-word captions, 1080×1920 MP4. Internal use first, SaaS-ready architecture from day one.
---
## 1. Why fork MPT (and what it gives us for free)
MPT already implements ~50% of our pipeline as a clean MVC Python codebase with both a FastAPI REST layer and a web UI:
**Keep as-is:**
- Sequential task pipeline orchestration (`task.start()`) — script → TTS → subtitles → composition → render
- LLM provider abstraction (OpenAI, Claude, Gemini, DeepSeek, Ollama...) — we only swap prompts
- TTS provider abstraction — we add an ElevenLabs adapter
- Subtitle alignment: word-level timing from TTS, or faster-whisper (large-v3) fallback
- Local video material support (MPT already accepts local files instead of stock footage — this is exactly our screen-recording input path)
- FFmpeg/MoviePy composition + 1080×1920 render (libx264, AAC 192k)
- Batch generation (N variants per run — critical for UGC A/B testing)
- FastAPI endpoints for every pipeline capability
**Delete / disable:**
- Pexels/Pixabay stock footage sourcing (irrelevant — our footage is the user's screen recording)
- Generic "topic → essay" script prompts (replaced with UGC persona prompts)
**Build new (the real work — ~4 modules):**
1. Avatar generation + lip-sync stage
2. PiP/split-screen composition layer (avatar over screen recording)
3. Karaoke-style word-emphasis captions (MPT's subtitles are static lines — not viral style)
4. Production infra: job queue, storage, auth, billing
---
## 2. Target pipeline
```
INPUT: screen_recording.mp4 + optional prompt + language (tr|en) + avatar_id + voice_id
│
├─ 1. SCRIPT (LLM) → hook-first UGC script, 30–60s, TR or EN
├─ 2. TTS (ElevenLabs) → audio + character-level timestamps
├─ 3. AVATAR (lip-sync) → talking-head video synced to the audio
├─ 4. CAPTIONS → word-by-word ASS subtitles from TTS timestamps
├─ 5. COMPOSE (FFmpeg) → screen recording (bg) + avatar PiP + captions + optional music
└─ 6. RENDER → 1080×1920 MP4, NVENC/VideoToolbox hw-accel where available
OUTPUT: ready-to-post vertical video (+ N batch variants)
```
---
## 3. Module specs
### 3.1 Script generation (modify MPT's LLM service)
- System prompt = "TikTok UGC creator" persona. Inputs: app description, optional user prompt, target language, desired duration.
- Output must be **structured JSON**: `{hook, body_segments[], cta, estimated_duration_s}`. Hook constraint: ≤ 2 seconds of speech, pattern-interrupt style.
- Maintain a hook-template library (e.g. "I wasn't going to share this but...", "POV:", "3 apps that...") as few-shot examples per language. Turkish hooks written natively, not translated.
- Model: Claude Sonnet 4.6 or GPT-4o via MPT's existing provider layer.
### 3.2 TTS (new ElevenLabs adapter)
- `eleven_multilingual_v2` — natural Turkish and English from the same voice.
- Use the `/with-timestamps` endpoint → character-level timing. This **eliminates Whisper from the happy path** (faster, cheaper, zero desync since captions come from the same source as audio).
- Keep MPT's faster-whisper as fallback for user-uploaded voiceovers.
### 3.3 Avatar + lip-sync (new stage — the core new module)
Two-tier strategy, both behind one `AvatarProvider` interface:
| Tier | Provider | Cost | When |
|---|---|---|---|
| A (launch) | HeyGen API (or D-ID as cheaper alt) | ~$0.50–1.00 / min | Phase 1–2: quality + zero infra |
| B (scale) | Self-hosted **LatentSync** or **MuseTalk** on GPU worker (RunPod/Hetzner GPU, ~$0.40/hr) | ~$0.02–0.05 / min | Phase 3: margin optimization |
- Input: audio file + avatar reference (preset library of ~10 stock UGC-style avatars, later user photo upload).
- Output: transparent-background or green-screen talking head clip, ≥ 512×512, matched to audio duration.
- The interface abstraction means switching providers is a config change, not a rewrite.
### 3.4 Captions (new renderer)
- Convert ElevenLabs character timestamps → word groups → **ASS subtitle file with karaoke tags** (`\k`), burned in via FFmpeg `libass`. This gives frame-accurate word-by-word pop with color emphasis (white→yellow), stroke/outline, positioned upper-third — CapCut style — with no per-frame Python rendering cost.
- Configurable: font (bundle 3–4 licensed bold fonts incl. Turkish glyph coverage — critical: İ, ş, ğ, ö, ü), colors, position, words-per-group (1–3).
### 3.5 Composition (extend MPT's video service)
- Layouts: (a) fullscreen recording + avatar PiP bottom corner (circle or rounded-rect mask), (b) split screen 50/50, (c) avatar fullscreen intro (hook, 0–3s) → cut to screen recording. Layout selectable per job; (c) is the default because it performs best for hooks.
- Smart screen-recording handling: auto-crop/scale to 9:16, speed-ramp long recordings to fit script duration, trim dead frames at start.
- Single FFmpeg filter-graph pass for overlay + captions + audio mix (voiceover ducked over optional bg music) → avoids multi-pass re-encoding.
---
## 4. Production infrastructure (SaaS-ready from day one)
- **API:** MPT's FastAPI, extended. Async job model: `POST /v1/jobs` → job_id → poll/webhook.
- **Queue/workers:** Redis + separate render workers (rendering must never block the API). Docker Compose → later split API vs. GPU worker nodes.
- **Storage:** Cloudflare R2 (uploads + outputs, presigned URLs, zero egress fees).
- **DB:** Postgres on Neon — jobs, users, credits, assets. (We already run Neon + Hetzner + Cloudflare; deploy on this stack.)
- **Auth:** email + Google OAuth (Phase 2).
- **Billing:** credit-based; Stripe (global) + iyzico (TR cards) (Phase 3).
- **Observability:** per-stage timing + cost logged per job (LLM tokens, TTS chars, avatar seconds) — we need unit economics from job #1.
---
## 5. Phases & acceptance criteria
**Phase 1 — Production pipeline, internal use (3–4 weeks)**
Fork MPT, strip stock-footage path, add ElevenLabs adapter, HeyGen avatar stage, ASS karaoke captions, 3 composition layouts, async job API, R2 storage, Docker deploy on Hetzner.
✅ Accept: screen recording + prompt in → posted-quality 1080×1920 MP4 out, TR and EN, zero audible desync (≤ 50ms audio/caption drift), ≤ 5 min wall-clock for a 60s video, batch of 3 variants per run.
**Phase 2 — Web platform (2–3 weeks)**
Auth, dashboard (job history, previews, re-run with tweaks), UI controls: avatar/voice/caption-style/layout pickers, prompt field. Replace Streamlit with a proper Next.js frontend hitting the FastAPI.
✅ Accept: a non-technical user produces a video end-to-end without touching the API.
**Phase 3 — Commercialization (3–4 weeks)**
Stripe + iyzico credits, usage metering, self-hosted lip-sync tier for margin, direct publish to TikTok/IG/Shorts (MPT already integrates Upload-Post — reuse it), mobile app (thin client over the same API).
✅ Accept: paying user flow live; marginal cost per 60s video ≤ $0.30 on self-hosted tier.
---
## 6. Unit economics (per 60s video, Phase 1)
| Item | Est. cost |
|---|---|
| LLM script | <$0.01 |
| ElevenLabs TTS (~150 words) | ~$0.10–0.20 |
| HeyGen avatar (60s) | ~$0.50–1.00 |
| Render compute | ~$0.01 |
| **Total (API tier)** | **~$0.65–1.20** |
| **Total (self-hosted lip-sync, Phase 3)** | **~$0.15–0.30** |
Pricing later at ~$1.50–2.50/video (credit packs) leaves healthy margin even on the API tier.
## 7. Risks & mitigations
- **Avatar API cost/rate limits** → provider abstraction + Tier B plan from the start.
- **Turkish caption rendering** (glyphs, hyphenation) → font QA in week 1, Turkish-native hook prompts, native-TR test set.
- **Desync** → single source of truth for timing (TTS timestamps drive both lip-sync input and captions); automated drift check in CI (compare caption timing vs. audio envelope).
- **MPT MoviePy bottleneck** → keep MoviePy only for prototyping; production render path is a pure FFmpeg filter-graph.
- **Platform ToS on AI content** → auto-tag YouTube uploads as AI-generated (MPT already does this); keep disclosure toggle for TikTok/IG.
## 8. Deliverables checklist for the developer
1. Forked repo, stock-footage path removed, config-driven pipeline ✅
2. `ElevenLabsTTSProvider` with timestamp support ✅
3. `AvatarProvider` interface + HeyGen implementation ✅
4. ASS karaoke caption generator (TR/EN fonts bundled) ✅
5. FFmpeg composition service (3 layouts, hw-accel) ✅
6. Async job API + Redis workers + R2 storage, Dockerized ✅
7. Per-job cost/timing telemetry ✅
8. 10-video golden test set (5 TR / 5 EN) passing acceptance criteria ✅ (local gate)
---
## 9. Platform expansion (beyond the original 3-phase plan)
The Phase-1/2/3 pipeline above is delivered. On top of it the product became a
**pay-as-you-go, multi-provider platform** — see
[`docs/reelforge/PROVIDER_MARKETPLACE_PLAN.md`], [`docs/reelforge/PRODUCT_ROADMAP.md`],
and CTO-plan §11.
- **Wallet + Creem checkout** (USD microdollar ledger, reserve/settle/release,
signed-webhook grant) replaces fixed credit packs for marketplace jobs.
- **Model catalog + generation profiles + signed quotes**; a routing engine with
five provider adapters (OpenRouter/ElevenLabs/HeyGen/Pixelle/Image), consented
fallback, and settle-at-measured-cost on the Celery `generation` queue.
- **BYOK** encrypted customer keys (per-use audit, consent gate, disclosed
routing fee); **spend controls** (per-user + per-workspace monthly budget caps).
- **Repurposing engine**: long video → transcript → LLM-ranked highlight clips →
promote into reel drafts (Opus Clip / ClipsAI class).
- **Clients**: Next.js wallet/catalog/model-picker + reel-wizard paygo selector;
Expo wallet + catalog screens.
**Next (⏭):** SadTalker photo-avatar provider · multi-backend voice fallback ·
ReelForge MCP server (agent distribution) · OpenCut editor · usage analytics.