Automatically transform articles into engaging short-form videos (Reels/TikToks) using AI.
ReelCraft is an automated video generation pipeline that converts web articles into 30-60 second social media videos. It uses Google's Gemini AI for script generation and text-to-speech, Pexels for stock media, and FFmpeg for video editing. Now with a modern web interface for easy video generation!
- Automatic Script Generation: Converts articles into engaging, fast-paced scripts optimized for short-form video
- AI-Powered Voice Over: Generates natural-sounding voice narration using Gemini TTS
- Smart Asset Selection: Automatically finds and downloads relevant images/videos from Pexels
- Professional Video Editing: Combines visual assets, voice-over, and background music into polished videos
- Parallel Processing: Efficiently generates audio and downloads assets concurrently
- Database Integration: SQLite database for tracking videos, jobs, and metadata
- Cloud Storage Support: Optional Cloudflare R2 integration for scalable video storage
- Job Management: Background job tracking with status updates and cancellation
- Langfuse Integration: Track and monitor AI model calls and performance
- Dynamic Audio Ducking: Background music automatically lowers during voiceover and rises during pauses (professional sidechain compression)
- Text-Only Scenes: AI generates punchy text overlays (1-5 words) on solid backgrounds to emphasize key points
- Smart Aspect Ratios: Landscape videos (16:9) display with blurred background fill for portrait frames (9:16)
- Smooth Transitions: Dynamic scene transitions (fade, wipe, slide) instead of hard cuts for polished flow
- π Modern Web UI: User-friendly interface for generating videos without code
- β‘ Real-time Progress: WebSocket-powered live updates during video generation
- π¬ Video Gallery: Browse, preview, and download all generated videos
- ποΈ Video Management: Delete videos from both local and cloud storage
- π Job Tracking: Monitor and cancel background video generation jobs
- π± Responsive Design: Works seamlessly on desktop and mobile devices
- π REST API: Full-featured API with interactive documentation
- π― One-Click Generation: Simple URL input to video output workflow
Article URL -> Script Generation -> Audio Generation -> Asset Download -> Video Editing -> Final Video
- Content Extraction: Fetches article content using FireCrawl
- Script Generation: Gemini AI converts the article into 7-15 scene scripts with visual keywords
- Audio Generation: Parallel generation of voice-over for each scene, with duration measurement
- Audio-Driven Pacing: Each scene's duration is set by its voiceover length (ensures natural speech)
- Asset Download: Concurrent download of images/videos from Pexels based on keywords
- Video Composition: FFmpeg stitches visual assets to match audio timing, adds background music and effects
ReelCraft now includes a modern, responsive web interface that makes video generation accessible to everyone!
- π¨ Beautiful Dark Theme UI: Modern, eye-friendly interface with smooth animations
- β‘ Real-time Updates: Live progress tracking via WebSocket connection
- π¬ Video Gallery: Browse all your generated videos with preview thumbnails
- π₯ Easy Downloads: One-click download for any generated video
- π± Mobile Responsive: Works perfectly on desktop, tablet, and mobile devices
- π Simple Workflow: Just paste a URL and click generate!
- Start the server:
python main.py - Open http://localhost:8000 in your browser
- Enter an article URL
- Click "Generate Video"
- Watch real-time progress updates
- Preview and download your video!
The FastAPI backend provides comprehensive API documentation:
- Interactive API Docs: http://localhost:8000/docs (Swagger UI)
- Alternative Docs: http://localhost:8000/redoc (ReDoc)
- Detailed Guide: See API.md for complete reference
Health & Status
GET /health- Health check
Video Generation
POST /api/generate-video- Generate video from URL (creates background job)WS /ws- WebSocket for real-time progress updates
Video Management
GET /api/videos- List all generated videos with metadataGET /api/videos/{video_id}/file- Stream/download video file by IDDELETE /api/videos/{video_id}- Delete video (local and/or cloud storage)
Job Management
GET /api/jobs- List all background jobsGET /api/jobs/{job_id}- Get specific job statusPOST /api/jobs/{job_id}/cancel- Cancel running job
- Python 3.11 or higher
- FFmpeg installed on your system
- Virtual environment tool (venv or uv)
-
Clone the repository
git clone <repository-url> cd reelcraft
-
Create and activate virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
Using uv (recommended):
uv sync
Or using pip:
pip install -e . -
Set up environment variables
Create a
.envfile in the project root:# Required API Keys GEMINI_API_KEY=your_gemini_api_key_here PEXELS_API_KEY=your_pexels_api_key_here FIRECRAWL_API_KEY=your_firecrawl_api_key_here # Optional - Cloud Storage (Cloudflare R2) R2_ENABLED=false R2_ENDPOINT_URL=https://your-account-id.r2.cloudflarestorage.com R2_ACCESS_KEY_ID=your_r2_access_key R2_SECRET_ACCESS_KEY=your_r2_secret_key R2_BUCKET_NAME=reelcraft-videos R2_PUBLIC_URL=https://videos.yourdomain.com # Optional - Monitoring LANGFUSE_PUBLIC_KEY=your_langfuse_public_key LANGFUSE_SECRET_KEY=your_langfuse_secret_key LANGFUSE_HOST=https://cloud.langfuse.com
Required:
- Gemini API: Get your key at Google AI Studio
- Pexels API: Get your key at Pexels API
- FireCrawl API: Get your key at FireCrawl
Optional:
- Cloudflare R2: Set up at Cloudflare Dashboard β R2 β Create bucket
- Langfuse: Get your keys at Langfuse
The easiest way to use ReelCraft is through the web interface:
-
Start the server
# Using uv uv run python main.py # Or with activated venv python main.py
-
Open your browser
Navigate to http://localhost:8000
-
Generate videos
- Enter an article URL
- Click "Generate Video"
- Watch real-time progress updates
- Preview and download your video
The web interface provides:
- Real-time progress tracking via WebSocket
- Video preview and download
- Gallery of all generated videos
- Modern, responsive design
For detailed API documentation, visit http://localhost:8000/docs when the server is running, or see API.md.
You can also use ReelCraft programmatically:
import asyncio
from pipeline import pipeline
# Generate a video from an article URL
asyncio.run(pipeline("https://example.com/article"))from pipeline import pipeline, generate_assets
from utils.video_editing import script_to_asset_details, video_editing_pipeline
import asyncio
import json
async def custom_pipeline():
# Step 1: Get article and generate script
article_url = "https://example.com/article"
# ... (rest of pipeline logic)
# Step 2: Add custom background music
asset_details = await script_to_asset_details(
script,
background_music_path="path/to/music.mp3"
)
# Step 3: Generate video
await video_editing_pipeline(asset_details)
asyncio.run(custom_pipeline())You can also interact with ReelCraft programmatically via the REST API:
import requests
# Generate a video via API
response = requests.post(
"http://localhost:8000/api/generate-video",
json={"url": "https://example.com/article"}
)
result = response.json()
print(f"Video created: {result['video_path']}")
# List all videos
videos = requests.get("http://localhost:8000/api/videos").json()
for video in videos['videos']:
print(f"{video['filename']} - {video['size_mb']} MB")Or using cURL:
# Generate video
curl -X POST "http://localhost:8000/api/generate-video" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/article"}'
# List videos
curl "http://localhost:8000/api/videos"For complete API documentation, visit http://localhost:8000/docs when the server is running, or see API.md.
reelcraft/
βββ main.py # Server entry point (start here!)
βββ pipeline.py # Core video generation pipeline
βββ reelcraft.db # SQLite database (auto-created)
βββ frontend/ # Web interface
β βββ index.html # Main UI page
β βββ style.css # Styling
β βββ app.js # Frontend logic & WebSocket client
βββ services/ # Backend services
β βββ api.py # FastAPI application & REST endpoints
β βββ database.py # SQLAlchemy models & database setup
β βββ storage.py # Cloud storage integration (R2)
βββ config/
β βββ directories.py # Asset folder paths
β βββ prompts.py # AI prompt templates
β βββ logger.py # Logging configuration
β βββ langfuse_config.py # Langfuse monitoring setup
βββ utils/
β βββ ai.py # Gemini AI integration (LLM + TTS)
β βββ assets.py # Pexels asset download
β βββ fire_crawl.py # Article content extraction
β βββ video_editing.py # FFmpeg video composition
β βββ http_client.py # HTTP utilities
βββ assets/
βββ temp/
βββ audio/ # Generated voice-overs
βββ videos/ # Downloaded video assets
βββ images/ # Downloaded image assets
βββ outputs/ # Final generated videos (if stored locally)
ReelCraft uses SQLite with SQLAlchemy for storing video metadata and job information:
- Videos Table: Stores video metadata (title, source URL, file path, storage location, duration, size)
- Jobs Table: Tracks background video generation jobs with status and progress
- Automatic Setup: Database is created automatically on first run at
reelcraft.db
ReelCraft supports Cloudflare R2 (S3-compatible) for scalable video storage:
Benefits:
- Unlimited storage without local disk constraints
- Global CDN delivery for fast video access
- Automatic upload after video generation
- Cost-effective storage (R2 has no egress fees)
Setup:
-
Install boto3 (if not already installed):
uv add boto3 # or: pip install boto3 -
Create R2 bucket at Cloudflare Dashboard:
- Navigate to R2 β Create bucket
- Note your bucket name and account ID
-
Configure environment variables in
.env:R2_ENABLED=true R2_ENDPOINT_URL=https://your-account-id.r2.cloudflarestorage.com R2_ACCESS_KEY_ID=your_access_key R2_SECRET_ACCESS_KEY=your_secret_key R2_BUCKET_NAME=reelcraft-videos R2_PUBLIC_URL=https://videos.yourdomain.com # Optional: custom domain -
Behavior:
- When enabled, videos are automatically uploaded to R2 after generation
- Local copies can be deleted to save disk space
- Videos are served from cloud URL instead of local file
Storage Locations:
local: Video stored only on server diskcloud: Video stored in Cloudflare R2 (can delete local copy)
Edit config/directories.py to change asset locations:
AUDIO_DIR = "assets/temp/audio"
VIDEO_DIR = "assets/temp/videos"
IMAGE_DIR = "assets/temp/images"
OUTPUT_FOLDER = Path("assets/temp/outputs")Customize the script generation prompt in config/prompts.py to adjust:
- Video tone and style
- Scene count (7-15 scenes)
- Script length (30-60 seconds)
- Asset keyword generation
Adjust voice settings in utils/ai.py:
# Change voice
voice_name="Kore" # Available voices: Kore, Aoede, Charon, Fenrir, etc.
# Adjust concurrency (avoid rate limits)
AUDIO_GENERATION_SEMAPHORE = asyncio.Semaphore(3) # Max 3 concurrent requestsModify video parameters in utils/video_editing.py:
fps = 25 # Frame rate
asset_width = 720 # Video width (portrait: 720x1280)
asset_height = 1280 # Video height
# Audio mixing volumes
background_volume = 0.2 # Background music volume
voiceover_volume = 2.0 # Voice-over volumeEach generated script contains:
{
"title": "Video Title",
"scenes": [
{
"scene_number": 1,
"script": "Scene narration text",
"asset_keywords": ["keyword1", "keyword2", "keyword3"],
"asset_type": "image/video",
"audio_file_path": "path/to/audio.wav",
"duration": 5.2,
"asset_file_path": "path/to/visual.mp4"
}
]
}-
Content Extraction (utils/fire_crawl.py)
- Fetches article markdown using FireCrawl API
- WebSocket update: "Extracting article content..."
-
Script Generation (utils/ai.py + config/prompts.py)
- Gemini AI generates 7-15 scenes with narration and asset keywords
- WebSocket update: "Generating script..."
-
Audio Generation (services/pipeline.py:56-71)
- Parallel TTS generation for all scenes (max 3 concurrent)
- Audio-driven pacing: Measures duration of each generated audio file
- Sets scene duration based on voiceover length (ensures natural speech)
- WebSocket update: Progress updates during generation
-
Asset Download (services/pipeline.py:74-76)
- Parallel download of images/videos from Pexels
- Handles "image/video" asset types intelligently
-
Video Composition (utils/video_editing.py)
- Combines all audio files sequentially
- Stitches visual assets to match audio duration (images displayed for full voiceover length, videos trimmed/looped)
- Applies Ken Burns effect (zoom/pan) for still images
- Mixes voice-over with background music
- Exports final video
If Langfuse is configured, the pipeline automatically tracks:
- LLM API calls and token usage
- Generation parameters and responses
- Error tracking and debugging
View traces at your Langfuse dashboard.
# macOS
brew install ffmpeg
# Ubuntu/Debian
sudo apt-get install ffmpeg
# Windows
# Download from https://ffmpeg.org/download.htmlAdjust the semaphore limit in utils/ai.py:
AUDIO_GENERATION_SEMAPHORE = asyncio.Semaphore(2) # Reduce concurrent requests- Check your Pexels API key
- Try more generic keywords in the script
- Verify internet connection
The pipeline uses audio-driven duration - each scene's visual duration is set by the voiceover length, ensuring natural-sounding narration. If sync issues occur:
- Check that audio files are being generated correctly
- Verify scene duration calculations in services/pipeline.py:69-71
- Ensure FFmpeg is properly installed and accessible
- Review audio file integrity with
ffprobe
Core dependencies:
ffmpeg-python- Video editingpydub- Audio processinggoogle-genai- Gemini AI (LLM + TTS)firecrawl-py- Article extractionhttpx- Async HTTP clientrequests- Pexels APIfastapi- Web framework and APIuvicorn- ASGI serversqlalchemy- Database ORMaiosqlite- Async SQLite driverboto3- AWS S3/R2 client (optional, for cloud storage)langfuse- Monitoring (optional)python-dotenv- Environment configuration
- Video Duration: Currently optimized for 30-60 second videos
- Rate Limits: Free tier APIs have request limits (use semaphores)
- Asset Quality: Dependent on Pexels search results
- Gemini TTS Voices: Limited to available prebuilt voices
- FFmpeg Dependencies: Requires system FFmpeg installation
- Web UI for easier usage (FastAPI + WebSocket)
- Subtitle generation support
- Custom font and styling options
- Multiple aspect ratios (square, landscape)
- Direct social media upload integration
- Batch processing multiple articles
- Custom background music library
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
[Add your license here]
- Google Gemini AI for LLM and TTS capabilities
- Pexels for stock media API
- FireCrawl for article extraction
- FFmpeg for video processing