Skip to main content

Automated video chapter generation using template matching and OCR

Project description

โšพ Loups

Automated video chapter generation using template matching and OCR

Automatically scan any video with on-screen text overlays to extract information and generate timestamped YouTube chapters! ๐ŸŽฅโœจ

Originally designed for Lights Out HB fastpitch softball games, but works with any video content that has consistent identifying frames or text overlays.

PyPI - Coming Soon Python 3.9+

โœจ What is Loups?

Loups uses template matching and OCR to automatically scan videos, detect specific frames with identifying information, and generate timestamped chapters.

Use cases include:

  • ๐ŸฅŽ Sports Games - Track player at-bats, shifts, or appearances (originally designed for fastpitch softball)
  • ๐ŸŽ“ Educational Content - Chapter markers for different topics or speakers
  • ๐ŸŽ™๏ธ Podcasts/Interviews - Detect guest name overlays or topic cards
  • ๐ŸŽฎ Gaming - Mark level changes, character selections, or game modes
  • ๐Ÿ“บ TV Shows/Series - Detect episode titles or scene markers
  • ๐ŸŽฌ Any Video - With consistent text overlays or identifying frames

๐Ÿ“ฆ Installation

Coming soon to PyPI! For now, install from source:

pip install loups

๐Ÿš€ Quick Start

# ๐ŸŽฌ For Lights Out HB games (uses bundled template)
loups game_video.mp4

# ๐ŸŽจ For any other video (use your own template)
loups -t my_template.png video.mp4

# ๐Ÿ’พ Save results to a file for YouTube chapters
loups -o chapters.txt video.mp4

# ๐Ÿคซ Quiet mode for automation/batch processing
loups -q -o chapters.txt video.mp4

Important: Options must be specified before the video argument.

๐Ÿ–ผ๏ธ Thumbnail Extraction

Loups can automatically extract thumbnails from your videos using SSIM (Structural Similarity Index) matching!

# Extract thumbnail using default template
loups video.mp4 thumbnail

# Use custom thumbnail template
loups video.mp4 thumbnail --thumbnail-template my_thumb_template.png

# Customize output location
loups video.mp4 thumbnail --thumbnail-output ./thumbnails/game_thumb.jpg

# Fine-tune the matching
loups video.mp4 thumbnail --thumbnail-threshold 0.85 --thumbnail-scan-duration 180

# Extract thumbnail during chapter scanning (options BEFORE video)
loups --extract-thumbnail --thumbnail-output thumb.jpg video.mp4

How Thumbnail Extraction Works

  1. ๐ŸŽฏ Template Matching - Scans video frames from the beginning using SSIM scoring
  2. โšก First-Match Strategy - Stops as soon as a frame exceeds the similarity threshold
  3. ๐Ÿ’พ Automatic Saving - Saves the matched frame as a JPEG thumbnail
  4. โฑ๏ธ Configurable Duration - Only scans the first N seconds (default: 120s)

Key Features:

  • ๐ŸŽฏ SSIM-based matching - More accurate than simple template matching
  • โšก Efficient scanning - Stops at first match, doesn't scan entire video
  • ๐ŸŽจ Default template support - Include thumbnail_template.png in package data
  • ๐Ÿ”ง Highly configurable - Control threshold, scan duration, and frame sampling

Options:

  • --thumbnail-template - Path to template image (uses default if not specified)
  • --thumbnail-output - Where to save thumbnail (default: <video>-thumbnail.jpg in current directory)
  • --thumbnail-threshold - Minimum SSIM score (0.0-1.0, default: 0.35)
  • --thumbnail-scan-duration - Max seconds to scan from start (default: 120)
  • --thumbnail-frames-per-second - Frame sampling rate (default: 3)

๐Ÿ“‹ Common Workflows

๐Ÿ“น Creating YouTube Chapters

# Scan video and save chapters for YouTube description
loups -o youtube_chapters.txt my_video.mp4
# Copy the contents of youtube_chapters.txt to your video description!

๐ŸŽจ Using Custom Templates

# Step 1: Create a template from a clear frame
# (Screenshot the text/overlay you want to detect)

# Step 2: Use your template
loups -t my_custom_template.png -o chapters.txt video.mp4

๐Ÿ”ง Troubleshooting with Logs

# Enable logging to debug detection issues
loups --log video.mp4

# Use custom log location with debug level
loups --log /path/to/debug.log --debug video.mp4

๐Ÿค– Automation & Batch Processing

# Process multiple videos quietly
loups -q -o video1_chapters.txt video1.mp4
loups -q -o video2_chapters.txt video2.mp4
loups -q -o video3_chapters.txt video3.mp4

๐Ÿ–ผ๏ธ Creating Thumbnails for YouTube

# Extract thumbnail with chapters in one command
loups -o chapters.txt --extract-thumbnail --thumbnail-output thumbnail.jpg game_video.mp4

# Or extract thumbnail separately
loups game_video.mp4 thumbnail --thumbnail-template title_screen.png

# Batch thumbnail extraction
loups video1.mp4 thumbnail --thumbnail-output vid1_thumb.jpg
loups video2.mp4 thumbnail --thumbnail-output vid2_thumb.jpg
loups video3.mp4 thumbnail --thumbnail-output vid3_thumb.jpg

โš™๏ธ CLI Options

Command Structure:

  • Default scanning: loups [OPTIONS] VIDEO - Options must come BEFORE the video path
  • Thumbnail extraction: loups VIDEO thumbnail [OPTIONS] - Thumbnail options come AFTER the subcommand

Main Command: loups [OPTIONS] VIDEO

Scan video for chapters (batter at-bats or any detected frames).

Required Arguments:

Argument Description
VIDEO ๐ŸŽฅ Path to the video file to scan (must come AFTER options)

Optional Flags:

Flag Short Description
--template PATH -t ๐ŸŽจ Path to template image for detection
โ€ข Defaults to bundled Lights Out HB template
โ€ข Provide your own for any video content
--output PATH -o ๐Ÿ’พ Save results to file in YouTube chapter format
--log [PATH] -l ๐Ÿ“ Enable logging (defaults to loups.log, or specify custom path)
โ€ข Rotates at 10MB
โ€ข Keeps 3 backup files
--quiet -q ๐Ÿคซ Suppress progress display (errors still shown)
--debug -d ๐Ÿ” Enable DEBUG level logging (requires --log)
--extract-thumbnail ๐Ÿ–ผ๏ธ Extract thumbnail during chapter scan
--thumbnail-template PATH ๐ŸŽจ Path to thumbnail template (optional)
--thumbnail-output PATH ๐Ÿ’พ Thumbnail save location (default: <video>-thumbnail.jpg)
--thumbnail-threshold FLOAT ๐ŸŽฏ SSIM threshold 0.0-1.0 (default: 0.35)
--thumbnail-scan-duration INT โฑ๏ธ Max seconds to scan for thumbnail (default: 120)
--thumbnail-frames-per-second INT ๐Ÿ“Š Frame sampling rate (default: 3)

Thumbnail Command: loups VIDEO thumbnail [OPTIONS]

Extract thumbnail from video using SSIM-based template matching.

Required Arguments:

Argument Description
VIDEO ๐ŸŽฅ Path to the video file (comes BEFORE the thumbnail subcommand)

Optional Flags:

Flag Description
--thumbnail-template PATH ๐ŸŽจ Path to thumbnail template (defaults to bundled template)
--thumbnail-output PATH ๐Ÿ’พ Output path (default: <video>-thumbnail.jpg in cwd)
--thumbnail-threshold FLOAT ๐ŸŽฏ Minimum SSIM score 0.0-1.0 (default: 0.35)
--thumbnail-scan-duration INT โฑ๏ธ Max seconds to scan from start (default: 120)
--thumbnail-frames-per-second INT ๐Ÿ“Š Frame sampling rate (default: 3)
--quiet ๐Ÿคซ Suppress output

โญ Features

๐ŸŽฏ Core Features

  • ๐ŸฅŽ Animated Progress Display - Real-time scanning with fun animations
  • ๐Ÿ” Template Matching - Detects specific frames using image templates
  • ๐Ÿ“ OCR Text Extraction - Reads text from matched frames to create chapter titles
  • ๐Ÿ“บ YouTube-Ready Output - Generates properly formatted chapter timestamps
  • ๐Ÿ–ผ๏ธ Thumbnail Extraction - SSIM-based automatic thumbnail extraction
  • ๐ŸŽจ Universal Custom Templates - Works with ANY video content
  • ๐Ÿ† Bundled Templates - Ready to use with Lights Out HB fastpitch games

๐Ÿ› ๏ธ Technical Features

  • ๐Ÿ“ Optional Logging - File logging with automatic rotation (10MB, 3 backups)
  • ๐Ÿ”ง Debug Mode - Detailed logs for troubleshooting
  • ๐Ÿคซ Quiet Mode - Perfect for automation and scripting
  • โšก Efficient Processing - Optimized video frame analysis
  • ๐ŸŽฏ Smart OCR - Confidence-based text extraction with filtering
  • ๐Ÿ”„ Smart Text Sorting - Left-to-right ordering of OCR results

๐Ÿ“š How It Works

Loups processes your video in several steps to create YouTube chapters:

  1. ๐Ÿ” Template Matching - Scans video frames looking for your template image

    • The template acts as a "trigger" that identifies frames of interest
    • When a match is found, Loups knows this frame contains information to extract
  2. ๐Ÿ“ OCR Text Extraction - On each matched frame, OCR reads the visible text

    • Extracts all text from the matched region (names, numbers, titles, etc.)
    • Applies confidence filtering to ensure accuracy
    • Sorts text elements left-to-right for proper ordering
  3. โฑ๏ธ Chapter Title & Timestamp - Combines the extracted text with video timestamp

    • Creates a chapter entry like: 0:05:23 John Smith #12
    • Each detection becomes a new YouTube chapter marker
  4. ๐Ÿ’พ YouTube Format Output - Exports chapters in YouTube-ready format

    • Copy and paste directly into your video description
    • Format: HH:MM:SS Chapter Title

Example:

0:00:00 Game Start
0:05:23 Sarah Johnson #7
0:08:45 Emma Martinez #12
0:12:30 Lily Garcia #9

๐ŸŽจ Creating Custom Templates

Loups works with any video - just provide a template!

  1. Find a clear frame - Pause your video where the text/overlay is visible
  2. Take a screenshot - Capture the region you want to detect
  3. Crop the template - Include the area where text appears
  4. Use it - loups -t my_template.png video.mp4

Tips for good templates:

  • โœ… Clear, high-contrast text
  • โœ… Consistent position throughout video
  • โœ… No motion blur or partial occlusion
  • โœ… Crop tightly around the target region

Example use cases:

  • ๐ŸŽฎ Game mode indicators or level titles
  • ๐ŸŽ“ Speaker name overlays in lectures
  • ๐Ÿ“บ Episode titles or scene markers
  • ๐Ÿ† Scoreboard player names (original use case)
  • ๐ŸŽต Song title overlays in music videos
  • ๐Ÿ“ฐ News segment titles or chyrons

๐Ÿ’ก Tips & Best Practices

๐ŸŽฏ For Best Results

  • โœ… Use high-quality video recordings (720p or higher recommended)
  • โœ… Ensure your template region is consistently visible throughout the video
  • โœ… Steady lighting/contrast improves OCR accuracy
  • โœ… Test on a short clip before processing full videos
  • โœ… The text in matched frames becomes your chapter titles - ensure it's readable!

๐Ÿ”ง Troubleshooting

  • Missed detections? Enable --log --debug to see template matches and OCR results
  • Wrong text extracted? Your template might be too large or including unwanted regions
  • False positives? Consider cropping your template more tightly around the identifying region
  • Template not matching? Ensure the template exactly matches the video frames
  • Names in wrong order? OCR results are automatically sorted left-to-right
  • Blank chapter titles? OCR confidence might be too low - check logs with --debug

๐Ÿค Contributing

Contributions are welcome! Whether it's:

  • ๐Ÿ› Bug reports
  • ๐Ÿ’ก Feature suggestions
  • ๐Ÿ“ Documentation improvements
  • ๐Ÿ”ง Code contributions
  • ๐ŸŽจ Sharing interesting use cases and templates

Please open an issue or pull request on GitHub.

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿ™ Acknowledgments

Originally created for Lights Out HB fastpitch softball coverage, now a flexible tool for any video content creator!


Made with โค๏ธ for content creators ๐ŸŽฌ

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

loups-0.1.0.tar.gz (461.3 kB view details)

Uploaded Source

Built Distribution

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

loups-0.1.0-py3-none-any.whl (402.7 kB view details)

Uploaded Python 3

File details

Details for the file loups-0.1.0.tar.gz.

File metadata

  • Download URL: loups-0.1.0.tar.gz
  • Upload date:
  • Size: 461.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for loups-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3f4fc32d09d32d65680cf873f709730f2e2e5e0c5f8dca5d0ba12e76e1a604e
MD5 f1ce8e8e7da40b83e2d41c5370d06313
BLAKE2b-256 86e793d150206903033b0dfd1129c184679c485905d9b9eb208bc76e2650e890

See more details on using hashes here.

Provenance

The following attestation bundles were made for loups-0.1.0.tar.gz:

Publisher: publish-to-pypi.yaml on jcspeegs/loups

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file loups-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: loups-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 402.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for loups-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 122c06358d86c5d8a74f709b6a42932a3b2b7faf9daca761fd2d42817a1234fe
MD5 8f338e052a32ae3374338132450cec30
BLAKE2b-256 884fde55752bb09d51e5dfd707d1a5fbf1274d5e3eee08ececcf160c11ab432d

See more details on using hashes here.

Provenance

The following attestation bundles were made for loups-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yaml on jcspeegs/loups

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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