🛠FFmpeg Guide for Compressing Files (Windows)
FFmpeg is a powerful command-line tool used to record, convert, and stream audio and video. In the context of Fab Academy, it is primarily used to compress high-quality videos into small, web-friendly files (ideally under 10MB) to keep repository sizes manageable.
Installation Steps
Step 1: Download the Binaries
- Navigate to the FFmpeg official site.
- Select the Windows Logo.
- Click on the link for Windows builds from gyan.dev.
- Download the file labeled
ffmpeg-release-essentials.zip.
Step 2: Extract and Organize
- Locate the downloaded
.zipfile and extract it. - Rename the resulting folder to
ffmpeg. - Move the folder to the root of your C: drive. The final path should look like:
C:\ffmpeg
Step 3: Add FFmpeg to System Path
To run FFmpeg from any terminal, you need to tell Windows where it lives:
- Search for "Edit the system environment variables" in your Windows search bar and open it.
- Click Environment Variables (bottom right).
- Under System Variables, find the one named
Pathand click Edit. - Click New and type:
C:\ffmpeg\bin - Click OK on all open windows.
To verify your installation, open a new Command Prompt (windows logo+cmd) and run:
ffmpeg -version
If you get an error saying "command not found," try restarting your terminal or your PC to ensure the new Path variable is recognized.
Compress Video (MP4)
This reduces file size while maintaining visibility:
In command prompt, navigate to the folder where your video is, then type the following:
ffmpeg -i input_video.mp4 -vcodec libx264 -crf 28 output_video.mp4
Convert Video to GIF
Useful for showing quick UI interactions or machine movements:
ffmpeg -i input.mp4 -vf "fps=10,scale=640:-1:flags=lanczos" output.gif
Remove Audio
Reduces file size further if sound isn't needed:
ffmpeg -i input.mp4 -an -vcodec copy output_no_audio.mp4
Using FFmpeg for Image Compression
High-resolution photos, like 5MB JPEGs from a phone, should be compressed to under 200-300KB for fast web loading.
Basic JPEG Compression
Reduce the quality level (on a scale of 1–31, where 1 is highest quality and 31 is lowest).
ffmpeg -i input.jpg -q:v 5 output.jpg
Resizing an Image
Most phone photos are 4000px+ wide. For a website, 1000px to 1200px is plenty.
ffmpeg -i input.jpg -vf scale=1000:-1 output_web.jpg
scale=1000:-1: Sets the width to 1000 pixels and keeps the height proportional.
Converting to WebP (Recommended)
WebP is the modern standard for web images. It provides much better compression than JPEG.
ffmpeg -i input.png -webp_quality 75 output.webp
webp_quality 75: 75-80 is the "sweet spot" for balancing sharpness and file size.
Batch Compression
If you have a folder full of .jpg files and want to compress them all at once to 1000px wide, run this command in your terminal:
for %i in (*.jpg) do ffmpeg -i "%i" -vf scale=1000:-1 "compressed_%i"