FFmpeg cheatsheet

FFmpeg: Video

11 common FFmpeg tasks.

Compress a video

Re-encode with H.264. Lower CRF means higher quality and a larger file; 23 is the default and 28 is smaller.

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

Compress with H.265

Encode with HEVC for smaller files. Add -tag:v hvc1 for Apple compatibility.

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

Resize a video

Scale to 1280 pixels wide and keep the aspect ratio. -2 keeps the height divisible by two.

ffmpeg -i input.mp4 -vf scale=1280:-2 output.mp4

Cut a section

Cut from 30 seconds for one minute. Placing -ss before -i seeks quickly; add -c copy to avoid re-encoding.

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

Change the frame rate

Set the output to 30 frames per second.

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

Speed up a video

Play at double speed, adjusting audio to match.

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" fast.mp4

Rotate a video

Rotate 90 degrees clockwise.

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

Crop a video

Keep a 640 by 360 area starting at x=100, y=50.

ffmpeg -i input.mp4 -vf crop=640:360:100:50 cropped.mp4

Overlay a logo

Place a PNG 10 pixels from the top right corner.

ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=W-w-10:10" output.mp4

Burn in subtitles

Draw subtitles permanently onto the picture.

ffmpeg -i input.mp4 -vf subtitles=subs.srt output.mp4

Join videos

Join files that share the same codecs, using a list file with lines like: file 'part1.mp4'.

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

Was this page helpful?