Video Plugin

Professional video processing powered by FFmpeg. The video plugin provides essential commands for compressing, converting, editing, and extracting content from video files.

Overview

The MediaProc video plugin delivers industry-standard video processing capabilities through 6 carefully selected commands that cover 90% of common video manipulation tasks. Built on FFmpeg, it provides professional-grade results with an intuitive command-line interface.

Key Features

  • Compression - Reduce file size with CRF-based quality control and 4 quality presets
  • Transcoding - Convert between formats and codecs (MP4, WebM, MKV, H.264, H.265, VP9, AV1)
  • Trimming - Cut video segments with precise frame-accurate timing plus fade effects
  • Resizing - Scale resolution from 360p to 8K with advanced codec support
  • Merging - Concatenate multiple videos with transitions and audio normalization
  • Extraction - Pull audio tracks, image frames, and thumbnails
  • Folder Support - Process entire directories of videos automatically
  • Hardware Acceleration - GPU-accelerated encoding for faster processing
  • Advanced Effects - Rotate, flip, crop, deinterlace, and adjust playback speed

Requirements

The video plugin requires FFmpeg to be installed on your system:

macOS:

$ brew install ffmpeg

Ubuntu/Debian:

$ sudo apt update && sudo apt install ffmpeg

Windows:

$ choco install ffmpeg

Verify installation:

Terminal
$ ffmpeg -version
ffmpeg version 6.0
$ ffprobe -version
ffprobe version 6.0

Installation

To install the Video plugin:

Terminal
$ npm install -g @mediaproc/video

Commands

Quick Start

# Compress a video with high quality
mediaproc video compress input.mp4 -q high

# Compress entire folder
mediaproc video compress videos/ -q medium -o compressed/

# Convert to different format
mediaproc video transcode input.avi -f mp4

# Trim a segment with fade effects
mediaproc video trim input.mp4 --start 00:01:00 --end 00:02:30 --fade-in 1 --fade-out 1

# Resize to 720p with GPU acceleration
mediaproc video resize input.mp4 -s 720p --hw-accel

# Resize to 8K
mediaproc video resize input.mp4 -s 4320p -c h265

# Merge videos with fade transition
mediaproc video merge video1.mp4 video2.mp4 --transition fade

# Extract audio
mediaproc video extract-audio input.mp4 --format mp3

# Rotate and flip video
mediaproc video resize input.mp4 -s 1080p --rotate 90 --flip horizontal

Advanced Features

Folder Processing

Process entire directories of videos with a single command:

# Compress all videos in folder
mediaproc video compress videos/ -q high -o output/

# Resize all videos to 1080p
mediaproc video resize raw-footage/ -s 1080p -o processed/

# Trim all videos
mediaproc video trim clips/ -s 5 -d 30 -o trimmed/

Hardware Acceleration

Enable GPU encoding for 3-5x faster processing:

# GPU-accelerated resize
mediaproc video resize 8k-video.mp4 -s 2160p --hw-accel

# GPU-accelerated compression
mediaproc video compress large-file.mp4 -q high --hw-accel

Quality Presets

Four comprehensive quality levels for different use cases:

# Low - Maximum compression (CRF 28)
mediaproc video compress video.mp4 -q low

# Medium - Balanced (CRF 23) - Default
mediaproc video compress video.mp4 -q medium

# High - Near lossless (CRF 20)
mediaproc video compress video.mp4 -q high

# Extreme - Visually lossless (CRF 18)
mediaproc video compress video.mp4 -q extreme

Optimization Targets

Optimize compression for specific platforms:

# Web delivery
mediaproc video compress video.mp4 --optimize-for web

# Streaming platforms
mediaproc video compress video.mp4 --optimize-for streaming

# Mobile devices
mediaproc video compress video.mp4 --optimize-for mobile --resize 720p

# Long-term archive
mediaproc video compress video.mp4 --optimize-for archive -c h265

Advanced Effects

# Fade in and out
mediaproc video trim video.mp4 -s 0 -d 60 --fade-in 2 --fade-out 3

# Slow motion (50% speed)
mediaproc video trim video.mp4 -s 10 -d 30 --speed 0.5

# Fast forward (2x speed)
mediaproc video trim video.mp4 -s 10 -d 30 --speed 2.0

# Adjust audio volume
mediaproc video trim video.mp4 -s 0 -e end --volume 1.5

# Remove audio
mediaproc video trim video.mp4 -s 10 -d 30 --no-audio

Video Transformations

# Rotate 90 degrees
mediaproc video resize video.mp4 -s 1080p --rotate 90

# Flip horizontal
mediaproc video resize video.mp4 -s 1080p --flip horizontal

# Crop to 16:9
mediaproc video resize video.mp4 -s 1080p --crop 16:9

# Deinterlace old footage
mediaproc video resize old-video.avi -s 720p --deinterlace

Two-Pass Encoding

Achieve optimal quality at target bitrate:

# Two-pass compression
mediaproc video compress video.mp4 --two-pass -b 5M

# Two-pass resize
mediaproc video resize video.mp4 -s 1080p --two-pass

Common Workflows

Prepare Video for Web

# Step 1: Resize to 1080p
mediaproc video resize 4k-video.mp4 --scale 1080p

# Step 2: Compress for web delivery
mediaproc video compress 4k-video_1920x1080.mp4 -q medium

# Step 3: Convert to WebM for HTML5 video
mediaproc video transcode 4k-video_1920x1080_compressed.mp4 -f webm --codec vp9

Create Social Media Clips

# Extract 30-second highlight
mediaproc video trim long-video.mp4 --start 00:02:15 --duration 30 -o highlight.mp4

# Resize for Instagram (1080x1080)
mediaproc video resize highlight.mp4 -w 1080 -h 1080 -o highlight-square.mp4

# Compress to reduce file size
mediaproc video compress highlight-square.mp4 -q medium

Batch Process Videos

# Compress all MP4 files
for file in *.mp4; do
  mediaproc video compress "$file" -q medium
done

# Convert all AVI to MP4
for file in *.avi; do
  mediaproc video transcode "$file" -f mp4 -o "${file%.avi}.mp4"
done

Format Support

Video Formats

  • MP4 (.mp4) - Universal compatibility, recommended for most use cases
  • WebM (.webm) - Web-optimized, HTML5 video tag support
  • MKV (.mkv) - Feature-rich, supports multiple audio/subtitle tracks
  • AVI (.avi) - Legacy format, wide software support
  • MOV (.mov) - QuickTime format, macOS native
  • FLV (.flv) - Flash video (legacy)

Video Codecs

  • H.264 (libx264) - Universal compatibility, fast encoding
  • H.265 (libx265) - 50% better compression than H.264, slower encoding
  • VP9 (libvpx-vp9) - Open-source, used with WebM format
  • AV1 (libaom-av1) - Next-gen codec, best compression (very slow)

Audio Codecs

  • AAC - Universal, recommended for MP4
  • MP3 - Legacy, wide compatibility
  • Opus - Modern, efficient for low bitrates
  • WAV - Lossless, large file size

Quality Settings

CRF (Constant Rate Factor)

Lower CRF = better quality, larger file:

  • 0-17: Visually lossless (archival)
  • 18-23: High quality (recommended)
  • 23-28: Good quality (distribution)
  • 28-51: Lower quality (streaming)

Presets

  • low: CRF 28 - Smaller files, acceptable quality
  • medium: CRF 23 - Balanced (default)
  • high: CRF 18 - Larger files, excellent quality

Performance Tips

  1. Use fast trim mode (--fast) for quick cuts without re-encoding
  2. Choose the right codec: H.264 for speed, H.265 for size
  3. Avoid unnecessary re-encoding when merging same-format videos
  4. Use preset scales (720p, 1080p) instead of custom dimensions
  5. Test with --dry-run before processing large batches

Global Options

All video commands support:

  • -o, --output <path> - Specify output file/directory
  • --dry-run - Preview command without executing
  • -v, --verbose - Show detailed FFmpeg output
  • --help - Display command-specific help

Technical Details

Video Processing Pipeline

  1. Analysis: FFprobe extracts video metadata (duration, resolution, codec, bitrate)
  2. Processing: FFmpeg applies transformations based on command options
  3. Output: Encoded video written to specified output path
  4. Validation: Output file verified and statistics displayed

Encoding Modes

CRF Mode (Constant Rate Factor):

  • Variable bitrate based on video complexity
  • Consistent quality throughout
  • Recommended for most use cases

Bitrate Mode (ABR - Average Bitrate):

  • Fixed average bitrate target
  • Predictable file sizes
  • Used for streaming constraints

Fast vs Accurate Trimming

Fast Mode (--fast):

  • Stream copy (no re-encode)
  • Very quick processing
  • May have slight inaccuracies at cut points

Accurate Mode (default):

  • Re-encodes video
  • Frame-perfect cuts
  • Slower but precise

Error Handling

The plugin provides clear error messages for common issues:

  • FFmpeg not installed: Instructions for installation
  • Invalid input file: File path verification
  • Unsupported format: List of supported formats
  • Out of range times: Time validation against video duration
  • Insufficient disk space: Storage requirement checks

Troubleshooting

FFmpeg Not Found

# Check if FFmpeg is installed
ffmpeg -version

# Install on macOS
brew install ffmpeg

# Install on Ubuntu
sudo apt install ffmpeg

Codec Not Supported

Some codecs require specific FFmpeg builds:

# Check available codecs
ffmpeg -codecs | grep h265
ffmpeg -codecs | grep vp9

Processing Too Slow

  • Use H.264 instead of H.265 or VP9
  • Lower CRF value for faster encoding
  • Use --fast mode for trimming
  • Consider reducing resolution first

Large Output Files

  • Increase CRF value (28 instead of 23)
  • Use more efficient codec (H.265 instead of H.264)
  • Reduce resolution before compressing
  • Lower audio bitrate

Best Practices

  1. Always test with --dry-run before batch processing
  2. Keep originals - never overwrite source files
  3. Use appropriate quality - don't over-compress
  4. Choose the right format - MP4 for universal compatibility
  5. Maintain aspect ratios - avoid distortion
  6. Check output - verify results before deleting inputs

Advanced Usage

Custom FFmpeg Options

While the plugin covers common use cases, you can use FFmpeg directly for advanced scenarios:

# The plugin generates commands like:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac output.mp4

# Use --verbose to see exact FFmpeg commands
mediaproc video compress input.mp4 --verbose

Chaining Operations

# Resize, then compress
mediaproc video resize large.mp4 --scale 1080p
mediaproc video compress large_1920x1080.mp4 -q medium

# Trim multiple segments and merge
mediaproc video trim video.mp4 --start 0:30 --end 1:00 -o clip1.mp4
mediaproc video trim video.mp4 --start 2:00 --end 2:30 -o clip2.mp4
mediaproc video merge clip1.mp4 clip2.mp4 -o highlights.mp4

Support

Found an issue? Help us improve this page.

Edit on GitHub →