[FFmpeg-user] Merging animated gif and mp3

Moritz Barsnick barsnick at gmx.net
Wed Apr 22 22:18:33 CEST 2015


Hi JJ,

On Wed, Apr 22, 2015 at 11:10:31 -0700, OldZepHead wrote:
> question, but I have searched this forum (and google) for a couple days and
> I cant find the answer

Well, you haven't googled enough. ;-)

And you didn't read (or post) your ffmpeg outputs. You should have
gotten a lot of error messages.

> ./ffmpeg -i Soundtrack.mp3 -i CombinedPics1.mp4 -filter_complex overlay=shortest=1 Merged_out1.mp4

For one, you used a filter without reading its documentation:
"Overlay one video on top of another."
You don't want to do that, so forget this.

> ./ffmpeg -i Soundtrack.mp3 -i CombinedPics1.mp4 -shortest=1 Merged_out1.flv

This does the opposite of what you want. It will make the result end
when the shorter file is over, in this case your video. It will never
make it loop.

> ./ffmpeg -i CombinedPics1.gif -loop_input -i Soundtrack.mp3 Merged_out1.mp4

This only works for image input sequences as handled by the image2
demuxer (the docs say so, btw), and that doesn't handle gifs, I guess.
But close! The option is deprecated though. See next:

> ./ffmpeg -i -loop 1 CombinedPics1.gif -i Soundtrack.mp3 Merged_out1.mp4

"-loop 1" is the supported syntax for the deprecated "-loop_input".
Same remark as above.

The wiki (and stackexchange) give good hints - my first two google
hits.
https://trac.ffmpeg.org/wiki/Concatenate#demuxer
See "You can also loop a video. This example will loop input.mkv 10
times".

Due to DTS/PTS issues, I couldn't directly use my animated GIF for an
arbitrary number of times. What did work was to convert the GIF to a
(non-looped) H.264 video in the first step, then to loop that using
"-c[:v] copy". More than one step, sorry, but successful.

I created the input file for the concat demuxer thus:
$ perl -e 'print "file animgif.mkv\n" x 10000' > animgif.txt
thereby looping the input video 10000 times, which makes it significantly
longer than the audio file I provided.

Then I created the complete video with audio thus:
$ ffmpeg -f concat -i animgif.txt -i audiofile.mp3 -map 0 -map 1 -c copy -shortest output.mkv

> Two thing's I've picked up on from this forum - 1) loop 1/ignore_loop don't
> act the same way is all ffmpeg builds,

I don't know what you're trying to say, except what I pointed out: One
flag is being replaced by another, more useful or intuitive one. They
do the same thing.

> and 2) the order of operations and encoding types matter greatly.

Absolutely.

Cheers,
Moritz


More information about the ffmpeg-user mailing list