Smart video frame extraction tool
Project description
Distant Frames
Distant Frames is a smart video frame extraction tool designed to capture distinct visual moments from video files. Instead of simply saving every Nth frame, it analyzes the visual similarity between consecutive potential frames and only saves those that are sufficiently different.
🚀 Features
- Smart Deduplication: Avoids saving redundant frames where the scene hasn't changed.
- Histogram Correlation: Uses HSV color space histogram comparison for robust similarity detection.
- Configurable Threshold: Fine-tune the sensitivity of frame dropping to suit your specific video content.
- Efficient Processing: Seeks directly to target timestamps (
CAP_PROP_POS_FRAMES) for faster processing than frame-by-frame reading.
🛠️ Prerequisites
- Python: 3.12 or higher
- Dependencies:
opencv-python
📦 Installation
From PyPI (Recommended)
Install the latest stable release using pip:
pip install distant-frames
or
uv add distant-frames
From Source (Development)
For development or to use the latest unreleased features:
-
Clone the repository:
git clone git@github.com:yubraaj11/distant-frames.git cd distant-frames
-
Install Dependencies:
uv sync --frozen
💻 Usage
Basic Command
Run the script by providing the path to your video file:
uv run distant_frames/cli.py path/to/your/video.mp4
Options
| Argument | Description | Default |
|---|---|---|
video_path |
Path to the input video file (Required). | N/A |
--output |
Directory to save the extracted frames. | extracted_frames |
--threshold |
Similarity threshold (0.0 to 1.0). Frames with similarity higher than this value compared to the last saved frame will be dropped. | 0.65 |
Examples
Extract frames with default settings:
uv run distant_frames/cli.py my_vacation.mp4
Save to a custom folder with a stricter similarity check (fewer frames):
uv run distant_frames/cli.py my_vacation.mp4 --output best_shots --threshold 0.95
Save more frames (looser similarity check):
uv run distant_frames/cli.py my_vacation.mp4 --output all_shots --threshold 0.6
🔍 How It Works
- Sampling: The script checks one frame every second (based on the video's FPS).
- Comparison: It compares the current candidate frame against the last successfully saved frame.
- Algorithm: It converts frames to HSV color space and calculates Normalized Histogram Correlation.
- Decision:
- If similarity <
threshold: SAVE (The scene has changed). - If similarity >=
threshold: SKIP (The scene is too similar).
- If similarity <
🧪 Testing
You can generate a test video to verify the functionality:
uv run generate_test_video.py
uv run main.py test_video.mp4
This will create a test_video.mp4 with known scene changes and then extract frames from it, demonstrating the deduplication logic.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file distant_frames-0.1.2.tar.gz.
File metadata
- Download URL: distant_frames-0.1.2.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e9e4da27139b7a97a0cc91e537aceda5f15fcfa446fcc88470e9ce183330bca
|
|
| MD5 |
9594a535cad45885ecd903bf2c20718b
|
|
| BLAKE2b-256 |
03f54b645346af65ff27a9a8a189d8d617c3a86abcf780c7a1950c5d9091c8f1
|
File details
Details for the file distant_frames-0.1.2-py3-none-any.whl.
File metadata
- Download URL: distant_frames-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
969ce0ffa91c9a0ca1a1b1f74a952eeb2d0e7609fa7b42996ac142dad6b3d576
|
|
| MD5 |
36bd55473a68f7eee2947316d365764d
|
|
| BLAKE2b-256 |
da3ada52b28e1866db9c2400ec2a63207c984766439edf4190587f297d10e7fe
|