FFmpeg is a free, open-source program for video and audio. It converts, compresses, trims, pulls the audio out of a video, makes GIFs and handles most other video and audio jobs, each with a single command.
What Is FFmpeg
FFmpeg is a set of open-source tools and libraries for working with audio and video. The official home page describes it as:
A complete, cross-platform solution to record, convert and stream audio and video.
Main features:
- Free and open-source (LGPL or GPL)
- Runs on Windows, macOS, Linux, BSD and more
- Used from the command line. It has no graphical interface, which makes it easy to script and automate.
- Supports hundreds of codecs and containers
- Used behind the scenes by YouTube, Netflix, VLC and HandBrake
Many video programs, such as VLC, HandBrake, OBS and Adobe Premiere, use FFmpeg’s libraries (libav*, the parts other programs build in) internally.
Codec vs. Container (Critical Background Knowledge)
These are the two terms people mix up most often when they start with FFmpeg.
| Concept | Description | Examples |
|---|---|---|
| Container (file format) | The “box” that holds the video, audio and subtitles. You can usually tell it from the file extension. | .mp4, .mkv, .avi, .mov, .webm |
| Codec (encoding method) | The method used to compress the video or audio, and to decompress it for playback. | H.264, H.265, AV1, AAC, MP3, Opus |
Common combinations:
| Filename | Container | Video Codec | Audio Codec |
|---|---|---|---|
video.mp4 |
MP4 | H.264 | AAC |
video.mkv |
Matroska | H.264 or H.265 | AAC or FLAC |
video.webm |
WebM | VP9 or AV1 | Vorbis or Opus |
video.mov |
QuickTime | ProRes or H.264 | AAC |
With -c copy, converting MP4 to MKV changes only the container; the codecs stay the same. This is called a stream copy, and nothing is re-encoded.
What FFmpeg Can Do (With Command Examples)
1. Format Conversion (Container Swap)
This changes the container without re-encoding. It is very fast and loses no quality.
# MKV → MP4 (codec stays the same)
ffmpeg -i input.mkv -c copy output.mp4
2. Encoding and Compression
Re-encoding can make the file smaller while keeping good quality. If the source is already heavily compressed, the result can come out larger. -crf sets the quality: a lower number means better quality and a bigger file.
# H.264 compression (most compatible)
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac output.mp4
# H.265 for smaller files (slower to encode)
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -c:a aac output.mp4
3. Trimming and Cutting
# Cut from 1:00 to 2:00 (fast stream copy)
ffmpeg -ss 00:01:00 -to 00:02:00 -i input.mp4 -c copy output.mp4
4. Audio Extraction
# Extract MP3 from video
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3
# Lossless AAC extraction
ffmpeg -i input.mp4 -vn -c:a copy output.aac
5. GIF Creation
# Convert a whole video to an animated GIF
ffmpeg -i input.mp4 -vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
6. Resize / Scale
# 1080p → 720p
ffmpeg -i input_1080p.mp4 -vf scale=1280:-2 -c:v libx264 -crf 23 output_720p.mp4
7. Live Streaming (RTMP)
RTMP is the protocol used to send a live stream to a streaming service. Replace YOUR_KEY with the stream key shown in YouTube Studio. -g 60 inserts a keyframe (a complete frame that playback can start from) every 60 frames. YouTube recommends a keyframe every 2 seconds (no more than 4), so use 60 for 30 fps video and 120 for 60 fps.
# Stream to YouTube Live
ffmpeg -re -i input.mp4 -c:v libx264 -b:v 4000k -g 60 -c:a aac -f flv rtmp://a.rtmp.youtube.com/live2/YOUR_KEY
What FFmpeg Cannot Do
| Limitation | Reason / Alternative |
|---|---|
| Bypass DRM-protected content | DRM (copy protection) is protected by law. FFmpeg cannot obtain the keys needed to remove it. |
| Visual GUI editing | FFmpeg has no graphical interface. If you want one, use HandBrake, OpenShot or similar. |
| Timeline / non-linear editing | Use a video editor (NLE) such as Adobe Premiere or DaVinci Resolve. |
| AI-based upscaling | The sr and dnn_processing filters exist, but they need a build with a DNN backend and a model file. The gyan.dev builds have no DNN backend, so people usually use a dedicated tool such as Real-ESRGAN. |
The Roles of ffmpeg, ffprobe, and ffplay
| Tool | Role | When to Use |
|---|---|---|
ffmpeg |
Conversion, encoding, filtering, streaming | Virtually all video processing |
ffprobe |
File analysis, metadata inspection | Checking codec, resolution, frame rate |
ffplay |
Simple player (SDL), for testing | Quick preview of filter output |
# Check version
ffmpeg -version
# Inspect file info
ffprobe -v quiet -show_streams -print_format json input.mp4
# Play a video
ffplay input.mp4
Developer Library Structure (libav*)
| Library | Role |
|---|---|
libavcodec |
Collection of encoders and decoders |
libavformat |
Writing streams into containers (muxing) and reading them out (demuxing) |
libavdevice |
Device I/O (cameras, microphones, etc.) |
libavfilter |
Filter graph processing |
libavutil |
Common utilities |
libswscale |
Video scaling and pixel format conversion |
libswresample |
Audio resampling and format conversion |
FAQ
Q1. Is FFmpeg free? A. Yes. It is free, open-source software under the LGPL v2.1 or later (or, optionally, the GPL v2 or later). You can use it commercially if you follow the license conditions in FFmpeg Legal.
Q2. Do I need programming knowledge to use it? A. No. You only need to open a terminal and type commands. You can paste the commands above as they are, after changing the file names to your own.
Q3. Does it work on Windows, macOS, and Linux? A. Yes. The installation steps differ, but the commands are almost the same on every system. Small details differ, such as the character that separates folders in a path.
Q4. How do I check which formats my FFmpeg build supports? A. These commands list what your build supports:
# List supported formats
ffmpeg -formats
# List supported codecs
ffmpeg -codecs
# List available encoders
ffmpeg -encoders
Q5. What is the difference between FFmpeg and HandBrake? A. HandBrake is a program with a graphical interface that uses FFmpeg’s libraries internally. FFmpeg is a command-line tool: it is far more flexible and easy to script and automate. HandBrake is easier for beginners; FFmpeg gives you complete control.