No fluff. Just the config that works.
Executive Summary
ffmpeg is the command line Swiss Army knife for audio and video. It sits under OBS, HandBrake, VLC, most video editors, and plenty of security tooling, and it is the fastest way to get a file from what you have to what you need. This post collects the ffmpeg commands I actually use, grouped into 15 common use cases, each with a copy-paste command and a way to prove it worked.
Objective: run the right ffmpeg command for a task the first time: inspect, remux, trim, compress, resize, pull audio, normalize loudness, crop for Shorts, join clips, grab thumbnails, make GIFs, add subtitles, strip location metadata, snapshot an RTSP camera, and batch convert a folder.
Target audience: network and security engineers, content creators, and anyone who has ever exported a 4 GB screen recording and needed it to be 40 MB in five minutes.
Prerequisites and Architecture
Assumed knowledge
- Comfortable in a terminal (zsh, bash, or PowerShell).
- Basic idea of the difference between a container (MP4, MKV, MOV) and a codec (H.264, HEVC, AAC).
Lab requirements
- macOS:
brew install ffmpeg(the Homebrew ffmpeg formula currently ships 9.1). - Ubuntu or Debian:
sudo apt install ffmpeg(distro packages lag the upstream release, which is fine for everything in this post). - Windows: ffmpeg.org only publishes source; the FFmpeg download page links the gyan.dev and BtbN builds. Unzip, then add the
binfolder to PATH. - Any test clip. If you have none, generate one: the first command in Use Case 1 builds a 20 second test pattern with a tone.
- Lab camera for Use Case 14 at 10.0.20.50 on the internal 10.0.0.0/16 LAN.
Components
| Binary | What it does | When you reach for it |
|---|---|---|
ffmpeg |
Reads inputs, runs filters and encoders, writes outputs | Every conversion, cut, crop, or encode |
ffprobe |
Reports container, stream, and tag details without changing anything | Before and after every job |
ffplay |
Minimal player built on the same libraries | Quick preview of a filter chain (not in every build) |
How an ffmpeg command is read
Order matters. Options apply to the next -i input or to the next output file, so -ss before -i is an input option (fast seek) and -ss after -i is an output option (decode and discard until that point). Per the ffmpeg documentation, ffmpeg transcodes every selected stream unless you tell it to stream copy with -c copy, which skips decode, filter, and encode entirely.
Figure 1: The ffmpeg pipeline and the stream copy shortcut

ffmpeg [input options] -i input.mov [output options] output.mp4
# -ss -t -f ^ -c:v -crf -vf -af -map
| Flag | Meaning |
|---|---|
-i |
Input file, URL, or device |
-c copy |
Stream copy: no re-encode, lossless, near instant |
-c:v / -c:a |
Video or audio encoder (for example libx264, aac) |
-vf / -af |
Video or audio filter chain |
-map |
Pick exactly which input streams go to the output |
-ss / -t / -to |
Start time, duration, stop time |
-vn / -an |
Drop video / drop audio |
-y / -n |
Overwrite outputs without asking / never overwrite |
15 Common ffmpeg Commands, Step by Step
Use Case 1: Inspect a file with ffprobe
Goal: Know what you have before you change it: codecs, resolution, duration, bitrate, and tags.
Action: Generate a test clip if needed, then ask ffprobe for a compact summary or full JSON.
# Optional: build a 20 second 1080p test clip with a 440 Hz tone
ffmpeg -f lavfi -i testsrc2=size=1920x1080:rate=30 \
-f lavfi -i sine=frequency=440 -t 20 \
-c:v libx264 -pix_fmt yuv420p -c:a aac -shortest input.mp4
ffprobe -v error \
-show_entries format=duration:stream=codec_name,width,height \
-of compact=p=0 input.mp4
# Everything, as JSON, for scripts
ffprobe -v error -show_format -show_streams -of json input.mp4
Verification: The compact form prints one line per stream plus the duration, for example codec_name=h264|width=1920|height=1080, codec_name=aac, duration=20.000000. The ffprobe documentation covers -show_entries syntax: sections separated by colons, fields by commas.
Use Case 2: Remux to a different container without re-encoding
Goal: Turn an MKV or MOV into an MP4 that plays everywhere, in seconds, with zero quality loss.
Action: Stream copy every stream into the new container.
ffmpeg -i input.mkv -c copy output.mp4
If MKV subtitles break the MP4 write, keep only video and audio, or convert the text subtitles to the MP4 format:
ffmpeg -i input.mkv -map 0:v -map 0:a -c copy output.mp4
ffmpeg -i input.mkv -map 0 -c copy -c:s mov_text output.mp4
Verification: The job finishes in a few seconds even for a large file, and ffprobe shows the same codecs as the source. If it takes minutes, you are transcoding, not copying.
Use Case 3: Trim a clip (fast vs. frame accurate)
Goal: Cut a section out of a long recording.
Action: Use stream copy when speed matters and a cut on the nearest keyframe is fine; re-encode when the first frame must be exact.
# Fast: seek on the input, copy 45 seconds starting at 1:30
ffmpeg -ss 00:01:30 -i input.mp4 -t 45 -c copy clip.mp4
# Frame accurate: same cut, re-encoded
ffmpeg -ss 00:01:30 -i input.mp4 -t 45 \
-c:v libx264 -crf 18 -c:a aac clip-exact.mp4
Verification: Check the result with ffprobe -v error -show_entries format=duration -of default=nw=1 clip.mp4. On my test clip a 10 second stream copy cut reported duration=10.100000: the extra tenth is the keyframe snap (see Troubleshooting).
Use Case 4: Compress a video with H.264 and CRF
Goal: Shrink a huge screen recording or phone video to something you can email, upload, or embed.
Action: Re-encode with libx264 in constant rate factor mode, AAC audio, and the web-friendly faststart flag.
ffmpeg -i input.mov -c:v libx264 -crf 23 -preset medium \
-pix_fmt yuv420p -c:a aac -b:a 128k \
-movflags +faststart output.mp4
The H.264 encoding guide puts the 8-bit CRF scale at 0 to 51 with 23 as the default and 17 to 28 as the sane range: lower is better quality and bigger files. Presets trade speed for compression, from ultrafast to veryslow. Want smaller files at similar quality? Use HEVC, and add the hvc1 tag so Apple devices play it:
ffmpeg -i input.mov -c:v libx265 -crf 28 -tag:v hvc1 \
-c:a aac -b:a 128k output-hevc.mp4
On Apple Silicon, the hardware encoder is dramatically faster at a modest quality cost (it uses a bitrate, not CRF):
ffmpeg -i input.mov -c:v h264_videotoolbox -b:v 6M -c:a aac output-hw.mp4
Verification: Compare sizes with ls -lh input.mov output.mp4. My 20 second test pattern went from 14.5 MB to 5.8 MB at CRF 28; real screen recordings with large static areas shrink far more.
Use Case 5: Resize or scale
Goal: Make a 4K or 1080p file 720p (or any size) without distorting it.
Action: Use the scale filter, fix one dimension, and let ffmpeg compute the other with -2 so it stays an even number.
ffmpeg -i input.mp4 -vf scale=-2:720 -c:v libx264 -crf 23 -c:a copy output-720p.mp4
Verification: ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 output-720p.mp4 returns 1280,720 for a 16:9 source.
Use Case 6: Extract, remove, or replace audio
Goal: Pull the audio for a podcast or transcript, mute a clip, or drop a new voiceover onto existing video.
Action: Use -vn to drop video, -an to drop audio, and -map to combine streams from two inputs.
# Extract as-is (fast, if the source audio is AAC)
ffmpeg -i input.mp4 -vn -c:a copy audio.m4a
# Extract as MP3 (VBR, high quality)
ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3
# Remove audio, keep video untouched
ffmpeg -i input.mp4 -an -c:v copy silent.mp4
# Replace audio: video from file 0, audio from file 1
ffmpeg -i input.mp4 -i voice.wav -map 0:v -map 1:a \
-c:v copy -c:a aac -shortest dubbed.mp4
Verification: ffprobe on silent.mp4 lists only the h264 stream; on dubbed.mp4 it lists the original video and a new aac stream.
Use Case 7: Normalize loudness for YouTube, TikTok, and podcasts
Goal: Stop viewers reaching for the volume knob. Hit a consistent loudness target instead of guessing with a volume boost.
Action: Use the EBU R128 loudnorm filter. One pass is fine for most clips; two passes are more accurate for finished files.
# One pass: target -14 LUFS, true peak -1.5 dBTP, leave the video alone
ffmpeg -i input.mp4 -af loudnorm=I=-14:TP=-1.5:LRA=11 \
-ar 48000 -c:v copy output-loud.mp4
# Two pass, step 1: measure only (no output file)
ffmpeg -i input.mp4 -af loudnorm=I=-14:TP=-1.5:LRA=11:print_format=json \
-f null -
# Step 2: feed the measured_I, measured_TP, measured_LRA, measured_thresh
# and offset values from step 1 back into loudnorm with linear=true
The loudnorm filter reference lists the defaults as I=-24, LRA=7, and TP=-2, which are broadcast numbers. Social and streaming platforms sit much louder, so set the targets explicitly; -14 LUFS is a common choice for Shorts and YouTube.
Always add -ar 48000. loudnorm works at a high internal sample rate and hands that rate to the encoder: without the flag, my 48 kHz test clip came out at 96 kHz in MP4 (192 kHz in MKV), which bloats files and confuses some players.
Verification: Run the measurement command on the output. The summary or JSON block reports the new integrated loudness close to your I= target.
Use Case 8: Crop horizontal video to vertical 9:16 for Shorts and Reels
Goal: Turn a 16:9 recording into a 1080×1920 vertical video.
Action: Crop a centered 9:16 window the full height of the frame, then scale to 1080×1920.
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih,scale=1080:1920" \
-c:v libx264 -crf 20 -c:a copy vertical.mp4
To keep the left side of the frame instead of the center (a terminal window, for example), add an x offset: crop=ih*9/16:ih:0:0.
Verification: ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 vertical.mp4 returns 1080,1920.
Use Case 9: Join clips with the concat demuxer
Goal: Stitch an intro, the main recording, and an outro into one file without re-encoding.
Action: Write a list file, then concatenate with stream copy. Every clip must share the same codecs, resolution, and timebase.
cat > list.txt <<'EOF'
file 'intro.mp4'
file 'main.mp4'
file 'outro.mp4'
EOF
ffmpeg -f concat -safe 0 -i list.txt -c copy joined.mp4
Verification: The output duration should be roughly the sum of the inputs. The ffmpeg formats documentation explains that -safe 0 is needed for absolute paths or names with spaces; if the clips came from different cameras or apps, re-encode them to a common format first.
Use Case 10: Grab thumbnails, frames, and a contact sheet
Goal: Get a still for a feature image, a frame every N seconds for review, or a one-image overview of a long recording.
Action: Seek and output one frame, or use the fps and tile filters.
# One high quality JPEG at 3 seconds
ffmpeg -ss 00:00:03 -i input.mp4 -frames:v 1 -q:v 2 thumb.jpg
# One PNG every 10 seconds
mkdir -p frames
ffmpeg -i input.mp4 -vf fps=1/10 frames/frame-%03d.png
# 4x3 contact sheet, one tile every 10 seconds
ffmpeg -i input.mp4 -vf "fps=1/10,scale=320:-1,tile=4x3" \
-frames:v 1 sheet.png
Verification: Open the images. frames/ holds one file per 10 seconds of video, numbered from frame-001.png.
Use Case 11: Make a small, sharp GIF
Goal: Embed a short demo in a README, ticket, or blog post where video will not autoplay.
Action: Generate an optimized palette from the clip and apply it in a single command, at a low frame rate and modest width.
ffmpeg -ss 2 -t 3 -i input.mp4 \
-vf "fps=12,scale=480:-1:flags=lanczos,split[a][b];\
[a]palettegen[p];[b][p]paletteuse" demo.gif
Verification: The GIF plays in a browser without the banding and dithering mush of a default conversion. If it is still too big, drop fps to 10 or the width to 360.
Use Case 12: Add subtitles (soft or burned in)
Goal: Ship captions viewers can toggle, or bake them into the picture for platforms that ignore subtitle tracks.
Action: Mux an SRT as an MP4 text track, or render it into the frames with the subtitles filter (needs a build with libass).
# Soft subtitles: selectable track, no re-encode of the video
ffmpeg -i input.mp4 -i subs.srt -map 0 -map 1 \
-c copy -c:s mov_text output-soft.mp4
# Burned in: always visible, video is re-encoded
ffmpeg -i input.mp4 -vf subtitles=subs.srt -c:a copy output-burned.mp4
Verification: ffprobe -v error -show_entries stream=codec_name -of csv=p=0 output-soft.mp4 lists h264, aac, and mov_text. The burned version shows the captions in any player.
Use Case 13: Strip GPS and other metadata before you share
Goal: Phone videos can carry location tags. Remove them before a clip goes to a customer, a ticket, or social media.
Action: Copy every stream, but tell ffmpeg not to carry global metadata across.
# Look for tags first
ffprobe -v error -show_entries format_tags -of default=nw=1 phone.mp4
# Strip them (no re-encode)
ffmpeg -i phone.mp4 -map 0 -map_metadata -1 -c copy clean.mp4
Verification: In my test, the source listed TAG:location=+27.9506-082.4572/; after the strip, only the container basics such as major_brand and the encoder tag remained. Check stream-level tags too with -show_entries stream_tags.
Use Case 14: Snapshot or record an RTSP camera
Goal: Pull a still from an IP camera for a ticket or NVR check, or record a camera to rolling files without an NVR.
Action: Force RTSP over TCP (UDP drops frames across firewalls and VPNs), then grab one frame or stream copy into time-based segments.
# One snapshot
ffmpeg -rtsp_transport tcp -i "rtsp://viewer:<password>@10.0.20.50:554/stream1" \
-frames:v 1 cam-snap.jpg
# Record in 5 minute files named by wall-clock time
ffmpeg -rtsp_transport tcp -i "rtsp://viewer:<password>@10.0.20.50:554/stream1" \
-c copy -f segment -segment_time 300 -reset_timestamps 1 \
-strftime 1 "cam-%Y%m%d-%H%M%S.mp4"
Credentials in the URL end up in your shell history and in ps output. Use a view-only camera account, and clean up afterwards with the tips in clearing bash and zsh history. For a recorder that survives reboots, wrap the command in a service; see systemctl commands and hidden options.
Verification: cam-snap.jpg opens and shows the current scene. A new cam-*.mp4 file appears every five minutes.
Use Case 15: Batch convert a whole folder
Goal: Convert every MOV in a folder to MP4 in one go, without overwriting anything that already exists.
Action: Loop over the files and call ffmpeg once per file. -n skips outputs that already exist, so the loop is safe to rerun.
# macOS / Linux (bash or zsh)
for f in *.mov; do
ffmpeg -n -i "$f" -c:v libx264 -crf 23 -c:a aac "${f%.mov}.mp4"
done
# Windows PowerShell
Get-ChildItem *.mov | ForEach-Object {
ffmpeg -n -i $_.FullName -c:v libx264 -crf 23 -c:a aac ($_.BaseName + '.mp4')
}
Long batches outlive SSH sessions. Run them inside tmux so a dropped connection does not kill the job; see tmux tips and tricks.
Verification: Every .mov has a matching .mp4, and a second run prints already exists. Exiting. per file instead of re-encoding.
Verification and Validation
Three checks cover almost every job:
# 1. Did I get the codecs and size I asked for?
ffprobe -v error -show_entries stream=codec_name,width,height,pix_fmt \
-of compact=p=0 output.mp4
# 2. Is the file fully decodable? (no output means no errors)
ffmpeg -v error -i output.mp4 -f null -
# 3. Did the loudness land where I wanted?
ffmpeg -i output.mp4 -af loudnorm=print_format=summary -f null - 2>&1 | \
grep -A3 "Input Integrated"
Expected success output: check 1 shows codec_name=h264|width=1920|height=1080|pix_fmt=yuv420p (or your target values), check 2 prints nothing and exits 0, and check 3 shows an Input Integrated value within about 1 LU of your target.
Troubleshooting and Gotchas
1. Stream copy cuts start early, or have a frozen first second
With -c copy, ffmpeg can only cut on keyframes, so the clip starts at the keyframe before your -ss time. My 10 second cut came out at 10.1 seconds, and two of those clips concatenated to 21.2 seconds instead of 20.2.
ffprobe -v error -show_entries format=duration -of default=nw=1 clip.mp4
Fix: accept the small drift for rough cuts, or re-encode the cut (Use Case 3, frame accurate version) when timing matters.
2. height not divisible by 2
libx264 with the standard yuv420p pixel format needs even dimensions. Scaling with -1 can produce an odd number:
[libx264 @ 0x563c80904400] height not divisible by 2 (1282x721)
Error while opening encoder - maybe incorrect parameters such as
bit_rate, rate, width or height.
Fix: use -2 instead of -1 in scale (for example scale=-2:720), or round explicitly with scale=trunc(iw/2)*2:trunc(ih/2)*2.
3. Concat fails with Unsafe file name
The concat demuxer rejects absolute paths and names with spaces or special characters by default:
[concat @ 0x55642257b000] Unsafe file name 'my clip.mp4'
Fix: add -safe 0 before -i list.txt. If the join succeeds but playback stutters or audio drifts, the clips do not share codecs or timebases; re-encode each to the same settings first.
4. Plays in VLC but not in QuickTime, Safari, or Slack
VLC plays almost anything; Apple players and browsers are pickier. Usual causes: a 4:2:2 or 4:4:4 pixel format, HEVC tagged hev1 instead of hvc1, or the index at the end of the file.
ffprobe -v error -select_streams v:0 \
-show_entries stream=codec_name,codec_tag_string,pix_fmt \
-of compact=p=0 output.mp4
Fix: add -pix_fmt yuv420p, use -tag:v hvc1 for HEVC, and add -movflags +faststart for anything played in a browser.
Sources
- ffmpeg Documentation (ffmpeg.org)
- ffprobe Documentation (ffmpeg.org)
- FFmpeg Formats Documentation, concat demuxer (ffmpeg.org)
- H.264 Video Encoding Guide (FFmpeg wiki)
- loudnorm filter reference for FFmpeg 8.0
- FFmpeg Download page and third-party builds
- Homebrew ffmpeg formula