Combine Audio and Gif into a video while preserving transparency using ffmpeg

1

I'm trying to combine an audio file and a gif into a video and I'm running into some issues despite trying quite a few solutions over Stack Overflow.

I would like the combined file duration to match the audio's, as well as preserve the GIF transparency.

  • The audio file duration is 00:00:17.53
  • The Gif file duration is 00:00:00.40, it is transparent.

I managed to combine them but the duration I get is quite wrong and transparency is lost with the following command:

ffmpeg -i input.mp3 -ignore_loop 0 \
-i input.gif -movflags +faststart \
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
-shortest -strict -2 \
-c:v libx264 -c:a aac -b:a 192k -b:v 2M -pix_fmt yuv420p output.mp4

The resulting video's duration is 00:00:24.21

  1. Is there anyway to get the output duration right without having to use -t 00:00:17.53 option?
  2. I tried converting using other codecs such as libvpx-vp9 but I couldn't get the transparency right, is there any other codec I must use?

Edit: I managed to generate a transparent video (webm format) using the following command:

ffmpeg -i source.mp3 -ignore_loop 0 -i source.gif -c:v libvpx -pix_fmt yuva420p -auto-alt-ref 0 -t 00:00:17.53

However my first question about the duration not being automatically right still stands.

Dimitri

Posted 2019-12-10T17:05:57.397

Reputation: 111

Show the full log from the second command. – llogan – 2019-12-11T19:12:21.447

No answers