shrink

module
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: BSD-3-Clause

README

shrink

A high-performance media optimization tool written in Go. shrink automatically transcodes video, audio, images, and ebooks into modern, space-efficient formats like AV1, Opus, and AVIF. It can also recursively extract and process files within archives.

Supported formats

  • Video: Transcodes to AV1 (using SVT-AV1) in an MKV container.
  • Audio: Transcodes to Opus.
  • Images: Converts to AVIF (using ImageMagick).
  • Ebooks: Optimizes EPUB/PDF files by compressing internal images and cleaning CSS (using Calibre).
  • Archives: Recursively extracts and processes contents of ZIP, RAR, 7z, and more (using unar).

Features

  • Smart Filtering: Only processes files if the estimated savings meet your configured thresholds.
  • Parallelism: Concurrent processing of different media types.
  • Database Support: Integrates with SQLite databases to track and manage media state.
  • Video game / EXE mangler: This will help you cut down on your video game habit by mangling your EXE archives that contain video game resources in common formats by converting them into something that the video game doesn't expect and so it will probably crash!

Installation

Ensure you have Go installed, then run:

go install -tags fts5 github.com/chapmanjacobd/shrink/cmd/shrink@latest

External Dependencies

shrink relies on several industry-standard tools for media processing. Ensure these are installed and available in your PATH:

Tool Required For
FFmpeg Video and Audio transcoding
ImageMagick Image conversion (specifically magick)
Calibre Ebook conversion (ebook-convert)
unar Archive extraction (unar and lsar)
ocrmypdf (Optional) OCR for PDF files
OS-Specific Installation Notes

Fedora/RHEL:

  • ImageMagick requires the ImageMagick-heic package for HEIC/AVIF support:
    sudo dnf install ImageMagick-heic
    

macOS:

  • Calibre may require Rosetta 2 on Apple Silicon if the installed version is not yet native:
    softwareupdate --install-rosetta
    

Ubuntu/Debian:

  • FFmpeg may need the ffmpeg-extras package for full codec support (e.g., H.265, AV1):
    sudo apt install ffmpeg-extras
    

Quick Start

Basic Usage

Shrink all media in a directory:

shrink .
Advanced Examples

Process only video files and move successful transcodes to a specific directory:

shrink --video-only --move ./optimized_videos /path/to/media

Shrink files while requiring at least 20% space savings for video:

shrink --min-savings-video=20% /path/to/media

Dry run to see what would be processed:

shrink --simulate /path/to/media

Only transcode during specific hours (e.g., overnight 10pm-6am):

shrink --active-time 10pm-6am /path/to/media

Multiple active periods (lunch and evening):

shrink --active-time 12pm-1pm --active-time 6pm-11pm /path/to/media

CLI Reference

Global Flags
Flag Description Default
-v, --verbose Enable verbose logging false
--simulate Dry run; don't actually modify files false
-y, --no-confirm Don't ask for confirmation before starting false
--video-threads Maximum concurrent video transcodes 2
--video-4k-threads Maximum concurrent video transcodes for 4K+ resolution videos 1
--audio-threads Maximum concurrent audio transcodes 4
--image-threads Maximum concurrent image conversions 8
--text-threads Maximum concurrent text conversions 2
Optimization Flags
Flag Description Default
--min-savings-video Minimum savings for video (e.g., "10%" or "50MB") 5%
--min-savings-audio Minimum savings for audio 10%
--min-savings-image Minimum savings for images 15%
--preset SVT-AV1 preset (0-13, lower is slower/better) 7
--crf CRF value for SVT-AV1 (0-63, lower is higher quality) 40
--max-video-height Maximum video height 960
--max-video-width Maximum video width 1440
Filter Flags
Flag Description
--video-only Only process video files
--audio-only Only process audio files
--image-only Only process image files
--text-only Only process text/ebook files
-s, --include Include paths matching pattern
-E, --exclude Exclude paths matching pattern
Schedule Flags
Flag Description
--active-time Only transcode if estimated finish time falls within active period. Supports multiple time ranges. Accepts 12-hour (2pm, 8:30am) and 24-hour (14:00, 23:30) formats.
Schedule Examples

Only process during evening/night hours:

shrink --active-time 6pm-8am /path/to/media

Process during lunch break and evening:

shrink --active-time 12pm-1pm --active-time 6pm-10pm /path/to/media

Using 24-hour format:

shrink --active-time 11:30-23:00 /path/to/media

License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.

Directories

Path Synopsis
cmd
shrink command
internal
commands
Package commands implements the CLI commands and orchestration logic for the shrink application.
Package commands implements the CLI commands and orchestration logic for the shrink application.
db
Package db provides database access for archive analysis cache.
Package db provides database access for archive analysis cache.
ffmpeg
Package ffmpeg provides wrappers for FFmpeg and FFprobe operations.
Package ffmpeg provides wrappers for FFmpeg and FFprobe operations.
models
Package models defines the core data structures used throughout the application.
Package models defines the core data structures used throughout the application.
testutils
Package testutils provides helper functions and types for testing the shrink application.
Package testutils provides helper functions and types for testing the shrink application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL