FFmpeg cheatsheet

Common and useful ffmpeg commands. Go back to Eruhinim.

FFmpeg commands

Basic video/audio format conversion

ffmpeg -i input.webm output.mp4

You can put any video/audio file extension for the input and output. FFmpeg will do it's best to guess what to do.

Extract audio from a video file

ffmpeg -i input.webm -vn output.mp3

You can put any video/audio file extension for the input and output. FFmpeg will do it's best to guess what to do.

Take a sample from a video url/local file

ffmpeg  -ss 00:00:10 -i https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_5mb.mp4 -t 00:00:20 -async 1 -strict -2 output.mp4

Where:

  • -ss 00:00:10 -- means capture from the 10th second.
  • -i url/local file -- the input. Can be a url or a local file.
  • -t 00:00:20 -- duration of the sample.

Really useful if you don't want to download an entire video, but just a sample.

Screen grab of the current desktop area

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1366x768 -i :0.0 -threads 4 -y output.webm

Where:

  • -r 30 -- frame rate
  • -s 1366x768 -- resolution of your screen.
  • -i :0.0 -- X screen identifier. This is the default one.

It will record the screen together with audio and produce a output.webm as a result.

Webcam recording

ffmpeg -f alsa -i /dev/audio -f video4linux2 -s 1280x720 -i /dev/video0 output.mp4

Where:

  • -f alsa -i /dev/audio -- audio driver and default audio device.
  • -s 1280x720 -- resolution that your webcam records in.
  • -i /dev/video0 -- webcam device

Records webcam with mic and outputs to a mp4 file.

Change the resolution of a video file

ffmpeg -i input.avi -s 320x240 -c:a copy output.mp4

Where:

  • -s 320x240 -- desired resolution

Make a GIF from a video file

$ ffmpeg -i video.mp4 -r 5 'frames/frame-%03d.jpg'
$ convert -delay 20 -loop 0 frames/*.jpg myimage.gif

Where:

  • -r 5 -- frame rate. Capture every 5th frame.
  • 'frames/frame-%03d.jpg' - dumps the frames in jpg format like frame-001.jpg, etc.
  • -delay 20 -- display the next image after pausing.
  • -loop 0 -- loop GIF.