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. - Custom Start Time: Begin extraction from any point in the video using a timestamp in seconds.
- Open Eyes Filter: Optionally keep only frames where at least one face with both eyes open is detected, using local Haar cascade classifiers.
🛠️ 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 (Local)
Clone the repo and run directly without installing the package:
-
Clone the repository:
git clone git@github.com:yubraaj11/distant-frames.git cd distant-frames
-
Install dependencies:
uv sync --frozen
-
Run via
main.py:uv run main.py path/to/video.mp4 -o output_dir -t 0.75
💻 Usage
Installed package
distant-frames path/to/video.mp4 -o path/to/output -t 0.75
Cloned repo (no install)
uv run main.py path/to/video.mp4 -o path/to/output -t 0.75
Options
| Argument | Description | Default |
|---|---|---|
video_path |
Path to the input video file (Required). | N/A |
--output, -o |
Directory to save the extracted frames. | extracted_frames |
--threshold, -t |
Similarity score threshold (0.0 to 1.0). Frames with a score higher than this value are discarded. | 0.65 |
--start, -s |
Timestamp in seconds to begin extraction from. | 0.0 |
--open-eyes |
When set, only saves frames where at least one face with both eyes open is detected. | Off |
Examples
Extract frames with default settings:
distant-frames my_vacation.mp4
Save to a custom folder with a stricter similarity check:
distant-frames my_vacation.mp4 -o best_shots -t 0.95
Start extraction from a specific timestamp (e.g. 1 minute 30 seconds in):
distant-frames interview.mp4 -s 90
Only keep frames where a person's eyes are open:
distant-frames interview.mp4 --open-eyes -o key_frames
Combine all options:
distant-frames interview.mp4 -s 90 -t 0.80 --open-eyes -o key_frames
🔍 How It Works
- Sampling: The script checks one frame every second (based on the video's FPS), starting from
--startif provided. - 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: candidate for saving. - If similarity >=
threshold: SKIP (The scene is too similar).
- If similarity <
- Open Eyes Filter (optional): If
--open-eyesis set, a candidate frame is only saved if a face with two open eyes is detected using Haar cascade classifiers.
🧪 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.3.2.tar.gz.
File metadata
- Download URL: distant_frames-0.3.2.tar.gz
- Upload date:
- Size: 217.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c371f7f3b02089e03f08f9f3dc2ad43d4f4dec082adcdc9b466ecfe2481bfb7e
|
|
| MD5 |
75f97b5bbd9cd18776aae887c0b1f155
|
|
| BLAKE2b-256 |
e5726cca60ee1c12721aa212f3c972a5ff859b7971a5322874dc73c98b8e733e
|
File details
Details for the file distant_frames-0.3.2-py3-none-any.whl.
File metadata
- Download URL: distant_frames-0.3.2-py3-none-any.whl
- Upload date:
- Size: 208.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7719ebde396c0c43b00b517a52f9fd966d97e8fe54541531b8d3814e47903762
|
|
| MD5 |
16ce452ed7c125aefb59f9dce5d9bae2
|
|
| BLAKE2b-256 |
decbe6208fc0269ffae5beeac09068d10095673b5c25fe1dbb3bce9e2c5bdc24
|