Skip to main content

Smart video frame extraction tool

Project description

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.

🛠️ 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:

  1. Clone the repository:

    git clone git@github.com:yubraaj11/distant-frames.git
    cd distant-frames
    
  2. 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

  1. Sampling: The script checks one frame every second (based on the video's FPS).
  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: SAVE (The scene has changed).
    • If similarity >= threshold: SKIP (The scene is too similar).

🧪 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

distant_frames-0.2.1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

distant_frames-0.2.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file distant_frames-0.2.1.tar.gz.

File metadata

  • Download URL: distant_frames-0.2.1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for distant_frames-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3d5ad0a2aa365e42bf365784502df56f96522854542515301a5caa2762ba8347
MD5 74cb00b030846dffab1ee8670f49d068
BLAKE2b-256 33677a953607a1b1e741a6ce4bf1a0de5695d86d5e74d17f1f4d09e6d8b93707

See more details on using hashes here.

File details

Details for the file distant_frames-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: distant_frames-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for distant_frames-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9911f9ef28af26ea47fb03e4d676c9ce519eb3cf75b1b0d65e08dd311f8fa2f7
MD5 97b5a5c60a74e9a35b76a8a51fceac42
BLAKE2b-256 bc400df08e7d6916f3e4bea73c2156dd75a260fc9368558c323790b1ccec8694

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page