Skip to content

aminesayagh/Shell_Media_Optimizer

Repository files navigation

Video & Image Processing Scripts

A collection of high-performance shell scripts for video compression, image optimization, and format conversion, designed for web content optimization.

Table of Contents

Prerequisites

Required dependencies:

  • ffmpeg for video processing
  • ImageMagick for image processing
  • libwebp-tools for WebP conversion
  • bc for mathematical calculations

Install dependencies on Ubuntu/Debian:

sudo apt update
sudo apt install ffmpeg imagemagick webp bc

Scripts Overview

1. Video Compression Script (compress_video.sh)

Compresses and optimizes videos for web delivery with responsive sizes.

Features:

  • Multiple output sizes (mobile, tablet, desktop)
  • Object-cover-like scaling
  • WebP thumbnail generation
  • Progress tracking
  • Quality preservation
  • Automatic aspect ratio handling

2. Video Cropping Script (crop_video.sh)

Crops and resizes videos while maintaining aspect ratios.

Features:

  • Smart cropping with center focus
  • Custom dimensions support
  • Progress tracking
  • WebP thumbnail generation
  • Multiple output formats

3. Image Compression Script (compress_image.sh)

Optimizes JPEG images for web use.

Features:

  • Maintains image quality
  • Strips metadata
  • Resizes to maximum dimensions
  • Progressive loading support
  • Batch processing capability

4. WebP Conversion Script (convert_webp.sh)

Converts images to WebP format with optimization.

Features:

  • Quality control
  • Batch processing
  • Size comparison
  • Progress tracking
  • Original file preservation

Installation

  1. Clone or download the scripts
  2. Make them executable:
chmod +x compress_video.sh crop_video.sh compress_image.sh convert_webp.sh

Usage

Video Compression

./compress_video.sh input_video.mp4
# or process all videos in input directory
./compress_video.sh

Video Cropping

./crop_video.sh input_video.mp4

Image Compression

./compress_image.sh -q 82 -w 1920 -p "*.jpg" -o compressed

WebP Conversion

./convert_webp.sh -q 82 -p "*.jpg" -o webp

Configuration

Video Compression Settings

# Default CRF values (lower = better quality)
LAPTOP_CRF=23
TABLET_CRF=24
MOBILE_CRF=25

# Default dimensions
LAPTOP: 1920x1080
TABLET: 1280x720
MOBILE: 854x480

Image Compression Settings

QUALITY=82        # JPEG quality
MAX_WIDTH=1920    # Maximum width

WebP Conversion Settings

QUALITY=82        # WebP quality

Examples

Compress a Video for Web

./compress_video.sh video.mp4

Output:

  • video_laptop.mp4 (1920x1080)
  • video_tablet.mp4 (1280x720)
  • video_mobile.mp4 (854x480)
  • video_thumb_[size].webp

Crop Video to Specific Dimensions

./crop_video.sh video.mp4

Output:

  • video_mobile.mp4 (500x700)
  • video_tablet.mp4 (800x700)
  • video_thumb.webp

Compress Images

./compress_image.sh -q 85 -w 1600 -p "images/*.jpg"

Convert to WebP

./convert_webp.sh -p "french-dandy-*.jpg" -q 85

Troubleshooting

Common Issues

  1. Permission Denied
chmod +x script_name.sh
  1. FFmpeg Not Found
sudo apt install ffmpeg
  1. Low Quality Output
  • Adjust CRF values (lower number = higher quality)
  • Modify quality settings for images
  1. Processing Fails
  • Check input file exists
  • Verify sufficient disk space
  • Check FFmpeg/ImageMagick installation

Tips

  • Use -h flag for help with any script
  • Monitor output directory for space
  • Check generated file sizes and quality
  • Use appropriate quality settings for your needs

License

These scripts are provided under the MIT License.

Contributing

Feel free to submit issues, fork the repository, and create pull requests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages