FFmpeg Commands Guide

How to Add Multiple Videos into One Video

ffmpeg -f concat -i list.txt -c copy out.mp4

list.txt:

file 'video1.mp4'
file 'video2.mp4'

How to Record Screen

ffmpeg -framerate 20 -f x11grab -s 1366x768 -i :0.0+0,0 -f alsa -i hw:0 out.mkv

How to Record Screen Without Audio

ffmpeg -framerate 20 -f x11grab -s 1366x768 -i :0.0+0,0 out.mkv

How to Convert MP4 to MP3

ffmpeg -i video.mp4 -f mp3 -vn audio.wav

How to Remove Audio from a Video

ffmpeg -i video.mp4 -c:v copy -an out.mp4

How to Extract Audio from a Video

ffmpeg -i video.mp4 -vn audio.wav

How to Merge Video and Audio

ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4

How to Cut Video or Audio

ffmpeg -i input.mkv -ss 00:03:00 -to 00:03:44 -async 1 cut.mkv
ffmpeg -i input.mp4 -ss 01:43:46 -to 00:44:30 output.mp3

Use -t to cut specific duration, e.g., 03:44 minutes.

How to Download Multiple Videos Simultaneously using youtube-dl

To simulate and see the resolution:

youtube-dl -ct --simulate --batch-file='/path/to/batch-file.txt'

To download:

youtube-dl -ct --batch-file='/path/to/batch-file.txt'

How to Double the Speed of the Video with setpts Filter

ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv

0.5 => fast, 1.0 => slow

How to Enhance Video Quality

ffmpeg -i input.mkv -vf scale=1920:1080 -preset slow -crf 18 output.mp4

How to Create a Video Grid

ffmpeg \
   -i arch.mkv \
   -i artix_dinit.mkv \
   -i artix_runit.mkv \
   -i artix_s6.mkv \
  -filter_complex " \
	  [0:v] setpts=PTS-STARTPTS, scale=hd1080 [a0]; \
	  [1:v] setpts=PTS-STARTPTS, scale=hd1080 [a1]; \
	  [2:v] setpts=PTS-STARTPTS, scale=hd1080 [a2]; \
	  [3:v] setpts=PTS-STARTPTS, scale=hd1080 [a3]; \
	  [a0][a1][a2][a3]xstack=inputs=4:layout=0_0|0_h0|w0_0|w0_h0[out] \
	  " \
	-map "[out]" \
	-c:v libx264 -t '55' -f matroska out.mkv

How to Lower the Audio In and Out

To lower the audio at the start:

ffmpeg -i input.mp3 -af "afade=in:st=0:d=5" output.mp3

To lower the audio at the end:

ffmpeg -i input.mp3 -af "afade=out:st=0:d=5" output.mp3

How to Extract Frames from a GIF

ffmpeg -i input.gif -r 10 output_%03d.png