media-compress

Compress and convert images and videos using ffmpeg. Use when the user wants to reduce file size, change format, resize, or optimize media files. Handles common formats like JPG, PNG, WebP, MP4, MOV, WebM. Triggers on phrases like "compress image", "compress video", "reduce file size", "convert to webp/mp4", "resize image", "make image smaller", "batch compress", "optimize media".

3,891 stars
Complexity: medium

About this skill

This skill provides powerful media compression and conversion capabilities by leveraging the FFmpeg library. It adeptly handles a wide range of image formats including JPG, PNG, WebP, BMP, TIFF, and GIF for input, with output options for JPG, PNG, and WebP. For videos, it supports MP4, MOV, AVI, MKV, WebM, FLV, WMV, and M4V inputs, converting them efficiently to MP4. The skill offers flexible options for optimization, allowing users to target specific file sizes, adjust quality, resize dimensions (width/height), or convert to more efficient formats like WebP. It supports both single file and batch processing, making it highly versatile for managing collections of media. Advanced features like a preview mode and the option to keep original file backups ensure safe and controlled operations. Developers, content creators, and anyone needing to efficiently manage and process digital media will find this skill invaluable. It simplifies complex FFmpeg commands into accessible Python scripts, enabling automation of tasks such as optimizing web assets, preparing media for social media or email, or simply freeing up storage space.

Best use case

The primary use case is optimizing digital media assets (images and videos) for efficiency in web deployment, storage, or distribution. Web developers, content creators, social media managers, and anyone with large media libraries benefit most from automating tasks like reducing file sizes, standardizing formats, and resizing dimensions without losing significant quality.

Compress and convert images and videos using ffmpeg. Use when the user wants to reduce file size, change format, resize, or optimize media files. Handles common formats like JPG, PNG, WebP, MP4, MOV, WebM. Triggers on phrases like "compress image", "compress video", "reduce file size", "convert to webp/mp4", "resize image", "make image smaller", "batch compress", "optimize media".

The user should expect optimized, smaller, or reformatted image and video files, ready for their intended purpose, with clear feedback on the operation's success.

Practical example

Example input

Compress the `my_travel_video.mp4` to approximately 50MB and save it as `my_travel_video_optimized.mp4`.

Example output

Successfully compressed `my_travel_video.mp4` to `my_travel_video_optimized.mp4` (49.2 MB).

When to use this skill

  • You need to reduce the file size of images or videos.
  • You want to convert media files to different formats (e.g., JPG to WebP, MOV to MP4).
  • You need to resize images or videos to specific dimensions for web or print.
  • You are performing batch processing on multiple media files in a folder.

When not to use this skill

  • Performing advanced video editing tasks like cutting, merging, or adding complex effects.
  • When strictly lossless compression or conversion is required (this skill focuses on optimized, often lossy, compression).
  • Working with highly specialized or obscure media formats not supported by FFmpeg.
  • If FFmpeg cannot be installed or is not available on your system.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/media-compress/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/1987566643/media-compress/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/media-compress/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How media-compress Compares

Feature / Agentmedia-compressStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexitymediumN/A

Frequently Asked Questions

What does this skill do?

Compress and convert images and videos using ffmpeg. Use when the user wants to reduce file size, change format, resize, or optimize media files. Handles common formats like JPG, PNG, WebP, MP4, MOV, WebM. Triggers on phrases like "compress image", "compress video", "reduce file size", "convert to webp/mp4", "resize image", "make image smaller", "batch compress", "optimize media".

How difficult is it to install?

The installation complexity is rated as medium. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Media Compression Skill

Compress and convert images and videos with intelligent defaults. Supports single files and batch processing.

## Supported Formats

**Images:** JPG, PNG, WebP, BMP, TIFF, GIF → JPG, PNG, WebP
**Videos:** MP4, MOV, AVI, MKV, WebM, FLV, WMV, M4V → MP4

## Prerequisites

**ffmpeg must be installed:**
- Ubuntu/Debian: `sudo apt update && sudo apt install ffmpeg`
- macOS: `brew install ffmpeg`
- Windows: Download from https://ffmpeg.org/download.html and add to PATH

Verify installation: `ffmpeg -version`

## Quick Start

### Image Compression

```bash
# Compress to target size (auto-adjusts quality)
python scripts/compress_image.py photo.jpg --max-size 200kb

# Resize + compress
python scripts/compress_image.py photo.png --width 800 --output photo_small.jpg

# Convert to WebP (better compression)
python scripts/compress_image.py photo.jpg --format webp

# Batch compress entire folder
python scripts/compress_image.py ./photos --output ./compressed --quality 80

# Preview mode - see what will happen without compressing
python scripts/compress_image.py photo.jpg --max-size 500kb --preview

# Keep backup of original file
python scripts/compress_image.py photo.jpg --max-size 500kb --backup
```

### Video Compression

```bash
# Compress with default settings (good balance)
python scripts/compress_video.py video.mp4 --output video_small.mp4

# Resize to 720p
python scripts/compress_video.py video.mp4 --height 720

# Target specific file size (approximate)
python scripts/compress_video.py video.mp4 --target-size 50mb

# Lower quality for smaller file
python scripts/compress_video.py video.mp4 --crf 28

# Batch process all videos in folder
python scripts/compress_video.py ./videos --output ./compressed --height 480

# Preview mode - see what will happen without compressing
python scripts/compress_video.py video.mp4 --height 720 --preview

# Keep backup of original file
python scripts/compress_video.py video.mp4 --height 720 --backup
```

## Common Use Cases

### 1. Upload to Website (Image)
Most websites need images under 500KB:
```bash
python scripts/compress_image.py photo.jpg --max-size 500kb --format webp
```

### 2. Email Attachment (Image)
Email often has 25MB limit:
```bash
python scripts/compress_image.py scan.pdf.jpg --max-size 5mb --quality 90
```

### 3. Social Media Video
Platforms prefer 720p, smaller files:
```bash
python scripts/compress_video.py clip.mov --height 720 --crf 23 --preset fast
```

### 4. Archive Old Videos
Maximum compression for storage:
```bash
python scripts/compress_video.py old_video.avi --crf 28 --preset slow --height 480
```

### 5. Convert Format Only
Keep quality, just change format:
```bash
# Image
python scripts/compress_image.py image.png --format jpg --quality 95

# Video
python scripts/compress_video.py video.mov --output video.mp4 --crf 18
```

## Parameters Reference

### Image (`compress_image.py`)

| Parameter | Description | Default |
|-----------|-------------|---------|
| `input` | Input file or directory (required) | - |
| `--output, -o` | Output file or directory | Auto-generated |
| `--max-size` | Target max file size (e.g., 500kb, 2mb) | None |
| `--quality, -q` | JPEG/WebP quality (1-100) | 85 |
| `--width, -w` | Max width in pixels | Original |
| `--height` | Max height in pixels | Original |
| `--format, -f` | Output format: jpg, png, webp | Original format |
| `--no-strip` | Keep metadata (default: remove) | False |
| `--preview, -p` | Preview mode: show settings without compressing | False |
| `--backup, -b` | Keep backup of original file | False |

### Video (`compress_video.py`)

| Parameter | Description | Default |
|-----------|-------------|---------|
| `input` | Input file or directory (required) | - |
| `--output, -o` | Output file or directory | Auto-generated |
| `--crf` | Quality 0-51 (lower=better). 18=visually lossless, 23=default, 28=smaller | 23 |
| `--preset` | Encoding speed: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow | medium |
| `--height` | Max height (480, 720, 1080) | Original |
| `--target-size` | Approximate target size (e.g., 50mb, 1gb) | None |
| `--fps` | Limit frame rate (e.g., 30, 24) | Original |
| `--audio-bitrate` | Audio quality (e.g., 128k, 192k) | 128k |
| `--preview, -p` | Preview mode: show settings without compressing | False |
| `--backup, -b` | Keep backup of original file | False |

## Quality Guidelines

### Images
- **90-95**: High quality, minimal compression artifacts
- **85**: Sweet spot (default) - good quality, significant size reduction
- **70-80**: Acceptable for web, smaller files
- **50-60**: Low quality, visible artifacts

### Videos (CRF)
- **17-18**: Visually lossless, archival quality
- **20-22**: High quality, professional use
- **23**: Default, good balance (recommended)
- **28**: Smaller files, acceptable quality
- **35+**: Low quality, preview/draft only

### Presets
- **ultrafast**: Fastest encoding, largest files
- **fast**: Quick results, slightly larger
- **medium**: Default balance
- **slow**: Better compression, smaller files
- **veryslow**: Maximum compression, smallest files

## Batch Processing

When input is a directory:
- All supported files are processed
- Output directory structure mirrors input
- Progress shown for each file
- Original and compressed sizes displayed

Example:
```bash
$ python scripts/compress_image.py ./vacation_photos --output ./compressed --max-size 500kb
找到 24 个图像文件
[1/24] 处理: IMG_001.jpg
  ✓ 2847.3KB → 456.2KB (84.0% 减少)
[2/24] 处理: IMG_002.png
  ✓ 1532.1KB → 298.5KB (80.5% 减少)
...
```

## Troubleshooting

### "ffmpeg not found"
Install ffmpeg first:
```bash
# Ubuntu/Debian
sudo apt update && sudo apt install ffmpeg

# macOS
brew install ffmpeg
```

### "Permission denied"
Make scripts executable:
```bash
chmod +x scripts/*.py
```

### Quality too low
Increase quality setting:
```bash
# Image
python scripts/compress_image.py photo.jpg --quality 90

# Video
python scripts/compress_video.py video.mp4 --crf 20
```

### File not smaller
- Try lower quality or smaller dimensions
- Some files are already optimally compressed
- Use `--max-size` to force target size

### Batch processing stops
Check that all files in directory are valid images/videos. Corrupt files may cause errors.

## Advanced Tips

1. **Strip metadata** for privacy (default behavior)
2. **Use WebP** for best web compression
3. **720p height** is usually enough for mobile viewing
4. **CRF 23 + preset slow** gives great results for archiving
5. **Test with one file** before batch processing

## References

- [FFmpeg Guide](references/ffmpeg_guide.md) - Detailed ffmpeg commands and parameters

Related Skills

find-skills

3891
from openclaw/skills

Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.

General Utilities

filesystem

3891
from openclaw/skills

Advanced filesystem operations for listing files, searching content, batch processing, and directory analysis. Supports recursive search, file type filtering, size analysis, and batch operations like copy/move/delete. Use when you need to: list directory contents, search for files by name or content, analyze directory structures, perform batch file operations, or analyze file sizes and distribution.

General Utilities

Budget & Expense Tracker — AI Agent Financial Command Center

3891
from openclaw/skills

Track every dollar, enforce budgets, spot spending patterns, and build wealth — all through natural conversation with your AI agent.

General Utilities

yt-dlp

3891
from openclaw/skills

A robust CLI wrapper for yt-dlp to download videos, playlists, and audio from YouTube and thousands of other sites. Supports format selection, quality control, metadata embedding, and cookie authentication.

General Utilities

time-checker

3891
from openclaw/skills

Check accurate current time, date, and timezone information for any location worldwide using time.is. Use when the user asks "what time is it in X", "current time in Y", or needs to verify timezone offsets.

General Utilities

pihole-ctl

3891
from openclaw/skills

Manage and monitor local Pi-hole instance. Query FTL database for statistics (blocked ads, top clients) and control service via CLI. Use when user asks "how many ads blocked", "pihole status", or "update gravity".

General Utilities

mermaid-architect

3891
from openclaw/skills

Generate beautiful, hand-drawn Mermaid diagrams with robust syntax (quoted labels, ELK layout). Use this skill when the user asks for "diagram", "flowchart", "sequence diagram", or "visualize this process".

General Utilities

memory-cache

3891
from openclaw/skills

High-performance temporary storage system using Redis. Supports namespaced keys (mema:*), TTL management, and session context caching. Use for: (1) Saving agent state, (2) Caching API results, (3) Sharing data between sub-agents.

General Utilities

mema

3891
from openclaw/skills

Mema's personal brain - SQLite metadata index for documents and Redis short-term context buffer. Use for organizing workspace knowledge paths and managing ephemeral session state.

General Utilities

file-organizer-skill

3891
from openclaw/skills

Organize files in directories by grouping them into folders based on their extensions or date. Includes Dry-Run, Recursive, and Undo capabilities.

General Utilities

edge-tts

3891
from openclaw/skills

Text-to-speech conversion using node-edge-tts npm package for generating audio from text. Supports multiple voices, languages, speed adjustment, pitch control, and subtitle generation. Use when: (1) User requests audio/voice output with the "tts" trigger or keyword. (2) Content needs to be spoken rather than read (multitasking, accessibility, driving, cooking). (3) User wants a specific voice, speed, pitch, or format for TTS output.

General Utilities

ocr-local

3891
from openclaw/skills

Extract text from images using Tesseract.js OCR (100% local, no API key required). Supports Chinese (simplified/traditional) and English.

General Utilities