AI-powered video analysis tool using Gemini 3 Flash to identify events, generate timestamps, and help organize your home videos.
- Automatic Event Detection: Identifies distinct events, activities, and scenes in your videos
- Timestamp Generation: Provides accurate start/end timestamps for all events
- Smart Video Splitting: Automatically splits long videos (>30 min) into chunks for analysis
- Intelligent Stitching: Uses AI to merge multi-chunk analyses into a coherent timeline
- Rich Metadata: Extracts people, locations, tags, and highlights from video content
- Multiple Export Formats: JSON, Markdown, and CSV exports
- Easy CLI Interface: Simple command-line interface for all operations
- Python 3.10+
- ffmpeg (for video processing)
- OpenRouter API key (for Gemini 3 Flash access)
macOS:
brew install ffmpegUbuntu/Debian:
sudo apt-get update
sudo apt-get install ffmpegWindows: Download from ffmpeg.org or use:
choco install ffmpegcd video-analyzer
# Install Python dependencies
pip install -r requirements.txt
# Or use a virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtThe .env file is already created with your API key. If you need to update it:
# Edit .env file
nano .env
# Add your OpenRouter API key
OPENROUTER_API_KEY=your-api-key-here# Basic analysis
python -m src.main analyze videos/birthday.mp4
# Custom output name
python -m src.main analyze videos/vacation.mp4 --output vacation_summer_2023
# Skip automatic splitting (for videos < 30 min or to force single analysis)
python -m src.main analyze videos/short_clip.mp4 --no-split
# Use simple stitching instead of LLM stitching (faster, less intelligent)
python -m src.main analyze videos/long_video.mp4 --no-stitch
# Keep video chunks with AI-generated descriptive names (instead of deleting them)
python -m src.main analyze videos/long_video.mp4 --keep-chunkspython -m src.main listpython -m src.main summary birthday_20231225_143022.json# View all events
python -m src.main events birthday_20231225_143022.json
# Filter by event type
python -m src.main events vacation.json --type outdoor_activity
# Filter by tags
python -m src.main events party.json --tags celebration,family# Export to Markdown
python -m src.main export birthday.json --format markdown
# Export to CSV (event timestamps)
python -m src.main export birthday.json --format csv --output events.csv
# Copy JSON to custom location
python -m src.main export birthday.json --format json --output backup.jsonWhen using the --keep-chunks flag, the analyzer will automatically rename video chunks with descriptive names based on their content:
- Before:
2106880-01-USB_compressed_chunk_001.mp4 - After:
000000-001000_mountain-hiking-trail.mp4
This makes it easy to:
- Browse chunks by content without re-watching
- Share specific segments with others
- Quickly locate interesting moments in long videos
- Organize your video library
The AI analyzes the events, people, locations, and activities in each chunk to generate concise, descriptive filenames.
- Video Validation: Checks if the video file is valid and supported
- Duration Check: Determines if video needs to be split (>10 minutes)
- Splitting (if needed): Uses ffmpeg to split video into 10-minute chunks
- Analysis: Each chunk is:
- Encoded to base64
- Sent to Gemini 3 Flash via OpenRouter
- Analyzed for events, timestamps, people, locations, and tags
- Naming (if --keep-chunks): AI generates descriptive filenames for chunks
- Stitching (if multiple chunks): AI merges analyses and adjusts timestamps
- Output: Saves comprehensive JSON analysis with metadata
- Cleanup: Removes temporary chunks (unless --keep-chunks is used)
Each analysis includes:
- Events: Detailed timeline of activities with timestamps
- Scene Changes: Points where the video significantly changes
- Overall Summary: High-level description of video content
- Metadata: Video info, analysis date, model used
{
"metadata": {
"original_video": "birthday.mp4",
"duration": "01:15:30",
"analyzed_at": "2025-12-22T10:30:00",
"model": "google/gemini-3-flash-preview",
"chunks_processed": 3
},
"events": [
{
"start_time": "00:00:00",
"end_time": "00:05:30",
"event_type": "party_setup",
"description": "Adults setting up decorations and tables in backyard",
"people": ["adult male", "adult female"],
"location": "backyard",
"tags": ["preparation", "outdoor", "decorations"],
"highlights": ["Birthday banner hung at 00:02:15"]
},
{
"start_time": "00:15:00",
"end_time": "00:25:30",
"event_type": "birthday_celebration",
"description": "Children gathered around cake, singing and celebration",
"people": ["birthday child", "group of children", "parents"],
"location": "backyard table",
"tags": ["celebration", "cake", "singing", "family"],
"highlights": ["Cake cutting at 00:18:30", "Gift opening at 00:22:00"]
}
],
"scene_changes": ["00:05:30", "00:15:00", "00:30:00"],
"overall_summary": "Birthday party celebration with setup, cake, gifts, and outdoor games"
}video-analyzer/
├── videos/ # Place your videos here
├── outputs/
│ ├── analyses/ # JSON analysis files saved here
│ └── chunks/ # Temporary video chunks (auto-deleted)
├── src/ # Source code
│ ├── main.py # CLI interface
│ ├── config.py # Configuration
│ ├── video_processor.py # Video splitting & encoding
│ ├── analyzer.py # API integration & analysis
│ ├── stitcher.py # Multi-chunk merging
│ └── utils.py # Helper functions
├── .env # API key (DO NOT COMMIT)
├── .gitignore # Git ignore rules
├── requirements.txt # Python dependencies
└── README.md # This file
Edit src/config.py to customize:
CHUNK_DURATION: Video chunk size in seconds (default: 1800 = 30 min)THINKING_LEVEL: Gemini reasoning level (minimal, low, medium, high)MEDIA_RESOLUTION: Video processing resolution (low, medium, high)MAX_RETRIES: API request retry attemptsMODEL_ID: OpenRouter model to use
- MP4 (.mp4)
- MOV (.mov)
- AVI (.avi)
- WebM (.webm)
- MPEG (.mpeg, .mpg)
- M4V (.m4v)
- 3GPP (.3gpp)
Install ffmpeg using the instructions in the Installation section above.
Check that your OPENROUTER_API_KEY in .env is correct and active.
The API is rate-limited. The tool will automatically retry with exponential backoff. For persistent issues:
- Wait a few minutes between analyses
- Use smaller videos or split manually
- Check your OpenRouter plan limits
- Check that the video file is not corrupted
- Ensure file size is reasonable (<500MB per chunk)
- Try converting to MP4 format first
- Video analysis can take 2-5 minutes per 30-minute chunk
- Longer videos require more time
- Network speed affects upload time for base64-encoded video
- Use
--no-splitfor smaller videos to avoid chunk overhead - Close other applications
- Split very large videos manually into smaller files first
Using Gemini 3 Flash via OpenRouter:
- Input: $0.50 per 1M tokens
- Output: $3.00 per 1M tokens
- Audio: $1.00 per 1M tokens
Approximate costs:
- 30-minute video (with audio): ~$0.05-0.15
- 1-hour video (2 chunks): ~$0.10-0.30
- Token usage varies based on video content and complexity
- Video Quality: Higher quality videos (1080p) provide better analysis
- Lighting: Well-lit videos are analyzed more accurately
- Audio: Videos with clear audio provide richer context
- Stability: Steady camera work helps with scene detection
- Length: Break very long videos (>2 hours) into logical segments
- File Names: Use descriptive names for easier organization
- Local Processing: All video encoding happens locally
- API Transmission: Videos are sent to OpenRouter/Gemini via secure HTTPS
- No Storage: OpenRouter doesn't store your video data (zero retention policy)
- API Key: Keep your
.envfile secure and never commit it to git
Modify ANALYSIS_PROMPT in src/analyzer.py to customize what the AI looks for in your videos.
# Process multiple videos
for video in videos/*.mp4; do
python -m src.main analyze "$video"
doneExport events to CSV and import timestamps into:
- DaVinci Resolve
- Adobe Premiere Pro
- Final Cut Pro
This is a personal project, but suggestions and improvements are welcome! Feel free to:
- Open issues for bugs or feature requests
- Submit pull requests for enhancements
- Share your use cases and results
MIT License - feel free to use and modify as needed.
- Powered by Google Gemini 3 Flash
- API access via OpenRouter
- Video processing with ffmpeg
For issues or questions:
- Check this README's Troubleshooting section
- Review the code comments in
src/directory - Check OpenRouter and Gemini documentation for API issues
Happy video organizing! 🎥✨