Skip to content

FFmpeg Command Guide

Complete FFmpeg usage guide with various common commands, parameter explanations and practical application scenario examples

What is FFmpeg?

Understanding the most powerful multimedia framework

Cross-Platform

Runs on Linux, macOS, Windows, and more

Open Source

Free to use under LGPL or GPL license

Powerful

Supports virtually all video/audio formats

Flexible

Command-line interface for automation

How to Use FFmpeg

Quick start guide for beginners

1
Install FFmpeg
2
Open Terminal
3
Copy Command
4
Paste & Run

Basic Operations

Format Conversion

basic

Convert a video from one format to another

ffmpeg -i input.avi output.mp4
-iSpecify input file

The output format is determined by the file extension. FFmpeg automatically selects an appropriate encoder.

Extract Audio

basic

Extract the audio track from a video file

ffmpeg -i video.mp4 -vn -c:a libmp3lame audio.mp3
-vnDisable video stream
-c:aSet audio encoder

Extracts the audio stream from the video and saves it as MP3 while preserving original audio quality.

Capture Screenshot

basic

Capture a single frame at a specific timestamp

ffmpeg -i video.mp4 -ss 00:01:30 -vframes 1 screenshot.jpg
-ssSeek to specific timestamp
-vframesNumber of frames to capture

Captures a single frame at 1 minute and 30 seconds. Commonly used for thumbnails or previews.

View Media Info

basic

Display detailed media file information

ffmpeg -i input.mp4
-iSpecify input file

Displays codec, duration, resolution, bitrate, and stream details when no output file is specified.

Convert Video to GIF

basic

Convert a video clip to an animated GIF

ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" output.gif
-vfVideo filter chain
fpsSet frame rate
scaleResize video

Converts video to a 10 FPS GIF with 320px width. Commonly used for memes or short animations.

Batch Format Conversion

basic

Batch convert multiple files to MP4 format

for %i in (*.mov) do ffmpeg -i "%i" -c:v libx264 -crf 23 -c:a aac "%~ni.mp4"
for loopBatch process multiple files
-c:vSet video encoder

Batch converts all MOV files to MP4 using H.264 and AAC. Common for camera footage workflows.

Extract Frame Sequence

basic

Export all frames as an image sequence

ffmpeg -i video.mp4 frame_%04d.jpg
%04dFour-digit frame index

Extracts every frame as JPEG images (frame_0001.jpg, frame_0002.jpg, etc.).

Trim Video

basic

Extract a specific time range from a video

ffmpeg -i input.mp4 -ss 00:10:00 -to 00:15:30 -c copy clip.mp4
-ssStart time
-toEnd time
-c copyStream copy (no re-encoding)

Quickly trims a clip using stream copy to preserve original quality and speed up processing.

Merge Videos

basic

Concatenate multiple video files into one

ffmpeg -f concat -i filelist.txt -c copy output.mp4
-f concatUse concat demuxer
-i filelist.txtInput file list

Merges multiple videos listed in filelist.txt without re-encoding.

Change Playback Speed

basic

Speed up or slow down video playback

ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -an output.mp4
-vf setptsModify video timestamps
-anDisable audio

Speeds up video by 2x (0.5*PTS). Use 2*PTS to slow down by 0.5x.

Video Processing

Resize Video

video

Change the video resolution

ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
-vf scaleScale video using the video filter

Resizes the video to 1280x720 pixels while preserving the original aspect ratio.

Compress Video

video

Reduce video file size

ffmpeg -i input.mp4 -c:v libx264 -crf 23 compressed.mp4
-c:vSet the video encoder
-crfConstant Rate Factor (0–51)

Compresses the video using H.264. Lower CRF values produce higher quality. A typical range is 18–28.

Add Watermark

video

Overlay an image or text watermark on the video

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output.mp4
-filter_complexApply complex filter graphs
overlayOverlay position (top-left corner)

Adds a PNG watermark image at position (10,10) in the top-left corner of the video.

Crop Video

video

Crop a specific region of the video

ffmpeg -i input.mp4 -vf "crop=640:360:100:100" output.mp4
-vf cropCrop video using the crop filter

Crops a 640x360 region starting from position (100,100).

Rotate Video

video

Rotate the video by 90°, 180°, or 270°

ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
-vf transposeRotate video using the transpose filter

Transpose values: 0 = 90° CCW + vertical flip, 1 = 90° clockwise, 2 = 90° counter-clockwise, 3 = 90° clockwise + vertical flip.

Video Stabilization (Analysis)

video

Analyze camera shake using vid.stab

ffmpeg -i shaky.mp4 -vf vidstabdetect=shakiness=5:accuracy=15:result="transform_vectors.trf" -f null -
-vf vidstabdetectDetect camera motion for stabilization

Step 1: Analyzes camera shake and generates a transformation vector file.

Video Stabilization (Apply)

video

Apply video stabilization

ffmpeg -i shaky.mp4 -vf vidstabtransform=smoothing=10:input="transform_vectors.trf" stable.mp4
-vf vidstabtransformApply stabilization transforms

Step 2: Applies stabilization using the generated transform file. The smoothing parameter controls stabilization strength.

Deinterlace (YADIF)

video

Remove interlacing artifacts from video

ffmpeg -i input.mp4 -vf yadif output.mp4
-vf yadifYADIF deinterlacing filter

Removes interlacing artifacts to make the video suitable for progressive displays.

Deinterlace (BWDIF)

video

Convert interlaced video to progressive

ffmpeg -i interlaced.mp4 -vf bwdif=0:-1:0 deinterlaced.mp4
-vf bwdifHigh-quality deinterlacing filter

Uses the BWDIF filter to convert interlaced video to progressive scan for better playback quality.

Video Denoising

video

Reduce noise and grain in video

ffmpeg -i noisy.mp4 -vf hqdn3d denoised.mp4
-vf hqdn3dHigh-quality 3D denoising filter

Reduces visual noise and grain using the hqdn3d filter to improve overall video quality.

Audio Processing

Adjust Audio Volume

audio

Increase or decrease audio volume

ffmpeg -i input.mp3 -af "volume=1.5" output.mp3
-afApply audio filters
volume=1.5Increase volume by 50%

Boosts the audio volume by 50%. Use values below 1.0 to reduce volume.

Convert Audio Format

audio

Convert audio from one format to another

ffmpeg -i input.wav -c:a libmp3lame -b:a 192k output.mp3
-c:aSet audio encoder
-b:aSet audio bitrate

Converts WAV audio to MP3 at 192 kbps, suitable for web distribution.

Trim Audio

audio

Extract a specific time segment from audio

ffmpeg -i input.mp3 -ss 00:01:30 -to 00:03:45 -c copy clip.mp3
-ssStart time
-toEnd time
-c copyStream copy without re-encoding

Extracts audio from 01:30 to 03:45 without re-encoding, preserving original quality.

Fade In / Fade Out

audio

Add fade-in and fade-out effects to audio

ffmpeg -i input.mp3 -af "afade=t=in:st=0:d=3,afade=t=out:st=10:d=3" output.mp3
-af afadeAudio fade filter

Applies a 3-second fade-in starting at 0s and a 3-second fade-out starting at 10s.

Audio Noise Reduction

audio

Reduce background noise in audio

ffmpeg -i input.wav -af "afftdn=nf=-20" output.wav
-af afftdnFFT-based denoising filter

Uses FFT-based noise reduction to reduce background noise. The nf parameter controls denoising strength.

Merge Audio Files

audio

Merge multiple audio files into one

ffmpeg -i "concat:input1.mp3|input2.mp3" -c copy output.mp3
concat:Concatenate multiple input files

Merges multiple audio files in sequence without re-encoding, preserving original quality.

Change Sample Rate

audio

Adjust the audio sample rate

ffmpeg -i input.wav -ar 44100 output.wav
-arSet audio sample rate

Sets the audio sample rate to 44.1 kHz, the standard CD-quality sample rate.

Channel Conversion

audio

Convert between mono and stereo

ffmpeg -i input.wav -ac 1 output.wav
-acSet number of audio channels

Converts stereo audio to mono. Set to 2 to convert mono to stereo.

Audio Equalizer

audio

Adjust frequency response using EQ

ffmpeg -i input.wav -af "equalizer=f=1000:width_type=o:width=2:g=5" output.wav
-af equalizerAudio equalizer filter

Boosts the 1000 Hz frequency band by 5 dB to adjust tonal balance.

Dynamic Range Compression

audio

Apply audio dynamic range compression

ffmpeg -i input.wav -af "acompressor=threshold=0.1:ratio=9:attack=200:release=1000" output.wav
-af acompressorAudio compressor filter

Applies dynamic range compression to reduce loudness variation and make quiet parts louder.

Filter Effects

Add Text Watermark

filter

Overlay text watermark on video

ffmpeg -i input.mp4 -vf "drawtext=text='Sample Text':x=10:y=10:fontsize=24:fontcolor=white" output.mp4
-vf drawtextDraw text overlay filter

Adds a white text watermark at position (10,10) with a font size of 24.

Blur Video

filter

Apply blur effect to video

ffmpeg -i input.mp4 -vf "boxblur=5:1" output.mp4
-vf boxblurBox blur filter

Applies a blur effect to the video. The first parameter controls blur strength, and the second controls quality.

Color Correction

filter

Adjust brightness, contrast, and saturation

ffmpeg -i input.mp4 -vf "eq=brightness=0.1:contrast=1.2:saturation=1.5" output.mp4
-vf eqColor equalizer filter

Adjusts brightness (+0.1), contrast (1.2x), and saturation (1.5x).

Mirror Effect

filter

Create a vertical mirror effect

ffmpeg -i input.mp4 -vf "split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2" output.mp4
-vf splitSplit video stream
vflipVertical flip

Creates a vertical mirror effect where the bottom half mirrors the top half.

Vintage Film Effect

filter

Apply old film / vintage movie effect

ffmpeg -i input.mp4 -vf "noise=alls=20:allf=t+u, curves=vintage" output.mp4
-vf noiseAdd film grain noise
curvesApply vintage color curves

Adds film grain and vintage color curves to simulate an old movie look.

Sharpen Video

filter

Enhance video details and clarity

ffmpeg -i input.mp4 -vf "unsharp=5:5:1.0" output.mp4
-vf unsharpUnsharp mask filter

Sharpens the video using the unsharp mask algorithm to enhance detail and clarity.

Edge Detection

filter

Detect and highlight edges in video

ffmpeg -i input.mp4 -vf "edgedetect=low=0.1:high=0.4" output.mp4
-vf edgedetectEdge detection filter

Detects and highlights edges in the video, commonly used in computer vision workflows.

Color Space Conversion

filter

Convert video color space

ffmpeg -i input.mp4 -vf "colorspace=bt709:iall=bt601-6-625:fast=1" output.mp4
-vf colorspaceColor space conversion filter

Converts video from BT.601 color space to BT.709 color space.

Convert to Grayscale

filter

Convert color video to grayscale

ffmpeg -i input.mp4 -vf "hue=s=0" output.mp4
-vf hueHue and saturation filter

Converts color video to grayscale by setting saturation to 0.

Negative Effect

filter

Invert video colors

ffmpeg -i input.mp4 -vf "negate" output.mp4
-vf negateColor inversion filter

Inverts all color values to create a negative film effect.

Streaming Media

Record RTMP Stream

stream

Record RTMP live stream to a local file

ffmpeg -i rtmp://server/live/stream -c copy -f flv recording.flv
-c copyStream copy (no re-encoding)
-f flvSet output container to FLV

Records an RTMP live stream and saves it as an FLV file. Stream copy avoids re-encoding to reduce CPU usage.

Generate HLS Stream

stream

Convert a video file to HLS streaming format

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f hls -hls_time 10 -hls_list_size 0 output.m3u8
-f hlsSet output format to HLS
-hls_timeSegment duration (seconds)

Converts an MP4 file to HLS format with 10-second segments, suitable for web streaming.

Push RTMP Stream

stream

Stream a local file to an RTMP server

ffmpeg -re -i input.mp4 -c copy -f flv rtmp://server/live/stream
-reRead input at native frame rate
-f flvSet output container to FLV

Pushes a local video file to an RTMP server as a live stream, commonly used for live broadcasting.

Screen Recording

stream

Capture and record desktop screen

ffmpeg -f gdigrab -i desktop output.mp4
-f gdigrabGDI-based screen capture (Windows)

Records the entire desktop on Windows. On Linux, use x11grab for screen capture.

Webcam Recording

stream

Record video from webcam device

ffmpeg -f dshow -i video="Integrated Camera" output.mp4
-f dshowDirectShow input (Windows)

Records video from a webcam device on Windows. Make sure to specify the correct device name.

Audio Input Recording

stream

Record audio from input device

ffmpeg -f alsa -i default output.wav
-f alsaALSA audio input (Linux)

Records audio from the default input device on Linux and saves it as a WAV file.

Multi-Bitrate HLS Stream

stream

Generate adaptive bitrate HLS streams

ffmpeg -i input.mp4 -map 0 -c:v libx264 -b:v:0 800k -s:v:0 640x360 -c:v:1 libx264 -b:v:1 1500k -s:v:1 854x480 -c:a aac -f hls -var_stream_map "v:0,a:0 v:1,a:0" -hls_segment_filename stream_%v/data%02d.ts -master_pl_name master.m3u8 stream_%v.m3u8
-mapSelect stream mapping
-var_stream_mapVariant stream mapping

Generates multiple HLS variants (360p and 480p) for adaptive bitrate streaming under different network conditions.

Generate DASH Stream

stream

Convert a video file to MPEG-DASH format

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f dash -window_size 5 -extra_window_size 5 -remove_at_exit 1 output.mpd
-f dashSet output format to DASH
-window_sizeSet segment window size

Converts an MP4 file to MPEG-DASH format for adaptive bitrate streaming.

Record RTSP Stream

stream

Record RTSP video stream

ffmpeg -i rtsp://server/stream -c copy output.mp4
-iRTSP stream input URL

Records an RTSP video stream and saves it as an MP4 file. Commonly used for IP cameras and surveillance systems.

HTTP Upload Streaming

stream

Stream or upload video to an HTTP endpoint

ffmpeg -i input.mp4 -c copy -f mp4 http://server/upload
-f mp4Set output container to MP4

Streams or uploads a video file to an HTTP server endpoint using POST requests.

Advanced Features

Picture-in-Picture (PiP)

advanced

Create a picture-in-picture overlay

ffmpeg -i main.mp4 -i pip.mp4 -filter_complex "[1:v]scale=iw/4:ih/4 [pip]; [0:v][pip] overlay=W-w-10:10" output.mp4
-filter_complexComplex filter graph
overlayVideo overlay filter

Creates a picture-in-picture effect by scaling the secondary video to 25% size and placing it in the top-right corner.

GPU-Accelerated Transcoding

advanced

Use GPU hardware acceleration for video encoding

ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc output.mp4
-hwaccelEnable hardware acceleration
-c:v h264_nvencNVIDIA H.264 hardware encoder

Uses NVIDIA GPU acceleration to significantly speed up H.264 video encoding.

Multi-Stream Composition

advanced

Process and combine multiple video streams

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][1:v]hstack=inputs=2" output.mp4
hstackHorizontal video stacking

Combines two video streams side by side. Use vstack for vertical stacking.

Timecode Overlay

advanced

Burn timecode into video frames

ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='%{pts\:hms}':x=10:y=10:fontsize=24:fontcolor=white" output.mp4
drawtextText rendering filter
%{pts\:hms}Presentation timestamp expression

Overlays SMPTE-style timecode in the top-left corner using hours:minutes:seconds format.

Edit Video Metadata

advanced

Modify container metadata fields

ffmpeg -i input.mp4 -metadata title="My Video" -metadata year="2023" output.mp4
-metadataSet metadata fields

Edits video container metadata such as title, year, and author.

Video Quality Analysis (PSNR)

advanced

Measure video quality using PSNR

ffmpeg -i compressed.mp4 -i original.mp4 -lavfi psnr -f null -
psnrPeak Signal-to-Noise Ratio filter

Compares compressed and source videos and outputs PSNR values to evaluate quality loss.

Bitrate Control (CRF + VBV)

advanced

Control quality and limit peak bitrate

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -maxrate 2M -bufsize 4M output.mp4
-crfConstant Rate Factor (quality control)
-maxrateMaximum bitrate

Uses CRF for quality-based encoding while applying VBV to cap peak bitrate.

Progressive to Interlaced

advanced

Convert progressive video to interlaced format

ffmpeg -i progressive.mp4 -vf "fieldorder=tff" interlaced.mp4
fieldorderField order filter

Converts progressive video to top-field-first interlaced format for broadcast workflows.

Frame Rate Conversion

advanced

Change video frame rate

ffmpeg -i input.mp4 -vf "fps=30" output.mp4
fpsFrame rate filter

Converts video to 30 FPS using frame duplication or dropping as needed.

Deblocking Filter

advanced

Reduce compression blocking artifacts

ffmpeg -i blocky.mp4 -vf "deblock" deblocked.mp4
deblockDeblocking filter

Reduces blocking artifacts caused by aggressive compression to improve visual quality.

Utility Tools

Batch Add Watermark

utility

Add the same watermark to all videos in a folder

for %i in (*.mp4) do ffmpeg -i "%i" -i watermark.png -filter_complex "overlay=10:10" "watermarked_%~ni.mp4"
for loopProcess multiple files in batch

Batch process all MP4 files in the folder and add a watermark to the top-left corner.

Batch Resize Videos

utility

Resize all videos in a folder to a unified resolution

for %i in (*.mp4) do ffmpeg -i "%i" -vf scale=1280:720 "resized_%~ni.mp4"
for loopProcess multiple files in batch

Resize all MP4 files to 1280x720 resolution, suitable for standardizing video specs.

Batch Extract Audio

utility

Extract audio from all videos in a folder

for %i in (*.mp4) do ffmpeg -i "%i" -vn -c:a libmp3lame "%~ni.mp3"
for loopProcess multiple files in batch

Batch extract audio from all MP4 files and save as MP3 format.

Batch Generate Thumbnails

utility

Generate thumbnails for all videos in a folder

for %i in (*.mp4) do ffmpeg -i "%i" -ss 00:00:05 -vframes 1 "%~ni_thumb.jpg"
for loopProcess multiple files in batch

Generate one thumbnail for each video at the 5-second mark.

Batch Video Compression

utility

Compress all videos in a folder to reduce file size

for %i in (*.mp4) do ffmpeg -i "%i" -c:v libx264 -crf 23 -c:a aac -b:a 128k "compressed_%~ni.mp4"
for loopProcess multiple files in batch

Batch compress all MP4 files using CRF 23 and 128 kbps audio to balance quality and file size.

Video Duration Analysis

utility

Get duration of all videos in a folder

for %i in (*.mp4) do ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "%i"
ffprobeFFmpeg media analysis tool

Use ffprobe to output the duration of each video, useful for calculating total runtime.

Export Video Metadata

utility

Export detailed video metadata to a file

ffprobe -v quiet -print_format json -show_format -show_streams input.mp4 > video_info.json
-print_format jsonOutput in JSON format

Export detailed format and stream information to a JSON file for further analysis.

Analyze Frame Information

utility

Analyze video frame types and timestamps

ffprobe -show_frames input.mp4
-show_framesDisplay frame-level information

Display detailed information for each frame, including frame type (I/P/B) and timestamps.

Analyze Bitrate Information

utility

Analyze bitrate and frame-level stream details

ffmpeg -i input.mp4 -vf "showinfo" -f null -
-vf showinfoShow detailed stream information

Analyze stream-level and frame-level information to inspect bitrate and encoding behavior.

Validate Video File

utility

Check video file integrity and compatibility

ffmpeg -v error -i input.mp4 -f null -
-v errorOnly display error messages

Validate video file integrity and compatibility. Only errors will be shown.

Common Scenarios & Application Examples

Explore the powerful applications of FFmpeg in real-world scenarios

Batch Video Format Conversion

Convert all MOV files in a folder to MP4 format while preserving original quality

for %i in (*.mov) do ffmpeg -i "%i" -c:v libx264 -crf 18 -c:a aac "%~ni.mp4"

Use a Windows batch loop to convert all MOV files. Commonly used for processing videos imported from cameras.

Generate Thumbnail Gallery

Extract frames from a video at regular intervals to create a thumbnail set

ffmpeg -i video.mp4 -vf "fps=1/60,scale=320:-1" thumbnails/thumb%03d.jpg

Extract one frame per minute, scale to 320px width (height auto-scaled), and save as a numbered image sequence.

Video Trimming and Merging

Extract clips from a long video or merge multiple videos

ffmpeg -i input.mp4 -ss 00:10:00 -to 00:15:30 -c copy clip.mp4

Use stream copy (no re-encoding) to quickly extract a clip from 10:00 to 15:30 while preserving original quality.

Rotate Video

Rotate a video by 90°, 180°, or 270°

ffmpeg -i input.mp4 -vf "transpose=1" output.mp4

Transpose options: 0 = 90° CCW + vertical flip, 1 = 90° CW, 2 = 90° CCW, 3 = 90° CW + vertical flip.

Optimized Video Compression

Optimize compression settings for the best quality-to-size ratio

ffmpeg -i input.mp4 -c:v libx264 -preset slower -crf 18 -c:a aac -b:a 128k output.mp4

Use the 'slower' preset for better compression efficiency. CRF 18 provides high quality, with 128 kbps audio bitrate.

?
?

Frequently Asked Questions

Common questions about FFmpeg usage

Q

How to convert video format using FFmpeg?

A

Use ffmpeg -i input.mp4 output.avi to convert between formats. FFmpeg automatically detects the format from file extension.

Q

How to reduce video file size with FFmpeg?

A

Use ffmpeg -i input.mp4 -crf 23 output.mp4. Higher CRF values mean smaller files but lower quality. Range is 0-51, default is 23.

Q

How to extract audio from a video using FFmpeg?

A

Use ffmpeg -i video.mp4 -vn -acodec copy audio.aac. The -vn flag disables video, and -acodec copy extracts without re-encoding.

Q

How to merge multiple videos with FFmpeg?

A

Create a file list, then use ffmpeg -f concat -i filelist.txt -c copy output.mp4 to concatenate videos without re-encoding.