4
1
I'm trying to extract a GIF from an MP4 video file.
Now I have two modi with which I do this:
1) the regular one:
ffmpeg -t 7.7 -ss 00:22:53 -i video.mp4 -i palette.png -s 320x174 -filter_complex "fps=15" output.gif
which gives out a file, 1.6MB of size.
and 2)
ffmpeg -t 7.7 -ss 00:22:53 -i video.mp4 -i palette.png -filter_complex "fps=15,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
which gives out a way better looking, but 4.5MB (181% increase) big file. It uses a 16x16 palette file, which I created with
ffmpeg -y -t 7.7 -ss 00:22:53 -i video.mp4 -vf fps=15,scale=320:-1:flags=lanczos,palettegen palette.png
Now I can't quite see how 2 GIFs of the same fps, duration and resolution can have such a huge difference in size. My intuition would be, they should be the same. Why is there this difference? And is there any way to cut the size of 2) to the one of 1) without losing quality?
Thanks
1I don't think your first command makes use of the palette file. Create a palette image from the GIF created and compare it with the palette from the 3rd command. – Gyan – 2016-01-27T17:56:15.197
That is on purpose. The point is, that both use 2 different palettes of 256 colors (the first the standard one and the second a generated one), but differ hugely in size. – nfisher – 2016-01-27T18:32:04.967
Yes, fewer colors are used from the standard palette and they are repeatedly used, so LZW can compress it more effectively. With the tailored palette, use is more evenly spread across the 256 available choices.
– Gyan – 2016-01-27T18:52:25.640Imagine you wanted to make a GIF of a grayscale image with a 8 color palette. Palette A had black, white and 6 shades of red and blue. Palette B had a ramp from black to white. The GIF encoder will use only black and white from Palette A, so the compressor has to represent occurrences of two entries. From Palette B, all swatches will come in use in varying degrees. – Gyan – 2016-01-27T18:54:09.067
This may help: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
– slhck – 2016-01-28T08:12:06.190Mulvya, oh okay, that makes sense, thank you. – nfisher – 2016-01-28T13:58:03.463