{"id":19289787,"url":"https://github.com/ragibson/media-gallery-compressor","last_synced_at":"2025-04-22T05:31:44.523Z","repository":{"id":204049219,"uuid":"707708537","full_name":"ragibson/media-gallery-compressor","owner":"ragibson","description":"Simple tool to compress the entire set of photos and videos in a directory.","archived":false,"fork":false,"pushed_at":"2024-05-22T16:03:19.000Z","size":71,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T20:00:16.122Z","etag":null,"topics":["compression","folder-compression","image-compression","lossless-compression","lossy-compression","video-compression"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ragibson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-20T13:36:49.000Z","updated_at":"2024-07-29T16:31:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"40a966d5-207f-4a20-8283-02c965ec4403","html_url":"https://github.com/ragibson/media-gallery-compressor","commit_stats":null,"previous_names":["ragibson/media-gallery-compressor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragibson%2Fmedia-gallery-compressor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragibson%2Fmedia-gallery-compressor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragibson%2Fmedia-gallery-compressor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ragibson%2Fmedia-gallery-compressor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ragibson","download_url":"https://codeload.github.com/ragibson/media-gallery-compressor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250175066,"owners_count":21387132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compression","folder-compression","image-compression","lossless-compression","lossy-compression","video-compression"],"created_at":"2024-11-09T22:17:10.904Z","updated_at":"2025-04-22T05:31:44.261Z","avatar_url":"https://github.com/ragibson.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# media-gallery-compressor\n\nTool to compress the entire set of photos and videos in a directory (where beneficial).\n\n## Table of Contents\n\n* [Features](#features)\n* [Basic Usage](#basic-usage)\n* [Examples and other quality recommendations](#examples-and-other-quality-recommendations)\n* [Why?](#why)\n\n## Features\n\n* Multithreaded compression typically achieves a throughput of a few GB of images per minute\n* Retains \"visually lossless\" images and photos with extremely high default quality settings that typically achieve ~60%\n  compression\n    * PNG: maximum compression level and extra processing pass to determine optimal encoder settings\n    * JPEG: 95 quality, 4:4:4 subsampling, and extra processing pass to determine optimal encoder settings\n    * Videos: H.265 encoding with CRF 24\n* Downscales images based on the smaller dimension to support arbitrary aspect ratios\n    * By default, keeps resolutions higher than a 4K equivalent\n* Corrects image file extensions that are incorrect in the source filesystem\n* Retains most image and video metadata from the input as well as the files' modified and access times\n* Double checks that all files from the input were copied over to the output, explicitly tagging those that were\n  compressed\n* Only depends on Pillow (for image compression), ffmpeg (for video compression), and tqdm (for displaying progress)\n\n## Basic Usage\n\n```\nusage: compressor.py [-h] -i INPUT_DIRECTORY -o OUTPUT_DIRECTORY\n                     [-t TEMP_DIRECTORY] [-v] [-s SUFFIX]\n                     [-m MINIMUM_IMAGE_DIMENSION]\n\nCompress all files within a media directory, where beneficial\n\noptions:\n  -h, --help            show this help message and exit\n  -i INPUT_DIRECTORY, --input-directory INPUT_DIRECTORY\n                        Input media directory\n  -o OUTPUT_DIRECTORY, --output-directory OUTPUT_DIRECTORY\n                        Output media directory to create\n  -t TEMP_DIRECTORY, --temp-directory TEMP_DIRECTORY\n                        Temporary directory to create for intermediate files\n                        (default: temp_RG01COMPRESS)\n  -v, --verbose         If specified, will increase the verbosity of printed\n                        information (default: False)\n  -s SUFFIX, --suffix SUFFIX\n                        Suffix to append to file names when compressed\n                        (default: _RG01COMPRESS)\n  -m MINIMUM_IMAGE_DIMENSION, --minimum-image-dimension MINIMUM_IMAGE_DIMENSION\n                        Resolution to reduce the smaller image dimension to,\n                        if needed (default: 2160)\n  -p PROCESSES, --processes PROCESSES\n                        Maximum number of compression processes to run in\n                        parallel. Defaults to the number of CPUs in the\n                        system. (default: 8)\n```\n\nThere are a few more command line arguments that I would expect to be more rarely used.\n\n```\n  -d, --delete-existing\n                        If specified, will delete existing output and temp\n                        directories (default: False)\n  --jpeg-quality JPEG_QUALITY\n                        Quality setting for compressing JPEG images (default:\n                        95)\n  --jpeg-subsampling JPEG_SUBSAMPLING\n                        Subsampling setting for compressing JPEG images\n                        (default: 4:4:4)\n  --video-codec VIDEO_CODEC\n                        Codec for compressing videos with ffmpeg (default:\n                        libx265)\n  --video-crf VIDEO_CRF\n                        Constant rate factor for compressing videos with\n                        ffmpeg (default: 24)\n  --maximum-expected-compression MAXIMUM_EXPECTED_COMPRESSION\n                        Maximum compression percentage for sanity checks. An\n                        error will be raised if this threshold is ever\n                        exceeded after compressing a file. (default: 99)\n```\n\n### Examples and other quality recommendations\n\nUsing default settings, we get an overall compression rate of ~60%.\n\nSome alternative \"high-quality\" settings would be using 1440p resolution, JPEG quality 90, and CRF 26. This achieves a\ncompression rate of ~80%.\n\nFinally, a more \"medium\" quality setting of 1080p resolution, JPEG quality 85, JPEG 4:2:0 subsampling, and CRF 28\nyields a compression rate of ~90%.\n\n```bash\n$ python3 compressor.py -i \"media_to_compress\" -o \"media_after_compression\"\nProcessing 8445 input files...\n\ninput_directory summary (49.5 GB in total):\ninput_directory -\u003e Camera (48.7 GB in total):\n|  .jpg only: 28.8 GB\n|  .mp4 only: 19.5 GB\n|  .mov only: 168.9 MB\n|  .dng only: 99.9 MB\n|  .png only: 56.6 MB\n(Other subdirectories omitted for example)\n\nCompressing input files: 100%|█████████████████████████████| 8445/8445\nOutput directory appears consistent with the input.\n\noutput_directory summary (20.9 GB in total):\noutput_directory -\u003e Camera (20.4 GB in total):\n|  .jpg only: 14.9 GB\n|  .mp4 only: 5.3 GB\n|  .dng only: 99.9 MB\n|  .png only: 43.2 MB\n|  .mov only: 6.2 MB\n(Other subdirectories omitted for example)\n\n$ python3 compressor.py -i \"media_to_compress\" -o \"media_after_compression\" -m 1440 --jpeg-quality 90 --video-crf 26\n(Input summary omitted for example)\noutput_directory summary (9.6 GB in total):\noutput_directory -\u003e Camera (9.2 GB in total):\n|  .jpg only: 5.2 GB\n|  .mp4 only: 3.9 GB\n|  .dng only: 99.9 MB\n|  .png only: 36.6 MB\n(Other subdirectories omitted for example)\n\n$ python3 compressor.py -i \"media_to_compress\" -o \"media_after_compression\" -m 1080 --jpeg-quality 85 --jpeg-subsampling \"4:2:0\" --video-crf 28\n(Input summary omitted for example)\noutput_directory summary (5.5 GB in total):\noutput_directory -\u003e Camera (5.3 GB in total):\n|  .mp4 only: 2.8 GB\n|  .jpg only: 2.3 GB\n|  .dng only: 99.9 MB\n|  .png only: 32.2 MB\n(Other subdirectories omitted for example)\n```\n\n## Why?\n\nObviously, this could be used to drastically reduce the file sizes of a media library without any perceptible loss of\nquality, but I actually use it to trim down the content on secondary devices.\n\nPerhaps this a bit of an unusual use case, but I have a tremendous amount of photos/videos on my phone and use them more\nas a scrapbook to look through occasionally or for reference to trips from long ago. This balloons in size very quickly,\nbut all the content is backed up elsewhere, so it does not need to be in the original, raw quality at all.\n\nAs such, this mass compression focuses on visually lossless, high-quality defaults and otherwise falls back to copying\nover the original file if that saves no space.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fragibson%2Fmedia-gallery-compressor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fragibson%2Fmedia-gallery-compressor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fragibson%2Fmedia-gallery-compressor/lists"}