5

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?

2
  • Hey, still got the same issue. please help
    – Nirel
    Commented Jun 11, 2019 at 18:43
  • did you find a solution?
    – mars
    Commented Mar 27, 2020 at 17:29

4 Answers 4

6

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")
2
  • Just tested this and it works. Commented May 31, 2022 at 22:44
  • Quality control: ffmpeg -i transparent.gif -quality 10 -vcodec webp -loop 0 -pix_fmt yuva420p transparent.webp Commented Dec 9, 2022 at 12:15
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
6
  • What do you mean? what is the command? Unrecognized option '-with-chromaprint'. Error splitting the argument list: Option not found
    – Nirel
    Commented Jun 26, 2019 at 17:34
  • @Nirel thats compilaition option, not some ffmpeg command, you can find it here trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
    – warungman
    Commented Jun 28, 2019 at 8: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
    Commented Jun 28, 2019 at 8:43
  • Does the ffmpeg -i test.gif animation.webp command act like it should act in your machine?
    – Nirel
    Commented Jun 28, 2019 at 14:54
  • did you get this fixed? I'm struggling with the same issue @Nirel
    – mars
    Commented Mar 29, 2020 at 14:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .