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 version Python 3.13+ GitHub Actions Documentation License: MIT Downloads

Links: Repository โ€ข Documentation โ€ข Issues โ€ข PyPI โ€ข Author

โœจ 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

terminal-cast

๐Ÿ“‘ Table of Contents

๐Ÿ“ฆ Installation

Requirements: Python 3.13 or higher

Supported Platforms: Linux โ€ข macOS โ€ข Windows (tested via CI/CD)

# Install from PyPI
pip install loups

# Verify installation
loups --help

Note: If you're using an older Python version, you may need to upgrade:

# Check your Python version
python --version

# Install with specific Python version if needed
python3.13 -m pip install loups

๐Ÿš€ Quick Start

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

Expected output:

๐ŸฅŽ Scanning video for batter at-bats...
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100% 0:05:23

Found 12 batters:
0:00:00 Game Start
0:01:15 Sarah Johnson #7
0:03:42 Emma Martinez #12
0:05:23 Lily Garcia #9
...

More examples:

# ๐ŸŽจ 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

Common Issues

Python Version Errors

  • Error: ModuleNotFoundError or SyntaxError during installation
  • Solution: Loups requires Python 3.13+. Check your version with python --version and upgrade if needed

First Run is Slow

  • Behavior: First execution takes several minutes to start
  • Why: EasyOCR automatically downloads OCR models (~100MB) on first run
  • Solution: This is normal! Subsequent runs will be much faster. Be patient during the initial setup.

Detection Issues

  • 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 (size, position, quality)

OCR Issues

  • 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
  • Garbled text? Improve video quality or use a clearer template region

Video Codec Issues

  • Error: cv2.error or video won't open
  • Solution: Some video formats require additional codecs. Try converting to MP4 (H.264) format

๐Ÿค 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.1.tar.gz (1.4 MB 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.1-py3-none-any.whl (406.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for loups-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c4b61f413cd71214994717c650b682c80c8426883c6ae563f03134541a6f4664
MD5 b211aafb5ff07b57eafc942409cf7f97
BLAKE2b-256 85fe83b6d77d15cc786378efda776a2694e7456de356ec08cd3445b1fbc3a0ea

See more details on using hashes here.

Provenance

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

Publisher: publish-package.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.1-py3-none-any.whl.

File metadata

  • Download URL: loups-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 406.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe1c4c438b8ffee2db08fc36077e63d93fea32513666e4110c2ea5d7d88f8df4
MD5 aa476dc07b5d4301f3bd2e04354f037c
BLAKE2b-256 1043493d324f22f5c9f6127004180b42686ff2d8d766964e9d924372a64dd919

See more details on using hashes here.

Provenance

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

Publisher: publish-package.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