FFmpeg Cheat Sheet
November 15, 2018 • 5 minutes read

FFmpeg cheat sheet. Most helpful commands/options to use with FFmpeg

Screenshots from the screen

make png screenshot

ffmpeg -f x11grab -s 1920x1080 -i :0.0 -vframes 1 -y screenshot.png

make png screenshot of the 2nd monitor (right of the left one)

ffmpeg -f x11grab -s 1920x1080 -i :0.0+1920 -vframes 1 -y screenshot.png

Video post-processing

get all frames from each second of the video. Be careful command will generate a lot of jpg files!

ffmpeg -i test.mpg image%d.jpg

the same command but with some options:

-r 1 - how many frames to get from each second

-ss 00:00:10 - start from 10 second

-t 00:00:05 - get frames for 5 seconds of the video

ffmpeg -i test.mpg -r 1 -ss 00:00:10 -t 00:00:05 image%d.jpg

get a part of the video file. Get 2 minutes 25 seconds starting from 3rd second

ffmpeg -ss 00:00:03 -t 00:02:25 -i video.mp4 cut.mp4

get an audio in mp3 format from the video record

ffmpeg -i video.avi -f mp3 audio.mp3

mix a sound file to the video file

ffmpeg -i son.wav -i video_original.avi video_finale.mpg

Demo videos

grab FullHD video from desktop screen

ffmpeg -f x11grab  -r 30 -s 1920x1080 -i :0.0 -vcodec libx264 -threads 0 -y demo.mkv

-i :0.0 - source, your display. You can get connected displays with the command:

printenv DISPLAY

or

xrandr --query

grab FullHD video from desktop screen + audio from microphone

ffmpeg -f alsa -i pulse  -f x11grab  -r 30 -s 1920x1080 -i :0.0 -acodec ac3 -vcodec libx264 -threads 0 -y demo_with_audio.mkv

grab video from desktop screen starting with the upper-left corner at x=50, y=30 with a width and height of 1870x1050

ffmpeg -f x11grab  -r 30 -s 1870x1050 -i :0.0+50,30 -vcodec libx264 -threads 0 -y demo_capture_a_part.mkv

Conversion

get details about your video/audio file

ffprobe -loglevel quiet -show_format your_video_or_auido_file.mp4 

convert wav audio file to mp3

ffmpeg -i my_audio.wav  my_audio.mp3

convert jpg images to video file

ffmpeg -f image2 -i img%d.jpg  a_video_file.mpg

convert .avi video file to animated gif (uncompressed)

ffmpeg -i video_origine.avi gif_anime.gif

convert video file to 320x240 with 300 kbps

ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4

Time-lapse

build Time-lapse video from images

render to fast video

ffmpeg -pattern_type glob -i '*.JPG' -r 30 -c:v libx264 -crf 23 -preset fast -pix_fmt yuv420p timelaps_fast.mp4

render to slow video

ffmpeg -pattern_type glob -i '*.JPG' -r 30 -c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p timelaps_slow.mp4
Last update September 11, 2023
Cheat Sheet ffmpeg
Do you have any questions?

Contact Me