A powerful bash script for compressing video files and removing metadata using FFmpeg. Perfect for preparing videos for cloud upload with reduced file sizes and enhanced privacy.
- Video Compression: Reduce file sizes without noticeable quality loss using H.264 encoding
- Metadata Removal: Strip all metadata for privacy (location, device info, timestamps)
- Flexible Modes: Compress only, remove metadata only, or do both
- Batch Processing: Handle multiple files at once
- Quality Control: Adjustable compression settings
- File Size Reporting: Shows compression percentage after processing
- Safe Processing: Creates new files, preserves originals by default
- Linux/Unix system
- FFmpeg installed (
sudo apt install ffmpegon Ubuntu/Debian) - Bash shell
Make the script available to all users from anywhere:
# Download or create the script
chmod +x video_process.sh
# Install system-wide (requires sudo)
sudo cp video_process.sh /usr/local/bin/video_process
# Test installation
video_process --helpInstall for current user only:
# Create personal bin directory
mkdir -p ~/bin
# Install script
cp video_process.sh ~/bin/video_process
chmod +x ~/bin/video_process
# Add to PATH (if not already done)
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Test installation
video_process --helpMany distributions already include ~/.local/bin in PATH:
mkdir -p ~/.local/bin
cp video_process.sh ~/.local/bin/video_process
chmod +x ~/.local/bin/video_process# Compress and remove metadata (default)
video_process input.mp4
# Process multiple files
video_process *.mp4 *.mov *.avi| Option | Description | Example |
|---|---|---|
-c, --compress-only |
Only compress video (keep metadata) | video_process -c video.mp4 |
-m, --metadata-only |
Only remove metadata (no compression) | video_process -m video.mp4 |
-q, --quality CRF |
Set quality (CRF value, default: 22) | video_process -q 18 video.mp4 |
-p, --preset PRESET |
Set encoding preset (default: slow) | video_process -p fast video.mp4 |
-o, --output-dir DIR |
Output directory (default: processed) | video_process -o compressed *.mp4 |
-r, --remove-original |
Remove original files after processing | video_process -r video.mp4 |
-h, --help |
Show help message | video_process --help |
| CRF | Quality | File Size | Use Case |
|---|---|---|---|
| 18-20 | Excellent | Large | Archival, professional |
| 22-24 | High | Medium | General use, cloud upload |
| 26-28 | Good | Small | Web streaming, mobile |
| Preset | Speed | Efficiency | Use Case |
|---|---|---|---|
| ultrafast | Fastest | Poor | Real-time encoding |
| fast | Fast | Good | Quick processing |
| slow | Slow | Best | Best compression (default) |
| veryslow | Slowest | Excellent | Maximum efficiency |
# Default settings - good balance of quality and size
video_process vacation_video.mp4
# Higher compression for limited bandwidth
video_process -q 26 -p fast large_video.mov# Remove metadata only (no compression)
video_process -m sensitive_video.mp4
# Compress and remove all metadata
video_process -o clean_videos *.mp4# Process all MP4 files in current directory
video_process *.mp4
# Custom output directory and remove originals
video_process -o compressed -r *.mov *.avi
# High quality compression for multiple files
video_process -q 20 -p slow *.mkvThe script creates processed files in the specified output directory (default: processed/) with the suffix _processed added to the filename.
Example:
- Input:
my_video.mp4 - Output:
processed/my_video_processed.mp4
- Re-encodes video using H.264 codec for better compression
- Preserves original audio quality (no re-encoding)
- Maintains metadata information
- Strips all metadata tags (location, device info, timestamps)
- Copies video and audio streams without re-encoding
- Fastest processing mode
- Compresses video for smaller file size
- Removes all metadata for privacy
- Most comprehensive processing
# Ubuntu/Debian
sudo apt update && sudo apt install ffmpeg
# CentOS/RHEL/Fedora
sudo dnf install ffmpeg
# Arch Linux
sudo pacman -S ffmpeg# Make script executable
chmod +x video_process.sh
# For system-wide installation
sudo cp video_process.sh /usr/local/bin/video_process# Check if directory is in PATH
echo $PATH
# Add to PATH permanently
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc- Video Codec: H.264 (libx264) for maximum compatibility
- Audio Handling: Stream copy (no quality loss)
- Metadata Removal: Uses FFmpeg's
-map_metadata -1flag - Quality Control: CRF (Constant Rate Factor) for consistent quality
- File Safety: Creates new files, preserves originals by default
Feel free to submit issues, feature requests, or improvements. The script is designed to be simple, reliable, and user-friendly.
This script is provided as-is for educational and practical use. Modify and distribute freely.