1
votes

I have a web application that converts any video into an animated GIF. The app runs in PHP and the following steps are executed through php's shell_exec:

  1. Scale video to smaller dimensions, if they are large (ffmpeg -i $in -s 200x150 -an $out)
  2. Use ffmpeg to extract 1 jpeg every x seconds (ffmpeg -i $in -ss $ss -vframes 1 $out)
  3. Convert jpegs to animated GIF using imagick (convert -delay $delay -loop 0 $dir/* $out)

    aside - the reason I don't use the ffmpeg gif89a output is because the quality sucks.

I want to be able to except any major image format, but the most common will probably be .flv (flash) and .avi/.mpg.

My application runs fine, but I am a perfectionist and it needs to be faster for scalability.

My web server has 16 cores and I would like to utilize them as much as possible, but .flv multi-threading appears to not be supported by ffmpeg, while .avi and some others are supported. Also, ffmpeg doesn't support multi-threading when outputting to jpegs.

Does anyone know of any other programs that support multi-threading for .flv and others? Are there any more efficient methods to create an animated GIF from video, while maintaining relatively decent quality (aka not the 100-color palette that ffmpeg supports)?

Also, if anyone knows which codecs might perform best for stages 1 and 2, particularly with flv, I'd love to know. I've done hours of testing, but there are just so many options I haven't come to any solid conclusions.

***Update: My online app is working well so far animated gif generator. I would still love to make it faster though, so if anyone has run into similar circumstances... let me know!

1

1 Answers

0
votes

you can convert it directly AFAIK

ffmpeg -i [input_video] output.gif

though you should probably add additional user parameters with sane defaults for frame rate, size etc... (otherwise the output will be huge) and to optimize the image even further you can use gifsicle

Edit: Ok, agreed that ffmpeg's gif encoding could use improvement - it could benefit most from adding a quantizer like:

http://www.ece.mcmaster.ca/~xwu/cq.c

Algorithm: Greedy orthogonal bipartition of RGB space for variance minimization aided by inclusion-exclusion tricks. For speed no nearest neighbor search is done. Slightly better performance can be expected by more sophisticated but more expensive versions.