Skip to main content

PyPI - Version PyPI - Status PyPI - Python Version PyPI - Downloads GitHub License

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

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:

  1. Clone the repository:

    git clone git@github.com:yubraaj11/distant-frames.git
    cd distant-frames
    
  2. Install dependencies:

    uv sync --frozen
    
  3. Run via main.py:

    uv run main.py path/to/video.mp4 -o output_dir -t 0.78
    

💻 Usage

Installed package

distant-frames path/to/video.mp4 -o path/to/output -t 0.78

Cloned repo (no install)

uv run main.py path/to/video.mp4 -o path/to/output -t 0.78

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, so raising it keeps more frames. 0.78
--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
--refine When set, frames the histogram would skip are re-checked with a HOG or ORB descriptor if any region of the picture changed sharply. Catches title and text changes on slides, which the histogram scores as identical. Waits for animation to settle before saving, so refined frames may lag the change by a second or two. Only ever adds frames. 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

  1. Sampling: The script checks one frame every second (based on the video's FPS), starting from --start if provided.
  2. Comparison: It compares the current candidate frame against the last successfully saved frame.
  3. Algorithm: It converts frames to HSV color space and calculates Normalized Histogram Correlation.
  4. Decision:
    • If similarity < threshold: candidate for saving.
    • If similarity >= threshold: SKIP (The scene is too similar).
  5. Refinement (optional): If --refine is set, a frame the histogram wants to skip gets a second look when the worst 1/64 tile of the picture changed sharply. A dense HOG descriptor (flat, graphic content) or ORB keypoints (textured footage) then decides, and can turn the skip into a save. This catches a title changing on an otherwise static slide, which alters too little of the picture to move a whole-frame histogram. A frame judged distinct is then held until the picture stops moving, so an animated slide emits its settled state once rather than one frame per step of the transition — which means a refined save can land a second or two after the change that caused it.
  6. Open Eyes Filter (optional): If --open-eyes is 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.

Metadata

Release files for distant-frames 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for distant-frames 0.4.0
File Size Uploaded Provenance Actions
distant_frames-0.4.0.tar.gz 228.7 kB Without provenance Details for distant_frames-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for distant-frames 0.4.0
File Interpreter ABI Platform Actions
distant_frames-0.4.0-py3-none-any.whl Python 3 none any Details for distant_frames-0.4.0-py3-none-any.whl

Total release size: 441.4 kB

Release files / distant_frames-0.4.0.tar.gz

Download URL distant_frames-0.4.0.tar.gz
Size 228.7 kB
Tags Source
SHA-256 checksum
How to use checksums
25fd1db3384754a7f9609a9a42718d1be0be146a846ab1c757d0f03778fd355f
BLAKE2b-256 checksum
How to use checksums
d40d6b8fd103e02b84fb03ec685a0bf6d3ee46b10d69558324adca0914bd6c27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / distant_frames-0.4.0-py3-none-any.whl

Download URL distant_frames-0.4.0-py3-none-any.whl
Size 212.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46ca169bcf66addb83786f765eaae846325b78dd93ba472d4ae99ebd8cd25161
BLAKE2b-256 checksum
How to use checksums
ed58c9e89363ee9bebcf7149779c112eee768f5ce9876b42baedab630c9e1235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for distant-frames 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page