22
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 12 Jun 2025
22 points (95.8% liked)
Linux
8047 readers
785 users here now
A community for everything relating to the GNU/Linux operating system
Also check out:
Original icon base courtesy of lewing@isc.tamu.edu and The GIMP
founded 2 years ago
MODERATORS
Thank you for being you!
Please allow me to point you towards the relevant parts within its documentation; palettegen and paletteuse.
Together, they constitute -from what I can gather- the absolute minimal required to create a .gif with desirable qualities. As such, they will make their appearances within the following two commands that closely mirror the examples found in the documentation:
ffmpeg -i input.mp4 -vf palettegen palette.png
This generates a representative palette with 255 colors maximum from the video. Note that AFAIU the set of colors this can draw from is the same as the one used for gifs. Which will likely come into play when we try to understand why this works in the first place.
ffmpeg -i input.mp4 -i palette.png -lavfi paletteuse output.gif
This starts with converting the colors found in the original .mp4 to their closest counterparts found within the palette. Then, with converted colors, it's turned into a .gif. Note that AFAIU we've effectively eliminated the algorithm that would otherwise kick in to convert the .mp4's wide arrange of colors into the ones compatible with gif.
To be clear, I don't claim to understand why this actually works ๐ . But, combined, the above two commands do yield desirable gifs. Like, for example, the one found below.
Note that we can achieve the same with just a single command. For that, consider the command found below.
ffmpeg -i input.mp4 -vf "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
That would also be my conjecture.
Makes sense.