Skip to main content

ML-based image and video compression library with CLI

Project description

MLMediaCompressor

Image/Video compression using KMeans clustering.
This library reduces the color complexity of images by clustering pixel values into a limited palette, producing visually compressed images with fewer colors.


🚀 Installation

You can install directly from GitHub:

pip install git+https://github.com/1Nitin1/MLMediaCompressor.git

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

  • url (str): Path to the input image file.

  • n_colors (int): Number of colors (clusters) to reduce to. Default = 50.

  • Only for image quality (int): JPEG quality (1–95). Default = 50.

  • saveas (str): Output filename (without extension). Default = "compressed_image".

Returns:

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

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

Development

Clone the repo and install dependencies:

git clone https://github.com/yourusername/MLMediaCompressor.git
cd MLMediaCompressor
pip install -r requirements.txt

Contributing

  • Pull requests are welcome!
  • For major changes, please open an issue first to discuss what you’d like to change.

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.2.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.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mlmediacompressor-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 0e1f4c6f5b911d807fd0e128de757caec8868e833f6a10ba273ef52572c4d372
MD5 33ae7c70c500538d50f26f92d8797238
BLAKE2b-256 1b8959c85e704b505f3f3b04125bd10b6a71a6d1c2a79fa5b6bae43477e5eb28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mlmediacompressor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bcf86b8a03304ebb5ed743b56d36ff2f5e125fcaab5aa95f9d0c995864aad68a
MD5 95a846c64166534851d6848dce0adc34
BLAKE2b-256 fba21db6ed2dce91a92a0777441fa9c1da4dadae48153ec1d36c95364eb1df78

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