src/config.py.
Configuration File Location
The configuration file is located at:Synchronization Method
Determines the algorithm used for detecting temporal offsets between videos.Options:
"visual": Motion-based synchronization (default)"audio": GCC-PHAT audio cross-correlation
Visual Synchronization (Motion-Based)
How Visual Sync Works
How Visual Sync Works
Algorithm:
- Extract motion energy timeseries from video frames
- Apply cross-correlation to find temporal offsets
- Identify peak correlation as the optimal alignment
- Robust against silent videos
- Works in noisy audio environments
- No audio extraction overhead
- Requires visible motion in overlapping time periods
- Less precise than audio (typically ±1-2 frames)
- Action/sports videos with lots of movement
- Outdoor recordings with wind noise
- Cameras with no/poor audio recording
Audio Synchronization (GCC-PHAT)
How Audio Sync Works
How Audio Sync Works
Algorithm:
- Extract audio tracks from all videos using FFmpeg
- Apply GCC-PHAT (Generalized Cross-Correlation with Phase Transform)
- Find sub-frame precision offsets based on audio alignment
- Sub-frame accuracy (typically ±0.1 frames)
- Works with static camera setups
- High confidence scores for clean audio
- Requires audible, synchronized sound events (claps, music, etc.)
- Fails with silent videos
- Sensitive to background noise
- Studio recordings with synchronized audio
- Concert/performance videos
- Interview setups with shared microphones
Configuration Example
config.py
Directory Configuration
All file paths are configurable through directory constants:Temporary Base Directory
Root directory for all temporary file storage during processing.Default behavior: Uses system temp directory via
tempfile.gettempdir()Location: config.py:11Platform-specific defaults:- Linux/macOS:
/tmp/video_synchronization - Windows:
C:\Users\<username>\AppData\Local\Temp\video_synchronization
Project Root
Absolute path to the project directory (where Location: config.py:14
main.py is located).Auto-detection logic:You typically do not need to modify
PROJECT_ROOT. It’s automatically calculated relative to src/config.py.Working Directories
These directories are created automatically on startup:Storage for uploaded original video files.Location: config.py:17Usage: Upload endpoint saves files here (ui.py:769)
Output directory for synchronized videos.Location: config.py:18Filename pattern:
{original_name}_synced.{ext}Usage: apply_video_offsets() writes synchronized videos here (ui.py:724)Temporary storage for extracted audio tracks (only used when
SYNC_METHOD = "audio").Location: config.py:19File format: .wav files with same basename as videosUsage: Audio extraction via FFmpeg (ui.py:664)Debug output directory for motion analysis artifacts (e.g., energy timeseries plots).Location: config.py:20Usage:
sync_videos_by_motion() saves debug visualizations here (ui.py:701)Persistent directory for sync indicator images (survives application restarts).Location: config.py:23Contents: Bounding box overlay images showing sync qualityUsage:
generate_sync_indicators() saves images here (ui.py:713-717)Directory Creation
All directories are created withexist_ok=True to prevent errors if they already exist:
config.py
Advanced Configuration
These settings are not exposed inconfig.py but can be modified by editing the source code:
Maximum Offset Window
Maximum temporal offset to search (in seconds).Location: ui.py:669 (audio), ui.py:696 (visual)Impact:
- Larger values: Slower processing, more memory usage, but can detect larger time shifts
- Smaller values: Faster processing, but may miss offsets if videos are far apart
Minimum Confidence Threshold
Minimum confidence score required for audio sync.Location: ui.py:671Impact:
- Higher values (0.5-1.0): Only accept high-quality matches, reject uncertain alignments
- Lower values (0.1-0.3): Accept lower-quality matches, may produce incorrect sync
Log Retention
Maximum log file size before rotation (bytes).Default: 10MBLocation: ui.py:40
Number of rotated log files to retain.Default: 5 backups (total ~60MB with defaults)Location: ui.py:40
Maximum log entries stored in memory for UI display.Location: ui.py:75Impact: Higher values increase memory usage but provide more history in the log viewer
Allowed File Extensions
Permitted video file extensions for upload.Location: ui.py:757Modification example:
ui.py
Flask Server Settings
HTTP port for the Flask web server.Location: ui.py:848Modification example:
ui.py
Network interface to bind.Default:
127.0.0.1 (localhost only)Location: ui.py:856To allow external access:ui.py
Environment-Specific Configuration
Development vs. Production
For different deployment scenarios, consider creating environment-specific config files:main.py:
main.py
This pattern is not implemented in the current codebase but is a recommended practice for production deployments.
Configuration Best Practices
Test Changes Locally
After modifying
config.py, restart the application and test with sample videos before deploying.Configuration Reference Table
| Parameter | Type | Default | Modifiable | Requires Restart |
|---|---|---|---|---|
SYNC_METHOD | string | "visual" | ✅ config.py | ✅ |
TEMP_BASE | string | tempfile.gettempdir() | ✅ config.py | ✅ |
VIDEO_DIR | string | {TEMP_BASE}/raw | ✅ config.py | ✅ |
OUTPUT_DIR | string | {TEMP_BASE}/synced | ✅ config.py | ✅ |
AUDIO_DIR | string | {TEMP_BASE}/audio | ✅ config.py | ✅ |
RESULTS_DIR | string | {PROJECT_ROOT}/results | ✅ config.py | ✅ |
max_offset_sec | float | 20.0 | ⚠️ ui.py | ✅ |
min_confidence | float | 0.2 | ⚠️ ui.py | ✅ |
ALLOWED_EXTENSIONS | set | {'.mp4', '.mov', '.avi'} | ⚠️ ui.py | ✅ |
port | int | 5050 | ⚠️ ui.py | ✅ |
maxBytes (logs) | int | 10485760 | ⚠️ ui.py | ✅ |
backupCount (logs) | int | 5 | ⚠️ ui.py | ✅ |
✅ = Easily modifiable in config.py
⚠️ = Requires editing source code
⚠️ = Requires editing source code
Troubleshooting Configuration Issues
Changes to config.py not taking effect
Changes to config.py not taking effect
Cause: Flask cached the old config or application wasn’t restarted.Solution:
- Fully stop the application (
Ctrl+C) - Clear Python cache:
find . -type d -name __pycache__ -exec rm -r {} + - Restart:
python main.py
Permission denied when creating directories
Permission denied when creating directories
Cause:
TEMP_BASE points to a directory without write permissions.Solution: Change to a user-writable directory:Audio sync fails with SYNC_METHOD = 'audio'
Audio sync fails with SYNC_METHOD = 'audio'
Cause: FFmpeg not installed or videos have no audio tracks.Diagnosis: Check logs for “Audio extraction failed” messages.Solution:
- Verify FFmpeg installation:
ffmpeg -version - Check video audio tracks:
ffprobe -show_streams input.mp4 - Switch to visual sync if videos are silent
Next Steps
Using the UI
Learn how to navigate the web interface and upload videos
Interpreting Results
Understand confidence scores and validate synchronization quality