Logo
Media Processing Masterclass

Essential FFmpeg Commands

From generating mobile-friendly gallery thumbnails to compressing heavy media streams for cloud synchronization, master the most powerful CLI tool for audio and video manipulation.

FFmpeg v7.0 (Diorite)

The industry standard framework for decoding, encoding, transcoding, muxing, and demuxing. Version 7.0 introduces native VVC/H.266 decoding and multi-threading optimizations.

Format Conversion

Convert between container formats quickly. Using -c copy avoids re-encoding, preserving original quality.

ffmpeg -i raw_input.mov -c copy web_output.mp4

High-Efficiency Compression

Compress files safely for cloud uploading. Adjust CRF (Constant Rate Factor) between 18-28. Higher means smaller file but lower quality.

ffmpeg -i high_res.mp4 -vcodec libx265 -crf 28 cloud_sync_optimized.mp4

Extract Snippet / Trimming

Fast seeking and cutting. -ss is the start time, -t is duration. Putting -ss before -i makes it significantly faster.

# Extract 10 seconds starting from 00:01:15
ffmpeg -ss 00:01:15 -i full_video.mp4 -t 00:00:10 -c copy snippet.mp4

Scale / Change Resolution

Scale videos using video filters (-vf). Using -1 for one dimension automatically calculates the correct aspect ratio to prevent distortion.

# Scale to 720p height, auto-width
ffmpeg -i 4k_video.mp4 -vf scale=-1:720 gallery_thumbnail.mp4

Demuxing (Split Audio/Video)

Strip audio (-an) or video (-vn) streams completely. Useful for creating silent background loops or extracting podcast audio.

# Extract pure audio as MP3
ffmpeg -i video_with_music.mp4 -vn -c:a libmp3lame pure_audio.mp3

# Remove audio stream entirely
ffmpeg -i video_with_music.mp4 -an -c:v copy silent_video.mp4

Concatenate / Merge Videos

Merge multiple identical-format videos into one. Create a text file (list.txt) with 'file' syntax, then use the concat demuxer.

# Content of list.txt:
# file 'part1.mp4'
# file 'part2.mp4'

ffmpeg -f concat -safe 0 -i list.txt -c copy merged_final.mp4

Screen Recording

Record your desktop natively. Use gdigrab for Windows. (For macOS, replace with -f avfoundation -i '1:0').

# Record entire desktop at 30 fps
ffmpeg -f gdigrab -framerate 30 -i desktop output_screen.mp4

Extract Frames for Analysis

Extract image frames from a video stream. Essential for feeding visual data into content-based similarity algorithms or AI models.

# Extract 1 frame per second
ffmpeg -i input.mp4 -vf fps=1 frame_%04d.jpg

Spatial Cropping

Remove black bars or crop a 16:9 video to a 1:1 square. x and y define the starting top-left coordinates.

ffmpeg -i input.mp4 -vf "crop=w=640:h=640:x=0:y=0" output_crop.mp4

High-Quality GIF Generator

Generate a global color palette first, then render the GIF to prevent color distortion and jagged edges.

ffmpeg -i input.mp4 -vf "fps=15,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

Overlay Watermark

Overlay an image onto a video. Use basic math in the coordinates to position it accurately (e.g., bottom-right corner).

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=main_w-overlay_w-20:main_h-overlay_h-20" output_watermark.mp4

Rotate & Mirror Flip

Fix upside-down phone recordings using transpose, or create mirror effects using hflip/vflip.

# Rotate 90 degrees clockwise
ffmpeg -i input.mp4 -vf "transpose=1" output_rotate90.mp4

# Horizontal mirror flip
ffmpeg -i input.mp4 -vf "hflip" output_hflip.mp4

Volume & Audio Fades

Adjust background music volume or eliminate popping sounds by adding audio fade-in and fade-out effects.

ffmpeg -i input.mp4 -af "volume=1.5,afade=t=in:ss=0:d=3,afade=t=out:st=27:d=3" output_audio.mp4

Multi-Track Mapping

Select specific video and audio tracks from MKV/MP4 files that contain multiple languages or commentaries.

ffmpeg -i multi_audio.mkv -map 0:v:0 -map 0:a:1 -c copy output_single_track.mp4

Change Framerate (FPS)

Force a 60fps video down to 24fps or 30fps to accommodate older decoding hardware or reduce processing load.

ffmpeg -i input.mp4 -r 30 output_30fps.mp4

Pro Tip: Filtergraph Chaining

If you need to resize AND crop a video simultaneously, do not run FFmpeg twice. Chain the commands in a single -vf flag separated by a comma (e.g., -vf "scale=1920:-1,crop=1080:1080"). This ensures the video is only decoded and encoded once, saving massive amounts of compute time.