๐ Trip Media Sorter by Visual Scene Similarity
๐ About
This tool processes media files (images, RAW files, and videos) by extracting visual and temporal features, clustering them into scenes, and organizing them into separate directories. It uses the CLIP model for visual embeddings and supports both DBSCAN and HDBSCAN clustering.
โจ Features
- ๐ธ Media Support: Handles images (JPEG, PNG, RAW), and common video formats.
- ๐ Hybrid Clustering: Combines visual and temporal features.
- โป๏ธ Resumable Processing: Resume an interrupted run with a progress file.
- ๐ Video Optimization: Early termination for efficient keyframe extraction.
- ๐ก Safety Checks: File size limits, duplicate detection, and disk space verification.
- ๐งช Dry Run Option: Simulate file organization before actual execution.
๐ง Installation
๐ Requirements
๐ฝ Install Dependencies
pip install torch torchvision pip install ftfy regex tqdm pip install git+https://github.com/openai/CLIP.git pip install opencv-python pillow rawpy scikit-learn hdbscan pyyaml
๐ Setup & Usage
๐ฅ Clone the Repository
git clone https://github.com/yourusername/media_scene_sorter.git
cd media_scene_sorter๐ (Optional) Virtual Environment
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate
โ๏ธ (Optional) Custom Configuration
Create a config.yaml file to override default settings:
clustering: algorithm: hdbscan eps: 0.15 min_samples: 3 visual_weight: 0.7 temporal_weight: 0.3 processing: batch_size: 32 max_workers: 4 video_interval: 30 max_file_size_mb: 500 safety: dry_run: false min_disk_space_gb: 5 checksum_verify: true video_certainty_threshold: 0.05
โถ๏ธ Run the Script
python media_scene_sorter.py --input /path/to/input_directory --output /path/to/output_directory
๐ Command-Line Options
| Option | Description |
|---|---|
--input |
(Required) Input directory path containing media files. |
--output |
(Required) Output directory for organized scenes. |
--config |
Path to custom YAML configuration (default: config.yaml). |
--dry-run |
Simulate file organization without making changes. |
--process-large-files |
Process files exceeding size limit. |
--eps |
Override eps for DBSCAN clustering. |
--resume |
Resume from saved progress (progress.pkl). |
--video-certainty-threshold |
Set early termination threshold for video processing. |
--images-first |
Process images before videos. |
๐ Example Usage
python media_scene_sorter.py \ --input /media/input \ --output /media/output \ --process-large-files \ --video-certainty-threshold 0.05
๐ Logging & Debugging
- ๐ General logs: Stored in
media_sorter.log& printed to console. - โ ๏ธ Error logs: Critical errors are logged in
error.log.
๐ Resuming Interrupted Runs
If the process is interrupted, restart it with the --resume flag:
python media_scene_sorter.py --input /media/input --output /media/output --resume
๐ License
This project is licensed under the MIT License. See the LICENSE file for details.
๐ Happy Sorting! ๐ฅ๐ธ