6

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.sstatic.net/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
  • 161

4 Answers4

8

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")
3

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
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