Here's a quick memo on converting webp to png/jpeg with the ffmpeg command.
Introduction
Sometimes you need to convert images in WebP format to PNG or JPEG.
For example, images generated by DALL·E come in WebP format.
When I search online, many of the top results are promotional pages for corporate tools. I start to wonder if there's a simpler way.
Turns out, it’s very easy with the ffmpeg command, so here’s a quick note.
Note: This article was translated from my original post.
Convert WebP to PNG or JPEG Using ffmpeg
How to Do It
ffmpeg is a very well-known open-source tool used for processing images and videos.
You can install it using package managers like homebrew, or download the executable from the official site.
Converting a WebP file to PNG is easy.
Just specify the desired output file extension as shown below:
ffmpeg -i input.webp output.png
After the -i option, specify the name of the input WebP file. Then specify the output file name with the correct file extension.
To convert to JPEG, use a similar command:
ffmpeg -i input.webp output.jpg
Let’s try it out.
Try It
My environment: macOS with ffmpeg version 7.0.1.
$ ffmpeg -version ffmpeg version 7.0.1 Copyright (c) 2000-2024 the FFmpeg developers built with Apple clang version 15.0.0 (clang-1500.3.9.4)
First, here's the WebP image file we'll be using as input:
$ ls input.webp $ file input.webp input.webp: RIFF (little-endian) data, Web/P image, VP8 encoding, 100x100, Scaling: [none]x[none], YUV color, decoders should clamp
Now let's convert the WebP image to PNG:
ffmpeg -i input.webp output.png
After running the command, output.png was created:
$ ls input.webp output.png $ file output.png output.png: PNG image data, 100 x 100, 8-bit/color RGB, non-interlaced
Next, let’s generate a JPEG file:
ffmpeg -i input.webp output.jpg
The JPEG file was also created successfully:
$ ls input.webp output.jpg output.png $ file output.jpg output.jpg: JPEG image data, baseline, precision 8, 100x100, components 3
Conclusion
That was a quick memo on how to convert WebP images to PNG or JPEG using ffmpeg.
Hope this helps someone!
[Related Post]