8

I would like to convert an animated WebP file to a WebM. However, most tools only support converting to an animated WebP but not back, when they support animated WebPs at all: ImageMagick's convert does not support animated WebP, ffmpeg does not support animated WebP, and webpmux only supports extracting a single frame at a time (as far as I can tell).

How can I go about making that conversion?

2
  • FWIW, ImageMagick 6.9.11-60 seems to support converting animated WebP to frames without issue: identify ./example.webp to see the frames, then convert ./example.webp ./example%04d.png.
    – wchargin
    Dec 25, 2023 at 20:03
  • @wchargin Thanks for the tip. I just tried using this method and found that convert (v. 6.9.12-98) produced corrupt frames for an example image whereas anim_dump produced the correct result. Dec 27, 2023 at 5:48

1 Answer 1

11

Since there does not appear to be any widely-supported way to do it yet:

  1. Install the anim_dump example utility from libwebp, since it is not included in the webp package.
    1. Clone the repo:git clone https://chromium.googlesource.com/webm/libwebp && cd libwebp.
    2. Force make to build anim_dump: echo "bin_PROGRAMS += anim_dump" >> examples/Makefile.am.
    3. Install libwebp: ./autogen.sh && ./configure && make && sudo make install.
    4. Add /usr/local/lib to your linker path: echo "/usr/local/lib" |sudo tee -a /etc/ld.so.conf&& sudo ldconfig. Without this, anim_dump will not run.
  2. Extract the WebP frames to PNGs using anim_dump. mkdir frames && cd frames && anim_dump ../example.webp && cd ...
  3. Figure out the framerate of the video using webpmux: webpmux -info ../example.webp. Use about the average duration of the WebP frames as your WebM framerate. If your WebP does not use a consistent framerate, you'll have to manually deal with the durations somehow.
  4. Create a WebM using ffmpeg: ffmpeg -framerate <my-framerate> -i frames/dump_%04d.png example.webm
  5. Clean up: rm -r frames/.
0

You must log in to answer this question.

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