Skip to content

fmeyer/screenshotter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Screenshotter

A robust, high-performance Rust tool for extracting unique frames from video sequences using Mean Squared Error (MSE) analysis with comprehensive error handling and parallel processing.

Overview

Screenshotter processes sequential PNG frames extracted from video files and identifies visually distinct images by computing pixel-level differences between consecutive frames. The tool employs configurable parallel processing with robust error handling to efficiently and reliably handle large frame sequences.

Algorithm

The core algorithm implements Mean Squared Error calculation between consecutive frames:

  1. Frame Processing: Loads PNG images from input directory in lexicographical order
  2. MSE Computation: For each pixel (i,j), calculates:
    MSE = Σ[(R₂-R₁)² + (G₂-G₁)² + (B₂-B₁)²] / (3 × width × height)
    
  3. Threshold Evaluation: Frames exceeding the MSE threshold are copied to output directory
  4. Parallel Execution: Uses thread pool sized to available CPU cores for concurrent processing

Initial Frame Handling: The first frame is compared against a white baseline image, assuming typical video sequences begin with dark frames.

Performance Characteristics

  • Complexity: O(n×w×h) where n=frames, w=width, h=height
  • Threading: Work-stealing queue with configurable worker threads
  • Memory Usage: Processes frame pairs on-demand, minimal memory footprint
  • I/O Pattern: Sequential read with selective write based on threshold
  • Scalability: Automatic CPU core detection with manual override
  • Error Recovery: Individual frame failures don't halt processing

Installation

git clone <repository-url>
cd screenshotter
cargo build --release

Usage

Basic Operation

screenshotter --input <frame_directory> --output <output_directory> [--threshold <value>]

Parameters

  • --input, -i: Source directory containing sequential PNG frames
  • --output, -o: Destination directory for unique frames
  • --threshold, -t: MSE threshold value (default: 499.0)
  • --workers, -w: Number of worker threads (default: CPU cores)
  • --progress, -p: Show progress information during processing

Video Frame Extraction

Extract frames using FFmpeg with consistent naming:

ffmpeg -i video.mp4 -vf "fps=1" frames/frame_%04d.png

Advanced Usage

# With custom worker count and progress reporting
screenshotter -i frames -o unique_frames -t 600 -w 8 -p

# High sensitivity processing
screenshotter -i frames -o unique_frames -t 200 -p

Threshold Calibration

MSE values correlate with visual change magnitude:

  • 100-300: High sensitivity, captures subtle lighting changes
  • 400-600: Balanced sensitivity for general content
  • 700+: Low sensitivity, major scene transitions only

Features

  • Robust Error Handling: Comprehensive error recovery and meaningful error messages
  • Progress Reporting: Real-time progress feedback during processing
  • Configurable Threading: Adjustable worker thread count for optimal performance
  • Input Validation: Automatic validation of image dimensions and file integrity
  • Resource Management: Efficient memory usage and file handling

Recovery Features

  • Graceful degradation: Processing continues even if individual frames fail
  • Detailed error reporting: Specific error messages for troubleshooting
  • Input validation: Early detection of common issues before processing
  • Progress tracking: Resume capability through progress reporting

Output Format

Scanning Phase

Scanning for PNG files in 'frames'...
Found 1500 PNG files

Processing Phase

Processing with 8 worker threads
Using MSE threshold: 499
Processed 150/1499 pairs (10.0%)
Processed 300/1499 pairs (20.0%)

Completion Summary

Processing complete! Copied 87 unique frames to 'unique_frames'

With Progress Flag (-p)

Copied: frame_0045.png (MSE: 623.45)
Copied: frame_0089.png (MSE: 892.12)

Limitations

  • Perceptual Accuracy: MSE may not correlate with human visual perception
  • Transition Artifacts: Gradual effects (fades, dissolves) can produce false positives
  • Format Constraints: PNG input only, no format conversion
  • Temporal Assumptions: Requires chronologically ordered input files

Author

Fernando Meyer fm@pobox.com

Version

0.1.0

About

A robust, high-performance Rust tool for extracting unique frames from video sequences using Mean Squared Error (MSE) analysis with comprehensive error handling and parallel processing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages