0

How can multiple animated GIFs be converted to video?

I use this command to convert 1 animated gif to video:

ffmpeg -i aa0012.gif -crf 12 output.mp4

This is a more complex command to control the dimensions of the converted GIF:

ffmpeg -i aa0012.gif -vf "scale=min(1920/iw\,1920/ih)*iw:min(1920/iw\,1920/ih)*ih,pad=1920:1920:(1920-(min(1920/iw\,1920/ih)*iw))/2:(1920-(min(1920/iw\,1920/ih)*ih))/2" -c:v libx264 output.mp4

I've tried using:

-pattern_type glob -i '*.gif'

Which works for most image files, but when I try if with GIFs it returns the error "*.gif: No such file or directory"

  • multiple gifs into one video? or multiple gifs into multiple videos? converting gifs into HD video? – Logman Sep 29 '14 at 1:53
  • your error "No such file or directory", probably need to define the full path or set the current working directory. – Logman Sep 29 '14 at 1:55
  • I mean multiple gifs into 1 video. But both options would be nice if you know both solutions. I'm not converting them into HD video,but use that command to archive images to video. – dmm Sep 29 '14 at 2:07
  • Since I have the terminal Cd'ed into the folder which has the gifs shouldn't that cancel out the need to define the path? – dmm Sep 29 '14 at 2:09
  • "I mean multiple gifs into 1 video." -> are all the gifs then same resolution? Properties? Colors? that could be causing the problems – Logman Sep 29 '14 at 2:36
3

Animated GIFs are handled differently from normal "images". In fact, they're more like actual videos. That's why you can't use the image demuxer (i.e., can't use the -pattern_type option) there.

What you need to do is convert each one individually to an intermediate file with the same properties, then concatenate those.

ffmpeg -i gif1.gif -vf "…" -r 25 -c:v ffv1 output1.avi
ffmpeg -i gif2.gif -vf "…" -r 25 -c:v ffv1 output2.avi
…
ffmpeg -i "concat:output1.avi|output2.avi" -c:v libx264 output.mp4
  • Thanks! I tested it and it works. But I changed ffv1 to libx264, as the file size was too large with the ffv1 option. I wonder if a bash script could be created to convert multiple GIFs, using your command. – dmm Sep 29 '14 at 17:35
  • If you use libx264 instead of FFV1, then you will do two lossy encodes. This isn't recommended, since you'll lose quality. If you want to stay with libx264, then for the intermediates, choose -c:v libx264 -preset ultrafast -crf 18. This certainly can be automated with bash… – slhck Sep 29 '14 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.