Cheatsheet: ffmpeg

Last updated 2026-06-21

Inspect media

List streams, codecs, duration, bitrate, and container metadata with ffprobe.

ffprobe -hide_banner -i input.mp4

Show machine-readable stream information as JSON.

ffprobe -v error -show_format -show_streams -of json input.mp4

Print only the video resolution.

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4

Convert and encode

Convert from .mov to .mp4 using H.264 video and AAC audio for broad compatibility.

ffmpeg -i video.mov -c:v libx264 -c:a aac -pix_fmt yuv420p output.mp4

Change only the container when streams are already compatible; this is fast because it does not re-encode.

ffmpeg -i input.mkv -c copy output.mp4

Encode H.265/HEVC video with AAC audio.

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -c:a aac output.mp4

Control video quality with CRF; lower values are larger and higher quality, commonly 18-28 for H.264.

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac output.mp4

Change video bitrate and audio bitrate explicitly.

ffmpeg -i input.mp4 -b:v 2500k -b:a 128k output.mp4

Use two-pass encoding for a target average bitrate.

ffmpeg -y -i input.mp4 -c:v libx264 -b:v 3000k -pass 1 -an -f mp4 /dev/null && ffmpeg -i input.mp4 -c:v libx264 -b:v 3000k -pass 2 -c:a aac -b:a 128k output.mp4

Use NVIDIA hardware encoding when available.

ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc -preset p5 -cq 23 -c:a copy output.mp4

Use Apple VideoToolbox hardware encoding on macOS when available.

ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 4000k -c:a aac output.mp4

Resize, crop, and frame rate

Resize to an exact width and height.

ffmpeg -i input.mp4 -vf scale=1280:720 -c:a copy output.mp4

Resize to 720p while preserving aspect ratio; -2 chooses an even width required by many codecs.

ffmpeg -i input.mp4 -vf scale=-2:720 -c:a copy output.mp4

Crop to a centered 1080x1080 square.

ffmpeg -i input.mp4 -vf "crop=1080:1080:(in_w-1080)/2:(in_h-1080)/2" output.mp4

Change output frame rate to 30 fps.

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

Pad video to 1920x1080 with black bars while preserving the original aspect ratio.

ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output.mp4

Trim, concatenate, and images

Trim a clip from 00:01:00 for 30 seconds, re-encoding for accurate cuts.

ffmpeg -ss 00:01:00 -i input.mp4 -t 00:00:30 -c:v libx264 -c:a aac clip.mp4

Fast trim without re-encoding; cuts may align to nearest keyframe.

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

Concat file format for the concat demuxer.

file 'file1.mp4'
file 'file2.mp4'
file 'file3.mp4'

Concatenate videos from a text file without re-encoding when codecs, time bases, and dimensions match.

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4

Concatenate videos from a list but re-encode to avoid codec mismatch glitches.

ffmpeg -f concat -safe 0 -i mylist.txt -c:v libx264 -c:a aac output.mp4

Create a GIF from a video segment with palette generation for better colors.

ffmpeg -ss 00:00:05 -t 3 -i input.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

Extract one image frame every second.

ffmpeg -i input.mp4 -vf fps=1 frames/frame_%04d.jpg

Extract a screenshot at a specific timestamp.

ffmpeg -ss 00:01:52 -i input.mp4 -frames:v 1 -q:v 2 output.jpg

Convert one image into a 30 second video.

ffmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4

Add N seconds to the end of the video by cloning the last frame.

ffmpeg -i input.mp4 -vf tpad=stop_mode=clone:stop_duration=60 out.mp4

Audio and subtitles

Combine a video-only file and an audio file, copying streams when compatible.

ffmpeg -i video.mp4 -i audio.mp3 -c copy -map 0:v:0 -map 1:a:0 output.mp4

Extract audio as MP3.

ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3

Extract the original audio stream without re-encoding.

ffmpeg -i input.mp4 -vn -c:a copy audio.m4a

Remove all audio from a video.

ffmpeg -i input.mp4 -c:v copy -an muted.mp4

Replace a video's audio with a separate audio file and stop at the shorter input.

ffmpeg -i input.mp4 -i music.m4a -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac -shortest output.mp4

Adjust audio volume to 50 percent.

ffmpeg -i input.mp4 -filter:a "volume=0.5" output.mp4

Generate a silent audio file.

ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000 -t 1 silence.mp3

Burn subtitles into the video frames using an SRT file.

ffmpeg -i input.mp4 -vf subtitles=subtitles.srt -c:a copy output.mp4

Add soft subtitles as a selectable track without burning them into the picture.

ffmpeg -i input.mp4 -i subtitles.srt -c copy -c:s mov_text output.mp4

See also: