An enterprise-grade, high-throughput automated video production pipeline designed to transform raw story text into fully edited, high-definition short-form videos (YouTube Shorts, TikToks, Instagram Reels, and Manhwa recaps).
This pipeline orchestrates multi-agent LLM script expansion (Google Gemini API & Local Ollama Qwen 2.5), asynchronous text-to-speech engine (Edge-TTS / FastAPI), cloud/local diffusion rendering (ComfyUI, Wan 2.1, LTX-2), and programmatic motion editing via FFmpeg.
- ** Multi-LLM Agentic Scripting:** Leverages Gemini 1.5/2.0 for macro-scene breakdown and Local Ollama (Qwen 2.5 Uncensored) for granular beat expansion, character consistency prompts, and scene-by-scene timing metadata.
- ** Asynchronous Microservice TTS:** Built custom
FastAPIservice wrapper aroundedge-ttsfeaturing concurrent audio generation and automated speech duration profiling. - Hybrid Rendering Engine (Local & Cloud Distributed):
- Cloud GPU Workers: Features distributed Google Colab/Kaggle rendering nodes utilizing state-of-the-art Wan 2.1 and LTX-2 video models with lock-based state synchronization via Google Drive.
- ** Dynamic Audio-Visual Syncing:** Eliminates frame drift and static freezes. Calculates dynamic zoom/pan frame counts (
d = tts_duration * fps) on-the-fly for exact audio-visual alignment. - ** Automated Corruption Guard (
ffprobeValidation):** Built-in fault tolerance inspects generated MP4 streams viaffprobeimmediately post-creation. Corrupted or truncated segments trigger immediate fallback and auto-re-rendering loops. - ** Multi-Threaded FFmpeg Editing:** Utilizes Python
ThreadPoolExecutorcapped at optimal worker limits to perform Ken Burns pan-zoom motion FX and multi-track audio stitching without CPU/disk throttling. - ** Orchestration via n8n & Docker:** Pre-configured Docker Compose stack with n8n workflows for trigger-based, no-code/low-code operational pipelines.
[ Raw Story Input (.txt) ]
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. AI Script & Prompt Generation Engine β
β β’ Gemini API: Scene Segmentation β
β β’ Local Ollama (Qwen2.5): Beat Expansion & Prompts β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Outputs Structured JSON
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 2. Concurrent Asset Generation Subsystem β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ€
β FastAPI Edge-TTS β ComfyUI / Wan 2.1 Cloud β
β (Parallel Voiceovers) β (Parallel Image/Video) β
βββββββββββββββ¬ββββββββββββββ΄ββββββββββββββ¬ββββββββββββββ
β β
βββββββββββββββ¬ββββββββββββββ
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3. Automated Integrity Verification β
β β’ ffprobe validation check per frame/audio track β
β β’ Dynamic Zoompan frame sync calculation β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ
β Validated Streams
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 4. FFmpeg Video Compositing & Stitching β
β β’ Multi-threaded Ken Burns Motion FX β
β β’ Audio/Visual Merging -> Final Output MP4 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Core Backend: Python 3.10+, FastAPI, Uvicorn
- LLM Orchestration: Google Gemini API, Ollama (
qwen2.5-abliterate:7b,Qwen2.5-Coder-7B-Instruct) - Speech Synthesis:
edge-tts, Asyncio, FastAPI - Image & Video Synthesis: ComfyUI API, Wan 2.1, LTX-2, Google Colab GPUs
- Video Processing: FFmpeg,
ffprobe, Pythonpydub/subprocess - Automation & DevOps: Docker, Docker Compose, n8n, Google Drive API
Ensure the following tools are installed on your environment:
- Python 3.10+
- FFmpeg (Added to System
PATH) - ComfyUI (Running locally on default port
8188) - Ollama with required models pulled:
ollama run huihui_ai/qwen2.5-abliterate:7b ollama run thirdeyeai/Qwen2.5-Coder-7B-Instruct-Uncensored:Q4_0
- (Optional) Docker Desktop for n8n visual automation.
git clone https://github.com/your-username/automated-ai-video-pipeline.git
cd automated-ai-video-pipeline
# Create & activate virtual environment
python -m venv venv
# On Windows:
venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtCreate a .env file in the root directory:
GEMINI_API_KEY=your_gemini_api_key_here
HF_TOKEN=your_huggingface_token_here
CANVAS_WIDTH=1080
CANVAS_HEIGHT=1920
FPS=30
COMFYUI_URL=http://127.0.0.1:8188
TTS_SERVER_URL=http://127.0.0.1:8765Start the lightweight FastAPI TTS server in an independent shell:
python tts_server.pyServer listens at http://127.0.0.1:8765/tts.
Pass a raw text file to the AI script writer to decompose it into structured JSON:
python batch_ai_writer.py \
--input story.txt \
--scenes 80 \
--char "young Korean man, 22, sharp jawline, manhwa style, highly detailed"Outputs: story_80scenes.json containing audio text, scene timing, and AI visual prompts.
Run the main local rendering engine:
python local_pipeline.py --script story_80scenes.json| Flag | Description |
|---|---|
--skip-tts |
Bypass audio synthesis if audio files are cached. |
--skip-images |
Bypass image/video generation if visual assets exist. |
--skip-merge |
Skip individual FFmpeg clip rendering steps. |
--no-stitch |
Keep scene MP4s separate; skip rendering final merged movie file. |
For heavy computational video models like Wan 2.1 or LTX-2, offload visual generation to free/paid Cloud GPUs (Google Colab / Kaggle):
- Stage Script Assets to Cloud Storage:
python video_gen_collab/drive_uploader.py --drive-path "G:\My Drive\AnimeFactory" - Execute Worker Notebook:
- Open
video_gen_collab/Wan2GP_Batch_Worker.ipynbin Google Colab. - Select a GPU runtime (T4, L4, or A100).
- Execute cells 1β7 to start the worker. The cloud instance locks unrendered scenes, executes diffusion models, applies voiceovers, and syncs output back to Google Drive.
- Open
- Assemble Final Cut:
- Execute Cell 8 in Colab to assemble and stitch all cloud-rendered scenes into
final_movie.mp4.
- Execute Cell 8 in Colab to assemble and stitch all cloud-rendered scenes into
To manage execution workflows visually using n8n:
cd n8n
docker-compose up -d- Open n8n Dashboard at
http://localhost:5678. - Import
AnythingXL_Manhwa_Workflow.jsonorauto_local_v3_configured.json. - Use
embed_keys.pyto auto-inject API keys into the active n8n instance environment.
.
βββ batch_ai_writer.py # Multi-LLM script writer & visual prompt generator
βββ local_pipeline.py # Primary pipeline execution engine & FFmpeg compositor
βββ tts_server.py # Asynchronous FastAPI Edge-TTS microservice
βββ requirements.txt # Python dependencies
βββ .env # Application environment variables & settings
βββ n8n/ # Visual workflow orchestration
β βββ docker-compose.yml # n8n container deployment configuration
β βββ embed_keys.py # Key injection utility script
β βββ workflows/ # Exported n8n workflow JSON templates
βββ video_gen_collab/ # Cloud GPU worker architecture
βββ Wan2GP_Batch_Worker.ipynb # Colab rendering worker notebook
βββ drive_uploader.py # Lock-state Google Drive asset manager
βββ uploader.py # Remote sync utility
- Parallel Execution Efficiency: Leverages Python's
asyncioandconcurrent.futures.ThreadPoolExecutorto perform concurrent API requests and video frame rendering, reducing pipeline bottleneck time by up to 65%. - Zero-Downtime Reliability: Implemented health checks post-render to ensure corrupted video streams are identified prior to concatenation, preventing broken final renders.
- Deterministic Resource Allocation: Constrained worker thread limits prevent disk I/O locking during heavy FFmpeg encoding tasks.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Distributed under the MIT License. See LICENSE for details.
- Developer: Open for Machine Learning, AI Engineering, and Automation Pipeline roles.
- GitHub: @pranaya-sht
- LinkedIn: pranaya shrestha
- Email:
pranayashrestha8888@gmail.com