Create GIF from video using ffmpeg
18.02.2025After developing code for a new approach for handling parameters in FreeCAD I wanted to present it to other FreeCAD users to get some feedback. Of course, the code is still a prototype, but it is working and shows the intended workflow, so I wanted to know if other people also think something like this is useful.
To present it, I wanted to show a small video, but the forum only allows files up to 1MB. So I wanted to create a small GIF showing the essentials.
To capture the video from the FreeCAD window under Windows I used OBS Studio with the FreeCAD window as video source.
This way I got a Prototype.mkv
video showing the workflow.
Then I converted the video via ffmpeg to get the Prototype.gif
file:
ffmpeg -ss 2 -t 50 -i Prototype.mkv -vf "setpts=PTS/2,fps=1,crop=1547:1080:0:0,scale=1024:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 Prototype.gif
I applied filtering to get the file size down:
-ss 2
to skip the first two seconds-t 50
to convert the next 50 seconds, so the interval that is converted is [2;52] secondssetpts=PTS/2,fps=1
to make the GIF 2 times faster then the captured video and have 1 image per second in the GIFcrop=1547:1080:0:0,scale=1024:-1:flags=lanczos
to crop to the main window, scale the image down to 1024 pixels height to get a smaller file sizesplit[s0][s1];[s0]palettegen[p];[s1][p]paletteuse
to split the input to two virtual outputs s0 and s1, where s0 is used to generate the GIF color palette and s1 will use the generated GIF color palette-loop 0
to let the GIF loop indefinitely
Now I had everything to create a post in the FreeCAD forum.