
Compress Video
Compute FFmpeg 2-pass video bitrates from a target output size in MB using ffprobe duration and configurable audio kbps.
Overview
Compress-video is an agent skill for the Ship phase that calculates FFmpeg 2-pass video bitrates from a target file size in MB using ffprobe and a Python CLI.
Install
npx skills add https://github.com/gupsammy/claudest --skill compress-videoWhat is this skill?
- Python helper calc_bitrate.py outputs integer -b:v kbps on stdout for FFmpeg
- Uses ffprobe JSON for duration and stream/format introspection
- --target-mb required budget with optional --audio-kbps (default 128)
- stderr carries source info and budget breakdown for debugging passes
- Designed for 2-pass FFmpeg encoding workflows
- Default audio budget: 128 kbps
Adoption & trust: 1 installs on skills.sh; 253 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
What problem does it solve?
You have a length-known source video and a hard megabyte cap but no quick math for -b:v in a two-pass FFmpeg encode.
Who is it for?
Solo builders automating trailer or demo exports with FFmpeg who target exact upload limits.
Skip if: Users without ffprobe/ffmpeg installed or anyone needing one-click cloud transcoding without shell tools.
When should I use this skill?
User needs video bitrate for 2-pass FFmpeg encoding given input file and --target-mb (optional --audio-kbps).
What do I get? / Deliverables
You get an integer kbps video bitrate on stdout ready to plug into FFmpeg while stderr explains the size budget split.
- Integer kbps value for FFmpeg -b:v
- stderr diagnostic budget breakdown
Recommended Skills
Journey fit
Video size and bitrate budgeting is a shipping and performance concern before publishing demos, trailers, or course assets. The script optimizes encoded file weight (perf) rather than authoring creative cuts or hosting distribution copy.
How it compares
Use as a bitrate math helper ahead of raw FFmpeg CLI—not a replacement for HandBrake presets or hosted media APIs.
Common Questions / FAQ
Who is compress-video for?
Indie builders and content-focused developers who encode video locally with FFmpeg and want agent-assisted size targeting.
When should I use compress-video?
During Ship when tuning perf before release assets go live, and during Grow when recompressing course or marketing clips to platform size limits.
Is compress-video safe to install?
It runs ffprobe via subprocess on paths you provide; review the Security Audits panel on this page and avoid pointing it at untrusted files on shared machines.
SKILL.md
READMESKILL.md - Compress Video
#!/usr/bin/env python3 """ Calculate recommended video bitrate for 2-pass FFmpeg encoding. Usage: calc_bitrate.py <input_file> --target-mb <float> [--audio-kbps <int>] Output (stdout): integer kbps for use as -b:v value Diagnostics (stderr): source info and budget breakdown """ from __future__ import annotations import argparse import json import subprocess import sys def get_file_info(path: str) -> dict: result = subprocess.run( ["ffprobe", "-v", "quiet", "-print_format", "json", "-show_streams", "-show_format", path], capture_output=True, text=True, ) if result.returncode != 0: print(f"Error: ffprobe failed:\n{result.stderr}", file=sys.stderr) sys.exit(1) return json.loads(result.stdout) def main() -> None: parser = argparse.ArgumentParser( description="Calculate video bitrate for 2-pass FFmpeg encoding" ) parser.add_argument("input_file", help="Input video file path") parser.add_argument("--target-mb", type=float, required=True, help="Target output file size in MB") parser.add_argument("--audio-kbps", type=int, default=128, help="Audio bitrate budget in kbps (default: 128)") args = parser.parse_args() info = get_file_info(args.input_file) duration_s = float(info["format"].get("duration", 0)) if duration_s <= 0: print("Error: could not determine video duration", file=sys.stderr) sys.exit(1) # total_kbps = (target_mb * 8192) / duration_s # 1 MB = 8 Mbit = 8192 kbit total_kbps = (args.target_mb * 8192) / duration_s video_kbps = int(total_kbps - args.audio_kbps) current_mb = float(info["format"].get("size", 0)) / (1024 * 1024) print(f"Source: {current_mb:.1f} MB, {duration_s:.1f}s", file=sys.stderr) print( f"Budget: {args.target_mb} MB → {total_kbps:.0f} kbps total " f"→ {video_kbps} kbps video + {args.audio_kbps} kbps audio", file=sys.stderr, ) if video_kbps <= 0: print( f"Error: target {args.target_mb} MB is too small — only " f"{total_kbps:.0f} kbps total, which is less than the " f"{args.audio_kbps} kbps audio budget.", file=sys.stderr, ) sys.exit(1) # stdout: just the integer for clean shell capture # e.g.: VIDEO_KBPS=$(python3 calc_bitrate.py video.mp4 --target-mb 50) print(video_kbps) if __name__ == "__main__": main() --- name: compress-video description: > This skill should be used when the user asks to "compress this video", "reduce file size", "make this video smaller", "optimize for web", "shrink this video", "compress to under X MB", "reduce bitrate", "make it smaller without losing quality", "encode with H.265", or "re-encode this video". allowed-tools: - Bash(ffprobe:*) - Bash(ffmpeg:*) - AskUserQuestion --- # Video Compress Compress a video using quality-based (CRF) or size-based (2-pass) encoding. ## Process ### 1. Obtain input file If the user did not provide a file path, ask for it with AskUserQuestion before proceeding. ### 2. Probe the source ```bash ffprobe -v quiet -print_format json -show_streams -show_format "$INPUT" ``` Extract: duration (seconds), file size (bytes), existing video codec, audio bitrate. If ffprobe fails (file not found, not a valid video), report the error and stop — do not attempt encoding. ### 3. Determine mode from user intent - **CRF mode** (quality-based): user says "without losing quality", "good quality", "make it smaller", or gives no size target - **2-pass mode** (size-based): user specifies a target ("under 50MB", "around 20MB", "fit on X") ### 4. Choose codec H.264 is the safe default: universally device-compatible and fast to encode. Use H.265 only when the size reduction justifies the slower encode time and narrower device support. - **H.265 / libx265**: target is ≤50% of original size, or user asks for "maximum compr