AdamDev12TEST/ai-video-editor
AI Video Editor
A web-based AI-assisted video editing platform similar to CapCut. Users can upload main video/audio and B-roll clips, and the system automatically generates a synced video using AI-powered semantic matching.
Features
- B-roll Management: Organize clips into sets with product/non-product categorization
- AI-Powered Matching: Automatically matches B-roll clips to main content using semantic analysis
- Speech-to-Text: Transcribes main video/audio using OpenAI Whisper
- Timeline Editor: CapCut-style multi-track timeline for manual adjustments
- Silence Removal: Optionally removes silent gaps from videos
- Video Export: Export final edited videos as MP4
Storage
File Storage (Local - Default)
Video files are stored locally in the backend/uploads/ directory:
uploads/broll/- B-roll video clips and thumbnailsuploads/main/- Main video/audio filesuploads/exports/- Exported final videos
This works perfectly fine for local development and small-scale use. No additional storage setup is needed.
Storage Requirements
- Ensure you have enough disk space for your video files
- A 1-minute video at 1080p is typically 50-150MB
- Thumbnails are ~50KB each
Production/Cloud Storage (Optional)
For production deployment with many users, you might want to use cloud storage (AWS S3, Google Cloud Storage, etc.). This would require modifying the file upload/serving code - let me know if you need that.
Tech Stack
Backend
- FastAPI (Python 3.11+) - High-performance async API framework
- MongoDB - Document database for storing projects and metadata
- Motor - Async MongoDB driver
- OpenAI API - Whisper for transcription, GPT-4o-mini for analysis, Embeddings for matching
- FFmpeg - Video/audio processing
Frontend
- React 18 - UI library
- Vite - Build tool and dev server
- TailwindCSS - Utility-first CSS framework
- Zustand - State management
- React Router v7 - Client-side routing
- Axios - HTTP client
- Lucide React - Icon library
Prerequisites
Before setting up the project, ensure you have the following installed:
- Node.js 18+ - Download
- Python 3.11+ - Download
- MongoDB 6+ - Download
- FFmpeg - Required for video processing
Installing FFmpeg
macOS (Homebrew):
brew install ffmpegUbuntu/Debian:
sudo apt update
sudo apt install ffmpegWindows:
- Download from https://ffmpeg.org/download.html
- Extract and add to PATH
Verify installation:
ffmpeg -versionProject Structure
ai-video-editor/
├── backend/
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI application entry
│ │ ├── config.py # Configuration settings
│ │ ├── database.py # MongoDB connection
│ │ ├── models/
│ │ │ ├── __init__.py
│ │ │ └── schemas.py # Pydantic models
│ │ ├── routes/
│ │ │ ├── __init__.py
│ │ │ ├── projects.py # Project CRUD endpoints
│ │ │ ├── broll.py # B-roll management
│ │ │ ├── main_content.py # Main video/audio upload
│ │ │ ├── generation.py # AI generation & timeline
│ │ │ └── files.py # File serving
│ │ ├── services/
│ │ │ ├── __init__.py
│ │ │ └── ai_service.py # OpenAI integration
│ │ └── utils/
│ │ ├── __init__.py
│ │ └── video.py # FFmpeg utilities
│ ├── uploads/ # Uploaded media storage
│ │ ├── broll/
│ │ ├── main/
│ │ └── exports/
│ ├── requirements.txt
│ └── .env.example
│
└── frontend/
├── public/
├── src/
│ ├── components/ # Reusable UI components
│ ├── pages/ # Page components
│ │ ├── Home.jsx
│ │ ├── ProjectPage.jsx
│ │ └── EditorPage.jsx
│ ├── hooks/ # Custom React hooks
│ ├── services/
│ │ └── api.js # API client
│ ├── store/
│ │ └── index.js # Zustand store
│ ├── utils/
│ │ └── helpers.js # Utility functions
│ ├── App.jsx
│ ├── main.jsx
│ └── index.css
├── index.html
├── package.json
├── vite.config.js
├── tailwind.config.js
└── postcss.config.jsSetup Instructions
Step 1: Clone/Download the Project
# If you have the zip file, extract it
# Or create the directory structure manually
cd ai-video-editorStep 2: Setup MongoDB Atlas (Recommended)
MongoDB Atlas is free and easier than local MongoDB. Here's how to set it up:
- Create Account: Go to https://mongodb.com/atlas and sign up (free)
- Create Cluster:
- Click "Build a Database"
- Choose "M0 FREE" tier
- Select your region (closest to you)
- Click "Create Deployment"
- Create Database User:
- Username:
admin(or your choice) - Password: Generate a secure password (save this!)
- Click "Create User"
- Configure Network Access:
- Click "Add IP Address"
- Click "Allow Access from Anywhere" (for development)
- Or add your specific IP for production
- Get Connection String:
- Click "Connect" → "Connect your application"
- Copy the connection string
- It looks like:
mongodb+srv://admin:<password>@cluster0.xxxxx.mongodb.net/?retryWrites=true&w=majority - Replace
<password>with your actual password
Alternative: Local MongoDB If you prefer local MongoDB:
# macOS with Homebrew:
brew services start mongodb-community
# Ubuntu:
sudo systemctl start mongod
# Windows:
net start MongoDBUse mongodb://localhost:27017 as your connection string.
Step 3: Get OpenAI API Key
- Go to https://platform.openai.com/api-keys
- Create a new API key
- Copy it for the backend .env file
Step 4: Setup Backend
# Navigate to backend directory
cd backend
# Create Python virtual environment
python3 -m venv venv
# Activate virtual environment
# macOS/Linux:
source venv/bin/activate
# Windows:
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create .env file from example
cp .env.example .env
# Edit .env with your settings
nano .env # or use any text editorEdit the `.env` file:
# MongoDB Connection
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=ai_video_editor
# OpenAI API Key (REQUIRED)
OPENAI_API_KEY=sk-your-openai-api-key-here
# File Storage
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=500000000
# Server Config
HOST=0.0.0.0
PORT=8000
DEBUG=true
# CORS Origins
CORS_ORIGINS=http://localhost:5173,http://localhost:3000Start the backend server:
# Make sure virtual environment is activated
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
Verify backend is running:
- Open http://localhost:8000 in your browser
- You should see:
{"message":"AI Video Editor API","version":"1.0.0"} - API docs available at: http://localhost:8000/docs
Step 5: Setup Frontend
# Open a new terminal
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start development server
npm run devThe frontend will be available at http://localhost:5173
Step 6: Test the Application
- Open http://localhost:5173 in your browser
- Click "New Project" to create a project
- Create a B-roll set and upload some video clips
- Upload a main video or audio file
- Wait for transcription to complete
- Click "Generate Video" to create the AI-matched timeline
- Use the editor to make adjustments
- Export your final video
API Endpoints
Projects
GET /api/projects- List all projectsPOST /api/projects- Create new projectGET /api/projects/{id}- Get project detailsPATCH /api/projects/{id}- Update projectDELETE /api/projects/{id}- Delete project
B-roll Sets
GET /api/broll/sets/project/{project_id}- List sets for projectPOST /api/broll/sets- Create new setDELETE /api/broll/sets/{set_id}- Delete set
B-roll Clips
POST /api/broll/clips/upload- Upload single clipPOST /api/broll/clips/upload-batch- Upload multiple clipsGET /api/broll/clips/set/{set_id}- List clips in setDELETE /api/broll/clips/{clip_id}- Delete clip
Main Content
POST /api/main/upload- Upload main video/audioGET /api/main/project/{project_id}- Get main contentDELETE /api/main/{content_id}- Delete main contentPOST /api/main/{content_id}/remove-silence- Remove silent gaps
Generation & Timeline
POST /api/generate/timeline/{project_id}- Generate AI timelineGET /api/generate/timeline/{project_id}- Get timelinePOST /api/generate/export/{project_id}- Export video
Troubleshooting
Common Issues
1. MongoDB Connection Error
Error: Cannot connect to MongoDB- Ensure MongoDB is running:
mongodorbrew services list - Check your MONGODB_URL in .env
2. FFmpeg Not Found
Error: ffprobe not found- Install FFmpeg and ensure it's in your PATH
- Verify with
ffmpeg -version
3. OpenAI API Error
Error: Invalid API key- Check your OPENAIAPIKEY in .env
- Ensure your OpenAI account has credits
4. CORS Error
Error: CORS policy blocked- Ensure frontend URL is in CORS_ORIGINS in .env
- Restart the backend server
5. Video Processing Slow
- Video processing depends on file size
- Large files may take several minutes
- Check backend logs for progress
Checking Logs
Backend logs:
# Logs appear in the terminal running uvicorn
# Look for errors starting with "Error:"Frontend logs:
# Open browser developer tools (F12)
# Check Console tab for errorsProduction Deployment
Backend (Example with Gunicorn)
# Install gunicorn
pip install gunicorn
# Run with multiple workers
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000Frontend (Build for Production)
# Build the frontend
npm run build
# Output will be in dist/ folder
# Serve with any static file server (nginx, etc.)Environment Variables for Production
DEBUG=false
CORS_ORIGINS=https://yourdomain.comCost Considerations
This app uses OpenAI APIs which have associated costs:
- Whisper (transcription): ~$0.006/minute of audio
- GPT-4o-mini (analysis): ~$0.15 per 1M input tokens
- Embeddings (matching): ~$0.02 per 1M tokens
For a typical 1-minute video with 10 B-roll clips:
- Transcription: ~$0.006
- Analysis: ~$0.01
- Embeddings: ~$0.001
- Total: ~$0.02 per video
License
MIT License - See LICENSE file for details.
Support
For issues and questions:
- Check the Troubleshooting section above
- Review backend logs for error details
- Check browser console for frontend errors
