Skip to main content

ML-based image and video compression library with CLI

Project description

MLMediaCompressor

ML‑based image and video color complexity compression library with CLI support.


Features

  • Image compression using KMeans color quantization

  • Video compression (frame‑wise KMeans)

  • Automatic .mov → .mp4 conversion for compatibility

  • CLI support for quick usage from terminal

🚀 Installation

You can install directly using pip:

pip install MLMediaCompressor

Usage

from MLMediaCompressor import compress_image, compress_video

# Compress image
compress_image("input.png", n_colors=12, saveas="output")

# Compress video
compress_video("input.mov", n_colors=16, saveas="output_video")

🖥️ Command-Line Usage

After installing, you can run the compressor directly from the terminal:

# Image compression
mlcompress image input.png --n_colors 12 --quality 80 --saveas out

# Video compression (MOV auto-converts to MP4)
mlcompress video input.mov --n_colors 16 --saveas out

Parameters

Common (Image & Video)

  • path (str): Path to the input file.

    • For images: supported formats like .png, .jpeg.
    • For videos: supported formats .mp4 and .mov (MOV is auto‑converted to MP4).
  • n_colors (int): Number of color clusters (KMeans) to reduce to. Default = 50 for images, 20 for videos.

  • saveas (str): Output filename (without extension)

    • Default = "compressed_image" for images
    • Default = "compressed_video" for videos.

Image‑specific

  • quality (int): JPEG quality (1–95). Default = 50.
    • Only applies when saving compressed images.

Returns:

  • A PIL.Image.Image object representing the compressed image.
  • A mp4 file representing the compressed video.

Contributing

License

This project is licensed under the MIT License — see the LICENSE file for details.

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

mlmediacompressor-0.1.3.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

mlmediacompressor-0.1.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file mlmediacompressor-0.1.3.tar.gz.

File metadata

  • Download URL: mlmediacompressor-0.1.3.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for mlmediacompressor-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f7576821d52a1c37c9dab0f9efe4297e0f607f480d2065ed561a8b0d44ec87cb
MD5 c977ed23ba3d88d1a4c9349eebb95a73
BLAKE2b-256 1f04e96f40297e641aaea21757bef0bcf215821404bf232d624bc0fd93fcf0ad

See more details on using hashes here.

File details

Details for the file mlmediacompressor-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mlmediacompressor-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 398961a0329241aa126571ca45451a1cc1001819c0874a681be8c6eb0360f9ff
MD5 2bf31cbed636c5b592cadf75282e8ae1
BLAKE2b-256 b1fe0bc490c989778b2067b26ff14708141b9f2903812fb8783480cdbcd6340e

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