home / skills / benchflow-ai / skillsbench / ffmpeg-format-conversion

This skill helps convert media formats and codecs with FFmpeg, enabling fast container changes, quality control, and efficient transcoding.

npx playbooks add skill benchflow-ai/skillsbench --skill ffmpeg-format-conversion

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.7 KB
---
name: FFmpeg Format Conversion
description: Convert media files between formats - video containers, audio formats, and codec transcoding
---

# FFmpeg Format Conversion Skill

Convert media files between different formats and containers.

## When to Use

- Convert video containers (MP4, MKV, AVI, etc.)
- Convert audio formats (MP3, AAC, WAV, etc.)
- Transcode to different codecs
- Copy streams without re-encoding (fast)

## Basic Conversion

```bash
# Convert container format (re-encode)
ffmpeg -i input.avi output.mp4

# Copy streams without re-encoding (fast, no quality loss)
ffmpeg -i input.mp4 -c copy output.mkv

# Convert with specific codec
ffmpeg -i input.mp4 -c:v libx264 -c:a aac output.mp4
```

## Video Codec Conversion

```bash
# H.264
ffmpeg -i input.mp4 -c:v libx264 output.mp4

# H.265 (better compression)
ffmpeg -i input.mp4 -c:v libx265 output.mp4

# VP9 (web optimized)
ffmpeg -i input.mp4 -c:v libvpx-vp9 output.webm

# AV1 (modern codec)
ffmpeg -i input.mp4 -c:v libaom-av1 output.mp4
```

## Audio Format Conversion

```bash
# MP3
ffmpeg -i input.wav -acodec libmp3lame -q:a 2 output.mp3

# AAC
ffmpeg -i input.wav -c:a aac -b:a 192k output.m4a

# Opus (best quality/bitrate)
ffmpeg -i input.wav -c:a libopus -b:a 128k output.opus

# FLAC (lossless)
ffmpeg -i input.wav -c:a flac output.flac
```

## Quality Settings

```bash
# CRF (Constant Rate Factor) - lower is better quality
ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4

# Bitrate
ffmpeg -i input.mp4 -b:v 2M -b:a 192k output.mp4

# Two-pass encoding (best quality)
ffmpeg -i input.mp4 -c:v libx264 -b:v 2M -pass 1 -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 2M -pass 2 output.mp4
```

## Presets

```bash
# Encoding speed presets (faster = larger file)
ffmpeg -i input.mp4 -c:v libx264 -preset fast output.mp4
# Options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow

# Quality presets
ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 18 output.mp4
```

## Batch Conversion

```bash
# Convert all MKV to MP4
for f in *.mkv; do
  ffmpeg -i "$f" -c copy "${f%.mkv}.mp4"
done

# Convert with re-encoding
for f in *.avi; do
  ffmpeg -i "$f" -c:v libx264 -c:a aac "${f%.avi}.mp4"
done
```

## Common Codecs

### Video
- **H.264** (libx264) - Universal compatibility
- **H.265** (libx265) - Better compression
- **VP9** (libvpx-vp9) - Open standard
- **AV1** (libaom-av1) - Modern codec

### Audio
- **AAC** (aac) - Universal
- **MP3** (libmp3lame) - Legacy
- **Opus** (libopus) - Best quality/bitrate
- **FLAC** (flac) - Lossless

## Notes

- Use `-c copy` when possible for speed (no re-encoding)
- Re-encoding is slower but allows codec/quality changes
- CRF 18-23 is good quality range for H.264
- Preset affects encoding speed vs file size tradeoff

Overview

This skill converts media files across containers, audio formats, and codecs using FFmpeg best practices. It supports fast stream copying, full re-encoding with codec selection, and batch processing for multiple files. The goal is reliable, reproducible format conversion with control over quality and performance tradeoffs.

How this skill works

The skill builds FFmpeg commands to either copy streams (-c copy) or re-encode video and audio with chosen codecs (libx264, libx265, libvpx-vp9, libaom-av1, libmp3lame, aac, libopus, flac). It exposes options for CRF, bitrate, presets, and two-pass encoding to tune quality versus speed. Batch loops automate bulk conversions and preserve or change containers as required.

When to use it

  • Change container without re-encoding for fast, lossless conversion
  • Transcode video to a specific codec for device or web compatibility
  • Convert audio files between MP3, AAC, Opus, FLAC for distribution or archiving
  • Reduce file size with modern codecs (H.265, VP9, AV1) while balancing CPU cost
  • Batch-convert folders of media for library normalization or platform ingestion

Best practices

  • Use -c copy when only changing container to avoid quality loss and save time
  • Choose CRF for quality-based H.264/H.265 output (typical CRF 18–23) instead of fixed bitrate when quality matters
  • Select preset to tune encoding speed vs. compression (use slower presets for smaller files if CPU allows)
  • Use two-pass encoding for consistent bitrate-constrained targets when streaming or broadcast requirements exist
  • Test settings on short clips before processing large batches to validate quality and speed

Example use cases

  • Quickly remux MP4 to MKV without re-encoding for tool compatibility using -c copy
  • Transcode archival AVI files to H.264 MP4 with AAC audio for universal playback
  • Encode web-optimized VP9 or AV1 videos for lower bandwidth delivery to browsers
  • Convert WAV recordings to Opus or MP3 for efficient distribution with controlled bitrate
  • Batch-convert a folder of MKV movies to MP4 with libx264 and consistent CRF/preset settings

FAQ

When should I use -c copy instead of re-encoding?

Use -c copy when you only need to change the container and the existing codecs are already compatible with the target container; this is fastest and lossless.

How do I get smaller files without losing too much quality?

Use a modern codec (H.265, VP9, AV1) or lower CRF with a slower preset; test on samples to find the best quality/size tradeoff for your content.