Musings of a Fondue

FFmpeg Snippets

Batch scripts for useful FFmpeg actions. Posting for future reference. Perhaps others will also get use from them.

Crop a video and generate a gif
Useful when want to generate a gif from only a portion of the video.

@echo off


set src=yourVideo
set dest=yourOutput.gif

set width=
set height=
set x=
set y=

set palette=palette.png
set intermediate=temp.avi

rem Crop source
ffmpeg -i %src% -filter:v "crop=%width%:%height%:%x%:%y%" -c:v rawvideo %intermediate%

rem Gen gif
ffmpeg -i %intermediate% -vf palettegen -y %palette%
ffmpeg -i %intermediate% -i %palette% -lavfi paletteuse -y %dest%

Pad a video
Useful when want to achieve a given aspect ratio without rescaling.

set src=yourVideo
set dest=

set padColor=black
set targetWidth=
set targetHeight=
set curWidth=
set curHeight=

rem Should probably check that difference between target and current is even
set /a "x=(%targetWidth%-%curWidth%)/2"
set /a "y=(%targetHeight%-%curHeight%)/2"

ffmpeg -i %src% -vf "pad=width=%targetWidth%:height=%targetHeight%:x=%x%:y=%y%:color=%padColor%" -c:v rawvideo %dest%