· FabLab Westharima Team · Documentation · 6 min read
FFmpeg Installation, Usage, Options, and Commands
Explaining usage of FFmpeg, a powerful tool that can execute video/audio conversion, compression, extraction, and concatenation via command line. Basic command structure and practical recipes without confusion even for beginners.
FFmpeg is a powerful tool that can execute video/audio conversion, compression, extraction, concatenation, etc. via command line. This article aims to “avoid confusion even for first-timers” by summarizing basic command structure and frequently used options in tables with usage examples. Also includes practical recipes ready for copy-paste.
Installation
- macOS (Easy to use Homebrew):
Install Homebrew (only if you haven’t)
Install ffmpeg (execute following command from terminal)
brew install ffmpegCheck version
ffmpeg -version
Windows:
Official distribution or
choco install ffmpeg(Chocolatey), etc.Check with
ffmpeg -versionafter installation.
Linux:
- Use distribution’s package manager (e.g.,
sudo apt install ffmpeg).
- Use distribution’s package manager (e.g.,
Basic Command Structure (Most Important)
FFmpeg basic form is below. Conceptually it’s flow of “input → processing → output”.
ffmpeg [global options] [input options] -i [input file] [output options] [output file]Role of Each Part
| Part Name | Role/Description | Example/Notes |
|---|---|---|
| Global Options | Options affecting entire ffmpeg | -y (overwrite output file without confirmation) |
| Input Options | Specifications for input file | -ss 60 (start from 60 seconds of input), -f mp4 (explicitly specify input format) |
| Input File | Specify file to convert/edit | -i input.mp4 |
| Output Options | Specify output format and encoding method | -c:v libx264 (video codec), -c:a aac (audio codec), -crf 23 (quality specification), -vf scale=1280:720 (resize) |
| Output File | Specify file name after conversion/edit | output.mp4 |
Points (Order is Important)
For most options, “which output it affects” is determined by position. In principle, options written “before” output filename are applied to that output.
Specify input with
-i, then line up codec, bitrate, filters (-vf/-af), etc., and write output filename at end.Multiple outputs possible in single command (place options right before each output).
Command Example
ffmpeg -y -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k -vf "scale=1280:720" output.mp4Command Example Breakdown Image
ffmpeg \
[global] \ # -y (overwrite output file without confirmation)
-i input.mp4 # Input (container: MP4, contains video/audio streams) \
-c:v libx264 -crf 23 # Video codec settings (libx264) and quality (CRF) \
-c:a aac -b:a 128k # Audio codec (AAC) and audio bitrate \
-vf scale=1280:720 # Video filter (e.g., resize) \
output.mp4 # OutputTerminology Memo (For Beginners)
| Term | Meaning/Description | Example/Notes |
|---|---|---|
| Codec | Method to compress/decompress data. “Internal format” of video or audio. | Video: H.264, Audio: AAC |
| Container | Format of “container” that stores video, audio, subtitles, etc. together. | MP4, MKV, etc. |
| Bitrate | Amount of data per second. Higher tends to better image/sound quality. | 2M = 2 megabits/second |
| Frame Rate | Number of frames (images) displayed per second. | 24fps, 30fps, 60fps, etc. |
| Resolution | Screen vertical/horizontal size (number of pixels). | 1920x1080, etc. |
| CRF | Quality target index (Constant Rate Factor). Smaller is higher quality. | 0=lossless, 18-28 is guideline, around 23 is standard |
| CFR/VFR | Constant Frame Rate (CFR) / Variable Frame Rate (VFR). Use according to application. | Switch for editing or streaming |
Frequently Used Options Quick Reference (With Usage Examples)
| Option | Role/Meaning | Common Use Cases | Usage Example | Notes |
|---|---|---|---|---|
| -i | Specify input file | Starting point of conversion/edit | -i input.mp4 | Multiple possible (line up -i). |
| -c:v | Specify video codec | Select H.264/H.265/VP9, etc. | -c:v libx264 | H.264 (libx264) for compatibility priority. |
| -c:a | Specify audio codec | AAC/MP3/Opus, etc. | -c:a aac | AAC is safe for general MP4. |
| -b:v | Video bitrate | ABR or CBR specification | -b:v 2M | Roughly controls file size. Not recommended with CRF. |
| -b:a | Audio bitrate | Audio quality adjustment | -b:a 128k | 128k often sufficient for talk-centered content. |
| -crf | Quality index (variable bitrate) | Quality-priority compression | -crf 23 | Smaller number is higher quality. 18-28 guideline for H.264. |
| -preset | Encode speed/compression ratio adjustment | Adjust speed keeping quality same | -preset slow | ultrafast→placebo. Slower = higher compression = smaller. |
| -vf | Video filter | Resize/crop/rotate, etc. | -vf scale=1280:720 | Connect multiple with ,. |
| -af | Audio filter | Volume adjustment/normalize, etc. | -af volume=1.5 | Can also write as -filter:a. |
| -filter_complex | Complex filter graph | Concatenation/PIP, etc. | -filter_complex "[0:v][1:v]hstack" | Supports multiple inputs/branching. |
| -ss | Start position | Trimming/thumbnail extraction | -ss 00:01:00 | Before input=fast/approximate, after=precise. |
| -t | Duration (seconds/time) | Specify clip length | -t 30 | -to is end time. Avoid combining (later written takes priority). |
| -to | End time | Specify up to 2 minutes, etc. | -to 00:02:00 | Use with -ss for section extraction too. |
| -r | Output frame rate | 24/30/60fps, etc. | -r 30 | Used when changing input fps. |
| -s | Output resolution | Standardize to 720p, etc. | -s 1280x720 | Mostly same as -vf scale. -vf recommended for filter chain. |
| -map | Stream selection | Only specific video/audio/subtitle | -map 0:v:0 -map 0:a:0 | Controls automatic selection. Important with multiple inputs. |
| -an | No audio | Mute video | -an | Don’t output audio track. |
| -vn | No video | Audio extraction | -vn | Don’t output video track. |
| -sn | No subtitles | Remove subtitles | -sn | Don’t output subtitles. |
| -pix_fmt | Pixel format | Ensure compatibility | -pix_fmt yuv420p | Effective for old playback devices. |
| -movflags +faststart | Move MP4 moov to front | Fast web playback | -movflags +faststart | Streaming starts quickly. |
| -shortest | Match to shortest stream | BGM is short, etc. | -shortest | End early matching shortest stream. |
| -y | Allow overwrite | Automation | -y | Overwrite existing file without confirmation. |
| -n | Prohibit overwrite | Prevent accidental overwrite | -n | Fail if exists. |
| -f | Specify format | Explicitly state raw PCM, etc. | -f wav | Use when automatic detection errors. |
Note: For H.264/H.265 quality priority,
-crf+-presetis basic. Only consider-b:v(2pass recommended) when there’s clear target size.Note 2:
-rhas different meaning on input side and output side.-rplaced before input is specification “consider input frame rate as this”, unnecessary for normal MP4 etc. Output side-rspecifies “output target fps”.
Ready-to-Use Commands (Copy-Paste OK)
1) MOV→MP4, CRF 25 specification
ffmpeg -i input.mov -crf 25 output1.mp42) Video trimming (30 seconds from 1-minute point)
ffmpeg -i input.mp4 -ss 00:01:00 -t 30 -c:v libx264 -crf 22 -c:a aac -b:a 128k output_clip.mp4Memo: Placing -ss “after” input improves frame accuracy (speed slightly decreases).
3) Fast rough trimming (keyframe basis)
ffmpeg -ss 60 -i input.mp4 -t 30 -c copy output_fast.mp4Memo: Place -ss “before” input, no re-encoding with -c copy. Cut point becomes approximate.
4) Mute audio (video re-encoded)
ffmpeg -i input.mp4 -an -c:v libx264 -crf 23 output_noaudio.mp45) Extract only audio (WAV or MP3)
# WAV (uncompressed)
ffmpeg -i input.mp4 -vn -c:a pcm_s16le -ar 48000 -ac 2 output.wav
# MP3 (compressed)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -b:a 192k output.mp36) Resize to 1280x720 resolution
ffmpeg -i input.mp4 -vf scale=1280:720 -c:v libx264 -crf 22 -c:a aac -b:a 128k output_720p.mp47) Export with target bitrate (2Mbps)
ffmpeg -i input.mp4 -c:v libx264 -b:v 2M -c:a aac -b:a 128k output_2m.mp4Example: -b:v 2M. “Video quality is not guaranteed. Try with your desired bitrate.”
8) Quality priority (CRF basis)
ffmpeg -i input.mp4 -c:v libx264 -crf 20 -preset medium -c:a aac -b:a 160k output_crf20.mp49) Concatenate multiple videos (assuming same codec/resolution/frame rate)
# 1) Create list file (e.g., files.txt)
# file 'part1.mp4'
# file 'part2.mp4'
# file 'part3.mp4'
# 2) Concatenate with concat demultiplexer
ffmpeg -f concat -safe 0 -i files.txt -c copy merged.mp410) Burn in subtitles (SRT)
ffmpeg -i input.mp4 -vf subtitles=subs.srt -c:v libx264 -crf 22 -c:a copy output_subbed.mp411) Rotate 90 degrees (clockwise)
ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output_rotated.mp412) Convert frame rate to 30fps
ffmpeg -i input.mp4 -r 30 -c:v libx264 -crf 22 -c:a aac -b:a 128k output_30fps.mp4Specifying -r 30 is common. However, “frames are not interpolated, they are thinned/duplicated”
Common Questions/Troubleshooting
| Error/Phenomenon | Solution/Explanation |
|---|---|
| Unknown encoder ‘libx264’ | Build without H.264 encoder. macOS Homebrew version usually includes it. Use different distribution source or reinstall. |
| At least one output file must be specified | Forgot to write output filename. Explicitly state output.mp4 etc. at end. |
| Non-monotonous DTS | Timeline goes back and forth in trimming or stream concatenation. May resolve with -fflags +genpts or re-encoding. |
| Web playback slow to start | Move moov to front with -movflags +faststart. |
| Low compatibility/can’t play in some cases | Add -pix_fmt yuv420p, also consider adjusting level/profile for H.264. |
Reference Links
Official site: https://ffmpeg.org/
CRF explanation (English): https://slhck.info/video/2017/02/24/crf-guide.html
Above summarizes FFmpeg’s “basic template”, “standard options”, and “ready-to-use recipes”. First try running samples with copy-paste, then adjust parameters as needed.

