transcode
Convert videos between formats, codecs, and containers for universal compatibility.
Overview
The transcode command converts videos from one format/codec to another, ensuring compatibility across platforms, devices, and use cases. Whether you're converting old AVI files to modern MP4, preparing videos for web delivery, or migrating to more efficient codecs, transcode handles it intelligently.
Key Features:
- 🔄 Format conversion (MP4, WebM, MKV, AVI)
- 🎬 Codec migration (H.264, H.265, VP9, AV1)
- 📦 Container remuxing (fast, lossless)
- 🌐 Platform-optimized presets
- 📁 Batch folder processing
- ⚡ Smart codec defaults per format
Common Use Cases:
- Converting legacy formats (AVI, WMV) to modern MP4
- Preparing videos for web (MP4 with H.264)
- Creating HTML5-compatible WebM files
- Migrating to efficient codecs (H.265, AV1)
- Fixing incompatible video formats
- Container changes without re-encoding
Remux vs Re-encode: If only the container changes (e.g., MP4 → MKV with same codec), transcode uses fast remuxing (instant, lossless). Different codecs require re-encoding (slower, slight quality loss).
Quality Loss: Transcoding between lossy codecs (H.264 → H.265) involves re-compression. For maximum quality, always work from original/uncompressed sources.
Usage
Options
| Option | Alias | Type | Default | Description |
|---|---|---|---|---|
--output | -o | string | Auto | Output file path |
--format | -f | string | mp4 | Output format: mp4, webm, mkv, avi |
--codec | -c | string | Auto | Video codec: h264, h265, vp9, av1 |
--audio-codec | -ac | string | Auto | Audio codec: aac, mp3, opus |
--bitrate | -b | string | Video bitrate (e.g., 2000k, 5M) | |
--audio-bitrate | -ab | string | 128k | Audio bitrate |
--crf | number | 23 | CRF value (if no bitrate specified) | |
--dry-run | boolean | false | Preview without executing | |
--verbose | -v | boolean | false | Show detailed FFmpeg output |
Flag Details
--format - Output Format
Specify the output container format.
Available Formats:
MP4 (.mp4) - Universal
- Compatibility: All devices, browsers, platforms
- Best Codecs: H.264, H.265 (HEVC)
- Audio: AAC, MP3
- Use When: Maximum compatibility needed
- Best For: General distribution, mobile devices, web, social media
WebM (.webm) - Open Web Standard
- Compatibility: All modern browsers, limited device support
- Best Codecs: VP9, VP8, AV1
- Audio: Opus, Vorbis
- Use When: HTML5 video, YouTube, open-source projects
- Best For: Web streaming, progressive web apps
MKV (.mkv) - Matroska
- Compatibility: Desktop players, advanced features
- Best Codecs: Any codec (highly flexible)
- Audio: Multiple audio tracks, subtitles
- Use When: Need advanced features (chapters, multiple tracks)
- Best For: High-quality archival, media centers, anime
AVI (.avi) - Legacy Format
- Compatibility: Universal, older systems
- Best Codecs: H.264, MPEG-4, DivX
- Audio: MP3, PCM
- Use When: Legacy system compatibility
- Best For: Older editing software, retro compatibility
Learn More:
--codec - Video Codec
Select the video encoding codec.
H.264 (AVC) - Universal Standard
- Compatibility: ✅✅✅ All devices
- Encoding Speed: Fast
- Compression: Good
- File Size: Baseline reference
- Use When: Need maximum compatibility
- Patent Status: Free for end users
H.265 (HEVC) - High Efficiency
- Compatibility: Modern devices (2016+)
- Encoding Speed: Slow (2-3x longer)
- Compression: Excellent (40-50% smaller than H.264)
- File Size: Much smaller
- Use When: 4K video, storage critical, modern distribution
- Patent Status: Licensing complexities
VP9 - Google's Open Codec
- Compatibility: Web browsers, YouTube
- Encoding Speed: Very slow
- Compression: Excellent (similar to H.265)
- File Size: Small
- Use When: WebM format, open-source requirements
- Patent Status: Royalty-free
AV1 - Next Generation
- Compatibility: Latest browsers/devices (2020+)
- Encoding Speed: Extremely slow
- Compression: Best (20-30% better than H.265)
- File Size: Smallest
- Use When: Future-proofing, streaming platforms
- Patent Status: Open, royalty-free
Auto-Selection: If not specified, codec is chosen based on output format:
- MP4 → H.264
- WebM → VP9
- MKV → H.264
- AVI → H.264
Learn More:
--audio-codec - Audio Codec
Select the audio encoding codec.
AAC - Advanced Audio Coding
- Compatibility: Universal
- Quality: Excellent
- File Size: Efficient
- Best For: MP4 videos, general use
- Bitrate: 128k standard, 192k high quality
MP3 - MPEG Audio Layer 3
- Compatibility: Universal (older than AAC)
- Quality: Good
- File Size: Moderate
- Best For: Legacy compatibility, AVI format
- Bitrate: 128k standard, 192k high quality
Opus - Modern Open Codec
- Compatibility: Modern browsers, WebM
- Quality: Best (better than AAC at lower bitrates)
- File Size: Very efficient
- Best For: WebM videos, streaming
- Bitrate: 96k excellent, 128k transparent
Auto-Selection:
- MP4/MKV → AAC
- WebM → Opus
- AVI → MP3
--bitrate - Video Bitrate
Set target video bitrate (alternative to CRF-based quality).
Format: Number + unit
k= kilobits per second (e.g.,2000k= 2 Mbps)M= megabits per second (e.g.,5M= 5 Mbps)
Recommended Bitrates:
| Resolution | H.264 | H.265 | Purpose |
|---|---|---|---|
| 480p | 1-2M | 0.7-1.5M | Mobile, low bandwidth |
| 720p | 2.5-5M | 1.5-3M | HD streaming |
| 1080p | 5-8M | 3-5M | Full HD |
| 1440p | 10-15M | 6-10M | QHD |
| 4K | 20-40M | 15-25M | Ultra HD |
CRF vs Bitrate:
- CRF: Better quality distribution, variable file size
- Bitrate: Predictable file size, may waste bits on simple scenes
--crf - Constant Rate Factor
Control encoding quality (used when bitrate not specified).
Range: 0-51, lower = better quality
15-18- Near-lossless (large files)19-23- High quality ← 23 is default24-28- Good quality (smaller files)29+- Lower quality (compression artifacts)
Codec-Specific Recommendations:
- H.264: CRF 18-23 (23 default)
- H.265: CRF 22-28 (can go higher due to better compression)
- VP9: CRF 23-31
- AV1: CRF 20-30
--audio-bitrate - Audio Bitrate
Set audio quality/bitrate.
Common Values:
96k- Acceptable for speech128k- Standard quality ← default192k- High quality for music256k- Professional quality320k- Maximum quality
Impact on File Size: Audio typically 5-10% of total file size at standard settings.
Format Support
MP4 (.mp4)
- Compatibility: Universal (all devices)
- Best codecs: H.264, H.265
- Audio: AAC, MP3
- Use case: General distribution, web, mobile
WebM (.webm)
- Compatibility: Modern web browsers
- Best codecs: VP9, VP8
- Audio: Opus, Vorbis
- Use case: HTML5 video, web streaming
MKV (.mkv)
- Compatibility: Desktop players, advanced users
- Best codecs: Any (highly flexible)
- Audio: Multiple tracks supported
- Use case: High-quality archival, multiple audio/subtitle tracks
AVI (.avi)
- Compatibility: Legacy systems, wide software support
- Best codecs: H.264, MPEG-4
- Audio: MP3, AAC
- Use case: Legacy compatibility, older editing software
Codec Mapping
The plugin automatically selects appropriate codecs for each format:
| Format | Default Video Codec | Default Audio Codec |
|---|---|---|
| MP4 | H.264 | AAC |
| WebM | VP9 | Opus |
| MKV | H.264 | AAC |
| AVI | H.264 | MP3 |
Examples
Basic Format Conversion
Specify Output Location
Codec Selection
Audio Codec Control
Bitrate Control
CRF-Based Quality
# Use CRF for quality-based encoding (recommended)
mediaproc video transcode input.avi -f mp4 --crf 23
# High quality
mediaproc video transcode input.avi -f mp4 --crf 18
# Smaller file size
mediaproc video transcode input.avi -f mp4 --crf 28
HTML5 Web Video
# Create WebM for modern browsers
mediaproc video transcode video.mp4 -f webm -c vp9 --audio-codec opus
# Create MP4 fallback for older browsers
mediaproc video transcode video.mp4 -f mp4 -c h264 --audio-codec aac
# Use in HTML:
# <video>
# <source src="video.webm" type="video/webm">
# <source src="video.mp4" type="video/mp4">
# </video>
Codec Upgrade
# Upgrade old H.264 to H.265 for better compression
mediaproc video transcode old-video.mp4 -c h265 -o new-video.mp4
# Upgrade to VP9 for web
mediaproc video transcode video.mp4 -c vp9 -f webm --crf 20
Dry Run Preview
# Preview transcoding command
mediaproc video transcode input.avi -f mp4 --dry-run
Output:
[DRY RUN] Would execute:
ffmpeg -i input.avi -c:v libx264 -crf 23 -c:a aac -b:a 128k input.mp4
Input: input.avi (Format: AVI, Codec: MPEG-4)
Output: input.mp4 (Format: MP4, Codec: H.264)
Batch Transcoding
# Create WebM versions of all MP4 files
for file in *.mp4; do
mediaproc video transcode "$file" -f webm -o webm/
done
# Batch convert with specific codec
for file in *.mov; do
mediaproc video transcode "$file" -f mp4 -c h265 -o h265/
done
Folder Processing
# Convert entire folder to WebM
mediaproc video transcode videos/ -f webm -c vp9 -o output/
# Batch convert with quality control
mediaproc video transcode source/ -f mp4 -c h265 --crf 20 -o output/
Use Cases
Legacy Format Migration
Convert old video formats to modern standards:
# AVI to MP4
mediaproc video transcode old-videos/*.avi -f mp4 -o mp4/
# MOV to MP4
mediaproc video transcode *.mov -f mp4
# FLV to MP4
mediaproc video transcode flash-video.flv -f mp4
Web Platform Optimization
Create optimized videos for web delivery:
# YouTube (MP4 with H.264)
mediaproc video transcode video.avi -f mp4 -c h264 --crf 18
# Vimeo (MP4 or WebM)
mediaproc video transcode video.avi -f mp4 --bitrate 5M
# Self-hosted website (WebM + MP4 fallback)
mediaproc video transcode video.avi -f webm -c vp9 -o video.webm
mediaproc video transcode video.avi -f mp4 -c h264 -o video.mp4
Device Compatibility
Ensure playback on specific devices:
# Apple devices (MP4 with H.264)
mediaproc video transcode video.mkv -f mp4 -c h264 --audio-codec aac
# Android devices (MP4)
mediaproc video transcode video.avi -f mp4 -c h264
# Smart TVs (MP4, lower bitrate)
mediaproc video transcode 4k-video.mp4 --bitrate 8M -o tv-compatible.mp4
Streaming Preparation
Prepare videos for streaming services:
# High-quality stream
mediaproc video transcode source.avi -f mp4 --bitrate 5M --audio-bitrate 192k
# Medium-quality stream
mediaproc video transcode source.avi -f mp4 --bitrate 2M --audio-bitrate 128k
# Low-quality stream
mediaproc video transcode source.avi -f mp4 --bitrate 1M --audio-bitrate 96k
Archive Conversion
Convert to efficient archival formats:
# H.265 in MKV for space-efficient archival
mediaproc video transcode video.avi -f mkv -c h265 --crf 20
# VP9 in WebM
mediaproc video transcode video.mp4 -f webm -c vp9 --crf 20
Social Media Formatting
# Instagram (MP4 with AAC)
mediaproc video transcode video.avi -f mp4 -c h264 --audio-codec aac
# Twitter (MP4, specific bitrate)
mediaproc video transcode video.avi -f mp4 --bitrate 2M
# Facebook (MP4 H.264)
mediaproc video transcode video.avi -f mp4 -c h264 --crf 23
Technical Details
Container vs Codec
Container (format): The file wrapper that holds video/audio streams
- MP4, WebM, MKV, AVI
Codec: The algorithm that compresses video/audio data
- H.264, H.265, VP9, AAC, Opus
Example: MP4 container can hold H.264 or H.265 video + AAC audio
Transcoding vs Remuxing
Transcoding: Re-encode video (slow, quality loss)
# Changes codec, re-encodes video
mediaproc video transcode input.avi -f mp4 -c h264
Remuxing: Change container without re-encoding (fast, lossless)
# FFmpeg direct command for remuxing:
ffmpeg -i input.mkv -c copy output.mp4
The plugin always transcodes to ensure compatibility.
Codec Selection Logic
When codec is not specified, automatic selection:
- MP4 format: H.264 video + AAC audio
- WebM format: VP9 video + Opus audio
- MKV format: H.264 video + AAC audio
- AVI format: H.264 video + MP3 audio
Quality Control
CRF mode (default):
- Quality-based encoding
- Variable bitrate
- Consistent quality
- Recommended for most use cases
Bitrate mode:
- Target specific size
- Constant or average bitrate
- Predictable file sizes
- Use for streaming constraints
Performance Considerations
Encoding Speed
Relative encoding speeds (H.264 baseline = 1x):
- H.264: 1x (fast)
- H.265: 2-3x slower
- VP9: 3-5x slower
- AV1: 10-20x slower (not recommended for bulk processing)
When to Use Each Codec
H.264 (libx264):
- ✅ Universal compatibility needed
- ✅ Fast encoding required
- ✅ Live streaming
- ❌ Not ideal for 4K or UHD
H.265 (libx265):
- ✅ 4K/UHD content
- ✅ Storage space critical
- ✅ Modern devices (2016+)
- ❌ Slow encoding
- ❌ Limited older device support
VP9 (libvpx-vp9):
- ✅ Web delivery
- ✅ Open-source requirement
- ✅ YouTube compatibility
- ❌ Very slow encoding
- ❌ Limited hardware acceleration
AV1 (libaom-av1):
- ✅ Best compression (30% better than H.265)
- ✅ Future-proof
- ❌ Extremely slow (10-20x slower than H.264)
- ❌ Limited device support currently
Error Handling
Common Errors
FFmpeg not found:
Error: FFmpeg is not installed
Install: brew install ffmpeg (macOS) or apt install ffmpeg (Ubuntu)
Unsupported codec:
Error: Codec 'av1' not available in your FFmpeg build
Available codecs: h264, h265, vp9
Check: ffmpeg -codecs
Invalid format:
Error: Unsupported output format 'xyz'
Supported: mp4, webm, mkv, avi
Incompatible codec/format combination:
Warning: VP9 codec works best with WebM format
Recommended: -f webm -c vp9
Best Practices
- Choose the right format: MP4 for compatibility, WebM for web
- Use CRF for quality: Better than fixed bitrate for most cases
- Test codec support: Verify target devices support chosen codec
- Keep source files: Never overwrite originals
- Use dry-run: Preview commands before batch processing
- Consider encoding time: H.264 is much faster than H.265/VP9
- Match audio codec: AAC for MP4, Opus for WebM
- Verify output: Always test transcoded videos play correctly
Troubleshooting
Output File Won't Play
- Check device/player codec support
- Try H.264 (most compatible):
-c h264 - Use standard container:
-f mp4 - Verify with:
ffprobe output.mp4
Poor Quality Output
- Increase CRF (lower number):
--crf 18 - Use higher bitrate:
--bitrate 5M - Choose better codec:
-c h265 - Check source quality (can't improve bad source)
Encoding Too Slow
- Use H.264 instead of H.265/VP9:
-c h264 - Reduce resolution first:
mediaproc video resize input.mp4 --scale 1080p - Use hardware acceleration (FFmpeg directly)
- Process fewer files in parallel
File Size Too Large
- Lower CRF:
--crf 28 - Use efficient codec:
-c h265 - Reduce bitrate:
--bitrate 2M - Compress after transcoding:
mediaproc video compress output.mp4
Audio Sync Issues
- Check source file for issues
- Use verbose mode:
-v - Try different audio codec:
--audio-codec aac - Report FFmpeg errors from verbose output
Advanced Examples
Multi-Format Web Delivery
#!/bin/bash
# Create multiple formats for HTML5 video
input="source.avi"
output_name="video"
# WebM for modern browsers
mediaproc video transcode "$input" -f webm -c vp9 --crf 20 -o "${output_name}.webm"
# MP4 for older browsers
mediaproc video transcode "$input" -f mp4 -c h264 --crf 23 -o "${output_name}.mp4"
echo "Use in HTML:"
echo '<video controls>'
echo " <source src=\"${output_name}.webm\" type=\"video/webm\">"
echo " <source src=\"${output_name}.mp4\" type=\"video/mp4\">"
echo '</video>'
Adaptive Bitrate Ladder
#!/bin/bash
# Create multiple quality levels for adaptive streaming
input="source.mp4"
# 1080p high quality
mediaproc video transcode "$input" --bitrate 5M -o "1080p.mp4"
# 720p medium quality
mediaproc video transcode "$input" --bitrate 2.5M -o "720p.mp4"
# 480p low quality
mediaproc video transcode "$input" --bitrate 1M -o "480p.mp4"
Codec Comparison Test
#!/bin/bash
# Compare output of different codecs
input="test-video.mp4"
# H.264
mediaproc video transcode "$input" -c h264 --crf 23 -o "test-h264.mp4"
# H.265
mediaproc video transcode "$input" -c h265 --crf 23 -o "test-h265.mp4"
# VP9
mediaproc video transcode "$input" -c vp9 --crf 23 -o "test-vp9.webm"
# Compare sizes
ls -lh test-*.{mp4,webm}
Archive Conversion Pipeline
#!/bin/bash
# Convert old format archive to efficient modern format
for file in archive/*.{avi,mov,flv}; do
filename=$(basename "$file")
name="${filename%.*}"
echo "Converting: $filename"
mediaproc video transcode "$file" \
-f mkv \
-c h265 \
--crf 20 \
-o "converted/$name.mkv" \
-v
# Log file sizes
original_size=$(du -h "$file" | cut -f1)
new_size=$(du -h "converted/$name.mkv" | cut -f1)
echo "$filename: $original_size -> $new_size" >> conversion_log.txt
done
Related Commands
- compress - Reduce file size after transcoding
- resize - Change resolution during transcoding
- extract-audio - Extract audio in different formats