Skip to main content

Compress every frame of a movie in a single color barcode. Transform entire movies into stunning single-barcode visualizations. Capture the essence of cinematic storytelling through dominant color extraction from each frame.

Project description

Movie Barcodes

The Lodger: A Story of the London Fog (1927) - Alfred Hitchcock - Public Domain

Circular Barcode Horizontal Barcode

PyPI - Version PyPI - License Python Status Codecov pre-commit Black

Overview

Compress every frame of a movie in a single color barcode.

This project is a robust and highly configurable utility designed to extract dominant colors from video files and generate color barcodes. Built with Python and OpenCV, the tool offers multiple algorithms for color extraction, including average color, K-means clustering, and HSV/BGR histograms. The output can be generated in various forms, like horizontal and circular barcodes, providing a visually intuitive summary of the color distribution in the video.

Designed with performance in mind, the application supports both sequential and parallel processing. It scales automatically based on the available CPU cores but can be fine-tuned for a specified number of workers. This makes it suitable for analyzing both short clips and full-length movies with high efficiency.

Features

  • Horizontal and Circular Barcodes
  • Fast frame skipping for efficiency.
  • Supports .mp4, .webm & .mkv files
  • Multiprocessing support for parallel processing.
  • Customizable color extraction function (Average or K-means).
  • Progress tracking and estimated time remaining.

Usage

# Install the package
$ pip install movie-barcodes

# Generate a movie barcode
$ movie-barcodes -i "path/to/video.mp4"

# Arguments available
usage: movie-barcodes [-h] -i INPUT_VIDEO_PATH [-d [DESTINATION_PATH]] [-t {horizontal,circular}] [-m {avg,kmeans,hsv,bgr,smoothed}] [-w WORKERS] [--width WIDTH] [--height HEIGHT] [-n [OUTPUT_NAME]] [-a]

Mandatory Arguments:

  • -i, --input_video_path: The path to the input video file. (Required, type: str)

Optional Arguments:

  • -d, --destination_path: The path where the output image will be saved. If not provided, defaults to a pre-defined location. (Optional, type: str)

  • -t, --barcode_type: The type of barcode to generate. Options are horizontal or circular. Default is horizontal. (Optional, type: str)

  • -m, --method: The algorithm for extracting the dominant color from frames. Options are avg (average), kmeans (K-Means clustering), hsv (HSV histogram), bgr (BGR histogram) and smoothed versions. Default is avg. (Optional, type: str)

  • -w, --workers: Number of parallel workers for processing. By default, the script will use all available CPU cores. Setting this to 1 will use sequential processing. (Optional, type: int)

  • --width: The output image's width in pixels. If not specified, the width will be the same as the input video. (Optional, type: int)

  • --height: The output image's height in pixels. If not specified, the height will be the same as the input video. (Optional, type: int)

  • -n, --output_name: Custom name for the output barcode image. If not provided, a name will be automatically generated. (Optional, type: str)

  • -a, --all_methods: If set to True, all methods for color extraction will be employed, overriding the --method argument. Default is False. (Optional, type: bool)

Examples

Sequential Processing

python -m movie_barcodes -i "path/to/video" --width 200 -w 1

Parallel Processing

python -m movie_barcodes -i "path/to/video" --width 200 -w 8

Development Setup

# Clone this repository
$ git clone https://github.com/Wazzabeee/movie-barcodes

# Go into the repository
$ cd movie-barcodes

# (Recommended) Use uv for environment and tools
$ curl -LsSf https://astral.sh/uv/install.sh | sh   # or see uv docs for your OS

# Create a virtual environment and install dependencies
$ uv venv
$ uv pip install -r requirements.txt

# Install pre-commit hooks
$ uvx pre-commit install

# Run tests
$ uv pip install pytest pytest-cov
$ uv run pytest tests/

# Run package locally
$ uv run python -m movie_barcodes -i "path_to_video.mp4"

Todo

  • Optimize K-means to speed up the process
  • Add a small GUI with all options available
  • Add option to modify the barcode's height (current is frame's height)
  • Ensure the software can handle various video formats beyond MP4
  • Allow the software to process multiple videos at once
  • Develop POC on Hugging Face Space
  • Remove the logs creation when using package

More Examples

Barbie (2023) - Greta Gerwig

movie-barcodes -i "barbie.mp4" -t "circular" -m "smoothed"
movie-barcodes -i "barbie.mp4" --width 1920 --height 1080 -t "horizontal"
Circular Barcode Horizontal Barcode

Le Fabuleux Destin d'Amélie Poulain (2001) - Jean-Pierre Jeunet

movie-barcodes -i "amelie.mp4" -t "circular" -m "smoothed"
movie-barcodes -i "amelie.mp4" --width 1920 --height 1080 -t "horizontal"
Circular Barcode Horizontal Barcode

Your Name / Kimi no Na wa / 君の名は (2016) - Makoto Shinkai

movie-barcodes -i "Your Name.mp4" -t "circular" -m "smoothed"
movie-barcodes -i "Your Name.mp4" --width 1920 --height 1080 -t "horizontal"
Circular Barcode Horizontal Barcode

Drive (2011) - Nicolas Winding Refn

movie-barcodes -i "Drive.mp4" -t "circular" -m "smoothed"
movie-barcodes -i "Drive.mp4" --width 1920 --height 1080 -t "horizontal"
Circular Barcode Horizontal Barcode

The Royal Tenenbaums (2001) - Wes Anderson

movie-barcodes -i "royal_tenenbaums.mp4" -t "circular" -m "smoothed"
movie-barcodes -i "royal_tenenbaums.mp4" --width 1920 --height 1080 -t "horizontal"
Circular Barcode Horizontal Barcode

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

movie_barcodes-0.6.1.tar.gz (7.5 MB view details)

Uploaded Source

Built Distribution

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

movie_barcodes-0.6.1-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file movie_barcodes-0.6.1.tar.gz.

File metadata

  • Download URL: movie_barcodes-0.6.1.tar.gz
  • Upload date:
  • Size: 7.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for movie_barcodes-0.6.1.tar.gz
Algorithm Hash digest
SHA256 8700fe80b5d732cc1511ba3da267e98a6e667949a5b8534d6f08d1caa2f54742
MD5 cd32fc0b53f0c4c74ba3ca2ea8681119
BLAKE2b-256 713a189c0facd0e6cbc583d98f804ab95852f58b4da80cad31433c533538fecb

See more details on using hashes here.

File details

Details for the file movie_barcodes-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: movie_barcodes-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for movie_barcodes-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b0bf02df195bd6bdcd62eea025e5a0145c07541f59f51a6d8741494c373e262
MD5 7b60e865505d194d3ed392e1dce54758
BLAKE2b-256 4f92c5bfc3af2cc16f953db39b7d13b6741a165a39af90570ac4010bd14d8032

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