3

Let's say I have an 8 frame animated GIF that is 2 seconds long. I would like to build a video file (codec not important at this point) that is 30 seconds long that consists of the source GIF repeating over and over.

Is it possible to do this using only ffmpeg? Answers that use convert or some other pre-processing utility do not count [The reason being that I would like to use this on PandaStream, which does not have that utility]. Let's also assume that shell scripts are out of the question as well, though it can be multiple ffmpeg commands.


Things I have tried that did not work (though maybe I did them wrong, I'm not terribly familiar with ffmpeg):

  1. Using the -loop_input, -loop_output options present in the ffmpeg docs. Using both ffmpeg 1.2 and 2.0, I get a Unrecognized option 'loop_[input|output]' error message. I might be using this wrong though since the error is about not recognizing the option, though the docs say it is deprecated.

  2. -loop option. Does not seem to do anything with GIF -> Video. I think this flag and the above flag are related to generating animated GIFs as the output.

  3. Concat. Doing something like:

    ffmpeg -i "concat:image.gif|image.gif|image1.gif|image2.gif|image3.gif|image4.gif" image-long.gif

    Results in a 16 frame gif (so two gifs are concatenated) which is progress, though the output gif is of much lower quality.


I'm a bit at my wits end here (I have tried many other permutations of the above concepts), I'm at the point now of 'poking it with a stick', hopefully someone out there has done this!

Thomas Graft
  • 431
  • 3
  • 11

1 Answers1

8

Is it possible? Yes.

Looking at How to concatenate (join, merge) media files, we can take the gif and transcode to mpeg streams (you could copy the first one twice):

ffmpeg -i image.gif -f mpegts image1.ts
ffmpeg -i image.gif -f mpegts image2.ts
ffmpeg -i image.gif -f mpegts image3.ts

then concatenate them, outputting as a gif

ffmpeg -i "concat:image1.ts|image2.ts|image3.ts" -pix_fmt rgb24 output.gif

Starting with an mp4 or similar seems to give better results; replace the first step with

ffmpeg -i image.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts image1.ts

and repeat for the other copies.

I create multiple copies of the same because if I try to concat: the same file multiple times (concat:image1.ts|image1.ts|image1.ts) it doesn't work.

Enjoy

andy256
  • 2,821
  • 2
  • 13
  • 19