Page 1 of 1

How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T15:49:33-07:00
by LedZeppelin
I'm using a youtube downloader to download music videos in the MP4 container, encoded in H.264 with a bitrate of about .5Mbit/s

I'm currently exporting videos to frames using ffmpeg then converting those images to gifs using imagemagick

Code: Select all

ffmpeg -i video.mp4 -r 6 -t 5 frames/ffout%03d.png

Code: Select all

convert -delay 10 -loop 0 frames/ffout*.png output.gif
Instead of using .pngs as the images, I also tried using .gifs

Code: Select all

ffmpeg -i video.mp4 -r 6 -t 5 frames/ffout%03d.gif

Code: Select all

convert -delay 10 -loop 0 frames/ffout*.gif output.gif
I feel the file sizes are way too big for the quality. The above samples rendered a 2.8MB for the gif based of the png images and 1.6MB for the gif based off the gif images.

What option should I use to lower the file size? I tried setting

Code: Select all

-colors
to values that were powers of two. Are there any other options I can adjust to exchange quality for file size?

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T15:54:40-07:00
by fmw42
Gifs are limited to -colors less than or equal to 256. You do not have to use powers of 2. see the sections on GIF at http://www.imagemagick.org/Usage/formats/#gif

You could also define a fixed color palette image and recolor (all) your image using that common palette. See http://www.imagemagick.org/Usage/quantize/#remap

You could convert to 8-bit palette png and use some other tools such as pngcrush to reduce the file size. See the sections on PNG at http://www.imagemagick.org/Usage/formats/#png_non-im

What is wrong with just using JPG and compressing as desired?

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T16:15:17-07:00
by LedZeppelin
What is wrong with just using JPG and compressing as desired?
I tried the following (saving to jpg), but the results weren't satisfactory. The size was way high.

Code: Select all

$ ffmpeg -i video.mp4 -r 6 -t 5 frames/ffout%03d.jpg
$ convert -delay 10 -loop 0 frames/ffout*.jpg output.gif
Do you know how I could achieve this compression you mentioned? Do I do it through ffmpeg when I take the snapshots, or is there an option I can set in image magick?

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T16:22:28-07:00
by fmw42
convert your images from ffmpeg to png. then convert the pngs to GIF using the -colors or -remap option if you want an animated gif.

ffmpeg -i video.mp4 -r 6 -t 5 frames/ffout%03d.png
convert -delay 10 frames/ffout*.png -colors XX -loop 0 output.gif

or

ffmpeg -i video.mp4 -r 6 -t 5 frames/ffout%03d.png
convert -delay 10 frames/ffout*.png -dither none -remap paletteimage -loop 0 output.gif

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T16:24:58-07:00
by LedZeppelin

Code: Select all

convert your images from ffmpeg to png. then convert the pngs to GIF using the -colors or -recolor option if you want an animated gif.
Sorry for my ignorance, but isn't this exactly what I did before?

Code: Select all

ffmpeg -i video.mp4 -r 6 -t 5 frames/ffout%03d.png

Code: Select all

convert -delay 10 -loop 0 -colors 256 frames/ffout*.png output.gif

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T16:26:57-07:00
by fmw42
yes, but I am not sure what values for -color you used or if you tried the -remap option with a common fixed palette.

I missed the fact that you were making an animated gif when I suggested using jpg. I was only focusing on the compression/quality vs file size issue. Sorry for my mistake.

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T16:29:35-07:00
by LedZeppelin
I see. I tried 256, 128, 62, 32, 16 as arguments to -colors. I think I'll stick with my original approach and possible -remap to my own pallette later. Thanks for your help :D

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T16:31:57-07:00
by fmw42
LedZeppelin wrote:I see. I tried 256, 128, 62, 32, 16 as arguments to -colors. I think I'll stick with my original approach and possible -remap to my own pallette later. Thanks for your help :D
the number of colors is not limited to powers of two. any value between 1 and 256 is fine, though too low would be unacceptable results.

Re: How to lower file size of gifs from youtube videos?

Posted: 2013-07-22T17:02:21-07:00
by LedZeppelin
I understand it's not limited to powers of two as you mentioned previously.

Thanks for the follow up clarification.