4

How can I convert animated gif (with Alpha channel) to animated webp?

I stuck with transparent background, I can't figure out how to convert gif with transparent background to webP with transparent background, Its keep a 'trail' of the images,

ffmpeg -i test.gif animation.webp

For example, I want to convert this gif - https://i.stack.imgur.com/Ph2cv.jpg to webP,

The output for now is - https://media.giphy.com/media/UqevOuKr66xO04zRBa/giphy.gif

how can I achieve that using ffmpeg?

Nirel
  • 141
  • 1
  • 4

4 Answers4

3

to complement @abvarun226 answer:

use yuva420p instead of yuv420p to add alpha channel and keep transparency.

ffmpeg -i transparent.gif -vcodec webp -loop 0 -pix_fmt yuva420p transparent.webp

and to save time you can use the following bat to convert all files in your folder:

for %%i in (*.gif) do (ffmpeg.exe -i "%%i" -y -vcodec webp -loop 0 -pix_fmt yuva420p "%%~ni.webp")
Beerbill
  • 31
  • 1
2

I'm not sure if you were able to figure this one out, but I was able to get this to work by setting pixel format to yuv420p.

ffmpeg -i transparent.gif -vcodec webp -loop 0 -pix_fmt yuv420p transparent.webp
abvarun226
  • 121
  • 3
0

late reply, I know... But I had the same problem when I tried exporting a PNG image sequence to an animated WebP. I got "trails" from the previous frames shown through the alpha channel of the animated sequence.

I found the solution in this post from Stack Overflow: https://stackoverflow.com/questions/68987106/how-to-make-ffmpeg-convert-a-png-sequence-into-a-webp-sequence-instead-of-makin

Basically, instead of "-vcodec webp", use "-vcodec libwebp_anim"... And that's it, :D

-1

there is no problem convert that gif on my system, using compiled ffmpeg with all options enabled

--with-chromaprint --with-decklink --with-fdk-aac --with-game-music-emu --with-libbluray --with-libbs2b --with-libcaca --with-libgsm --with-libmodplug --with-librsvg --with-libsoxr --with-libssh --with-libvidstab --with-libvmaf --with-libxml2 --with-opencore-amr --with-openh264 --with-openjpeg --with-openssl --with-rtmpdump --with-rubberband --with-speex --with-srt --with-tesseract --with-two-lame --with-wavpack --with-webp --with-xvid --with-zeromq --with-zimg
warungman
  • 99
  • 1
  • What do you mean? what is the command? Unrecognized option '-with-chromaprint'. Error splitting the argument list: Option not found – Nirel Jun 26 '19 at 17:34
  • @Nirel thats compilaition option, not some ffmpeg command, you can find it here https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu – warungman Jun 28 '19 at 08:40
  • My point is your problem might be caused by missing dependency or compilation option, or maybe you should check your ffmpeg version using `ffmpeg --version`. Mine is on version 4.1.3 – warungman Jun 28 '19 at 08:43
  • Does the ffmpeg -i test.gif animation.webp command act like it should act in your machine? – Nirel Jun 28 '19 at 14:54
  • did you get this fixed? I'm struggling with the same issue @Nirel – mars Mar 29 '20 at 14:09
  • Nope, update me it works for you – Nirel May 26 '22 at 15:51