Open Video Watermark - Installation & Usage Guide โ
๐ฏ Project Overview โ
The Open Video Watermark application is a robust, self-contained web application that embeds invisible watermarks into video files using advanced DCT (Discrete Cosine Transform) frequency-domain techniques. The watermarks are designed to be resilient to compression and re-encoding.
โจ Key Features โ
- ๐ Invisible Watermarking: Uses DCT frequency-domain embedding for robust, invisible watermarks
- ๐ Modern Web Interface: Clean, responsive single-page application with real-time updates
- โก Real-time Progress: Live WebSocket updates showing frame-by-frame processing progress
- ๐ Background Processing: Queue-based video processing prevents UI blocking
- ๐ File Management: Complete file lifecycle management (upload, process, download, delete)
- ๐ก๏ธ Error Handling: Comprehensive error handling and user feedback
- ๐ฑ Responsive Design: Works seamlessly on desktop and mobile devices
๐๏ธ Architecture โ
Backend (Python Flask) โ
- Flask: Web framework with SocketIO for real-time communication
- DCT Watermarking: Frequency-domain embedding in video frames
- OpenCV: Video processing and computer vision operations
- Background Workers: Threaded processing queue for video operations
Frontend (Modern JavaScript) โ
- Vanilla JavaScript: No external framework dependencies
- WebSocket Communication: Real-time progress updates
- Modern CSS: Responsive design with CSS Grid and Flexbox
- Progressive Enhancement: Works with and without JavaScript
Watermarking Technology โ
- DCT Transform: Embeds data in frequency domain coefficients
- Block-based Processing: 8x8 pixel block processing for robustness
- Compression Resistant: Survives JPEG/video compression
- Configurable Strength: Balance between invisibility and robustness
๐ง Installation โ
Method 1: Automated Setup (Recommended) โ
# Clone or download the project
cd open-video-watermark
# Run the automated setup and start script
./run.shThe script will:
- Check Python installation
- Create virtual environment
- Install dependencies
- Run tests (optional)
- Start the application
Method 2: Manual Setup โ
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run tests (optional)
python test_watermark.py
# Start application
python app.pySystem Requirements โ
- Python 3.8+
- OpenCV dependencies (automatically installed via pip)
- Modern web browser (Chrome, Firefox, Safari, Edge)
- Minimum 4GB RAM (for video processing)
- Storage space for uploaded and processed videos
๐ Security Configuration โ
Environment Variables โ
Before running the application, especially in production, you must configure environment variables:
- Copy the environment template:
cp .env.example .env- Generate a secure secret key:
python -c "import secrets; print('SECRET_KEY=' + secrets.token_hex(32))" >> .env- Edit the .env file and update these critical settings:
# Security - REQUIRED for production
SECRET_KEY=your-generated-secret-key-here
DEBUG=false
CORS_ORIGINS=https://yourdomain.com # Replace * with actual domains
# File paths (use absolute paths for production)
UPLOAD_FOLDER=/app/uploads
PROCESSED_FOLDER=/app/processed
# Logging
LOG_LEVEL=INFO
LOG_FILE=logs/app.logFile Validation โ
The application now includes multiple layers of file validation:
- Extension checking: Validates file extensions
- Magic number validation: Uses python-magic to verify file types
- OpenCV validation: Ensures files are readable video formats
Install system dependencies for magic number detection:
Ubuntu/Debian:
sudo apt-get install libmagic1macOS:
brew install libmagicCentOS/RHEL:
sudo yum install file-devel๐ Logging โ
The application now includes comprehensive logging:
- Console logging: Real-time feedback during development
- File logging: Persistent logs in
logs/app.log - Structured logging: Includes timestamps, log levels, and context
- Error tracking: Full stack traces for debugging
Log levels available: DEBUG, INFO, WARNING, ERROR, CRITICAL
View logs in real-time:
tail -f logs/app.log๐ Usage โ
Starting the Application โ
Run the startup script:
bash./run.shOpen your browser and navigate to:
http://localhost:5000
Embedding Watermarks โ
- Switch to "Embed Watermark" tab
- Upload videos: Click to select or drag-and-drop video files
- Supported formats: MP4, AVI, MOV, MKV, WMV, FLV, WebM
- Maximum file size: 500MB per file
- Enter watermark text: Up to 50 characters
- Adjust embedding strength:
- Lower (0.05-0.1): More invisible, less robust
- Higher (0.2-0.3): More robust, potentially visible
- Click "Start Processing"
- Monitor progress: Real-time updates show frame-by-frame progress
Managing Files โ
- Switch to "Manage Files" tab
- View processed files: See all watermarked videos
- Download files: Click download button for any processed video
- Delete files: Remove files from server storage
- Refresh list: Update the file list manually
๐งช Testing โ
Run All Tests โ
python test_watermark.pyCreate Demo Video โ
python create_demo.py --duration 5 --output test_video.mp4Test Individual Components โ
# Test just setup
./run.sh --setup
# Test functionality only
./run.sh --testโ๏ธ Configuration โ
Environment Variables (.env) โ
SECRET_KEY=your-secret-key-change-in-production
DEBUG=True
HOST=0.0.0.0
PORT=5000
MAX_CONTENT_LENGTH=524288000 # 500MB
UPLOAD_FOLDER=uploads
PROCESSED_FOLDER=processedApplication Settings (config.py) โ
- Watermarking parameters: Strength, block size
- File upload limits: Size, types, watermark length
- UI settings: Default tab, toast duration
- Processing settings: Progress intervals, sample rates
๐ Project Structure โ
open-video-watermark/
โโโ app.py # Main Flask application
โโโ config.py # Configuration settings
โโโ requirements.txt # Python dependencies
โโโ run.sh # Automated setup script
โโโ test_watermark.py # Test suite
โโโ create_demo.py # Demo video creator
โโโ README.md # Documentation
โโโ .env # Environment variables
โโโ .gitignore # Git ignore rules
โโโ watermark/ # Core watermarking modules
โ โโโ __init__.py
โ โโโ dct_watermark.py # DCT watermarking implementation
โ โโโ video_processor.py # Video processing utilities
โโโ templates/ # HTML templates
โ โโโ index.html # Main application template
โโโ static/ # Frontend assets
โ โโโ css/
โ โ โโโ style.css # Modern CSS styles
โ โโโ js/
โ โโโ app.js # Frontend JavaScript
โโโ uploads/ # Temporary upload storage
โโโ processed/ # Processed video storage
โโโ registry.json # File metadata registry๐ฌ Technical Details โ
Watermarking Algorithm โ
- Frame Extraction: Extract frames from input video
- Block Division: Divide each frame into 8x8 pixel blocks
- DCT Transform: Apply Discrete Cosine Transform to each block
- Coefficient Modification: Modify mid-frequency coefficients based on watermark bits
- Inverse DCT: Transform back to spatial domain
- Frame Reconstruction: Reconstruct watermarked video
Real-time Communication โ
- WebSocket Connection: Persistent connection for progress updates
- Room-based Updates: Each processing task has its own update channel
- Progress Callbacks: Frame-by-frame progress reporting
- Status Management: Queue, processing, completed, error states
File Management โ
- Secure Upload: Filename sanitization and validation
- Registry System: JSON-based metadata storage
- Automatic Cleanup: Temporary file removal after processing
- Download Security: Secure file serving with proper headers
๐ ๏ธ Development โ
Adding New Video Formats โ
- Update
ALLOWED_EXTENSIONSinconfig.py - Test with
VideoProcessor.validate_video_file() - Verify OpenCV codec support
Modifying Watermarking Algorithm โ
- Edit
DCTWatermarkclass inwatermark/dct_watermark.py - Adjust block size, coefficient positions, or embedding strength
- Run tests to verify changes
Customizing UI โ
- Modify styles in
static/css/style.css - Update templates in
templates/index.html - Extend functionality in
static/js/app.js
๐จ Troubleshooting โ
Common Issues โ
Environment Configuration:
# Missing .env file
cp .env.example .env
# Edit .env with your settingspython-magic Installation Problems:
# Ubuntu/Debian
sudo apt-get install libmagic1 python3-magic
pip install python-magic
# macOS
brew install libmagic
pip install python-magic
# If still having issues, try:
pip install python-magic-binOpenCV Installation Problems:
pip install --upgrade pip
pip install opencv-python-headlessPermission Errors:
chmod +x run.sh
sudo chown -R $USER:$USER .
# Create log directory
mkdir -p logs
chmod 755 logsCORS Issues:
- Update
CORS_ORIGINSin .env file - For development:
CORS_ORIGINS=* - For production:
CORS_ORIGINS=https://yourdomain.com
File Upload Failures:
- Check file format is supported (mp4, avi, mov, mkv, wmv, flv, webm)
- Verify file is not corrupted
- Check
MAX_FILE_SIZE_MBsetting - Review logs:
tail -f logs/app.log
Port Already in Use:
- Change
PORTin.envfile - Or kill existing process:
lsof -ti:8000 | xargs kill
Large File Upload Issues:
- Check
MAX_CONTENT_LENGTHsetting - Verify disk space availability
- Monitor browser network timeouts
Debug Mode โ
Enable detailed logging:
# In .env file
DEBUG=True
LOG_LEVEL=DEBUG
# Then restart the application
python app.pyChecking Logs โ
View application logs:
# Real-time log monitoring
tail -f logs/app.log
# View recent errors
grep ERROR logs/app.log | tail -20
# View all logs from today
grep "$(date +%Y-%m-%d)" logs/app.logPerformance Optimization โ
- Reduce video resolution before processing
- Adjust
PROGRESS_UPDATE_INTERVALfor fewer updates - Use SSD storage for better I/O performance
๐ License โ
MIT License - see LICENSE file for details.
๐ค Contributing โ
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
๐ Support โ
For issues and questions:
- Check this documentation
- Run the test suite:
python test_watermark.py - Review application logs
- Create an issue with detailed error information
Happy Watermarking! ๐ฌโจ