Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ffmpeg commands reminder

Convert video with x264 encoder

ffmpeg -i input -c:v libx264 -crf 23 -maxrate 1M -bufsize 2M output.mp4

0<crf<51 (default: 23) (lossless: 0)

To only change video bitrate/quality but keep audio :

ffmpeg -i input.avi -c:v libx264 -b:v 720k -crf 33 -c:a copy output.mkv

Easy way --> choose a preset

ffmpeg -i input.mp4 -c:v libx264 -preset superfast output.mp4

Optimize video for fast streaming :

ffmpeg -i INPUT.mp4 -c copy -movflags +faststart STREAMABLE_OUTPUT.mp4

Get video file informations

ffmpeg -i video.flv -hide_banner

Split video to images

ffmpeg -i video.flv image%d.jpg

Extract mp3 from video

ffmpeg -i video1.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio3.mp3

other links :

ffmpeg official website :

Hardware acceleration :

List availables : ffmpeg -hwaccels -hide_banner

Recommended for decoding : ffmpeg -hwaccel d3d11va

List available codecs : ffmpeg -codecs

Recommended NVidia accelerated codec : ffmpeg -i input -v:c h264_nvenc output

Fast lossless optimization :

ffmpeg -hwaccel d3d11va -threads 16 -i input -c:v h264_nvenc -rc:v vbr_hq -cq:v 19 -b:v 5000k -maxrate:v 12500k -profile:v high output

Using ffmpeg Filters


Concatenate videos

For video only (w/o audio)

ffmpeg -i 1.mp4 -i 2.mp4 ---filter_complex "[0:0][1:0]concat=n=2:v=1:a=0" 1and2.mp4

For both, video and audio

ffmpeg -i 1.mp4 -i 2.mp4 ---filter_complex "[0][1]concat=n=2:v=1:a=1" 1and2.mp4

Sometimes it's necesary to change SAR to 1:1, just use setsar=1 filter.

Crop a rectangle inside a video

ffmpeg -i full.mp4 -filter:v 'crop=width:height:x:y' cropped.mp4

Transform a vertical video (smartphone) to horizontal video with blur

9:16 --> 16:9

Using ffmpeg filters. 1st, split videos, crop and blur the background from original, then overlay original and rescale

Dot notation :

 input --> split -------------------------------> overlay --> output
        │                                          ^
        │[copy]                           [blurred]│
        └──────> crop ──> scale ──> gblur ─────────┘

Source :

ffmpeg -i vertical.mp4 -vf 'split[original][copy];[copy]scale=ih*16/9:-1,crop=h=iw*9/16,gblur=sigma=20,eq=brightness=-0.1[blurred];[blurred][original]overlay=(W-w)/2:(H-h)/2,scale=1920:1080' horizontal.mp4

Note : CPU intensive !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.