FFMPEG Cheatsheet

Here’s a quick cheatsheet I compiled over the years to quickly converting things using ffmpeg.

# Get Video Info
ffmpeg -i input.mp4 -hide_banner

# Preview or Test Video or Audio Files
ffplay input.mp4

# Basic Conversion
ffmpeg -i in.mp4 out.avi

# Remove Audio
ffmpeg -i input.mp4 -an mute-output.mp4

# Trim Video
ffmpeg -i input.mp4 -ss 00:01:54 -to 00:06:53 -c copy output.mp4

# Export Frames every 1 second
ffmpeg -i input.mp4 -vf fps=1 out%d.png

# Export Frames every 1 min
ffmpeg -i test.mp4 -vf fps=1/60 thumb%04d.png

# Extract Frames
ffmpeg -i input.mp4 -r 1 image-%03d.png

# Export Frames Between Range
ffmpeg -i in.mp4 -vf select='between(t,2,6)+between(t,15,24)' -vsync 0 out%d.png

# Cropping Videos
ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4

# Resize Video
ffmpeg -i input.mp4 -vf scale=1920:1080 output.mp4

# Concatenate Videos
ffmpeg -f concat -i file-list.txt -c copy output.mp4

# Speed Up Video
ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4

# Loop
ffmpeg -stream_loop 2 -i input.mp4 -c copy output.mp4

# Compress
ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4
ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4

# Convert to GIF
ffmpeg -i # -f gif - | gifsicle > #

# Convert to GIF
ffmpeg -i in.mov -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif

# Create Still from Video
ffmpeg -i ~/Downloads/### -r 1 -s 1920x1080 -f image2 ~/Desktop/video.jpeg

# Convert to Low Quality for Browser
ffmpeg -i %inputfile% -map 0:v -map 0:a -c:v libx264 -b:v 1500k -s 640x360 -ac 2 -bf 0 -y %outputfile%

# Multiformat low quality
-i %inputfile% -map 0:v -map 0:a -c:v mpeg2video -b:v 3500k -s 640x360 -y %outputfile% -ac 2 %outputfile%.mp4 -cpu-used 5 -deadline realtime %outputfile%.webm

# High Quality Encoding
ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4

# Watermark on HD video
ffmpeg -i %inputfile% -vf "movie=logo.png [watermark]; [in][watermark] overlay=1820:980 [out]" %outputfile%

# Watermark and resize
ffmpeg -i %inputfile% -i logo.png -filter_complex "scale=480:384, overlay=44:44" -s 480x384 -c:v libx264 -b:v 500k -y %outputfile%

# Trim a clip (the fast way)
ffmpeg -ss 00:00:10 -i %inputfile% -t 00:00:05 -codec copy -y %outputfile%

# Rotate 90 Clockwise
# 0 = 90CounterCLockwise and Vertical Flip (default)
# 1 = 90Clockwise
# 2 = 90CounterClockwise
# 3 = 90Clockwise and Vertical Flip
# "transpose=2,transpose=2" for 180
ffmpeg -i in.mov -vf "transpose=1" out.mov

# Download "Transport Stream" Video Streams
ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4

# Create a Video Slideshow from Omages
ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4