Introduction
WebP stores a picture for the web in as few bytes as possible, either lossy (close to the
original but not exact, like JPEG) or lossless (exact, like PNG), and it can also hold
transparency, a colour profile, camera and descriptive metadata and an animation of several
frames (like GIF). A .webp file is a RIFF container of chunks. The lossy mode
codes the picture as a single key frame of the VP8 video codec; the lossless mode is a
predictive format of its own.
The pages here describe every chunk and bitstream well enough to write a reader.
Container and chunks is the place to start; the explorer
reads all of it: drop a .webp file on this page to see its chunks, the fields of its
frame headers or transforms, and the decoded picture or animation.
Structure
A WebP file is a RIFF container: the bytes RIFF, a 4-byte little-endian
size of the rest of the file and the form type WEBP. One or more chunks
follow, each a 4-character ID, a little-endian size and the data, padded to an even
length.
A simple lossy image has a single VP8 chunk (with a trailing space), and
a simple lossless image a single VP8L chunk. The extended format starts with
a VP8X chunk of flags and the canvas size, and may add ICCP
(colour profile), ALPH (alpha for a lossy image), ANIM and
ANMF (animation and its frames), EXIF and XMP .
0RIFF header, size, form typeWEBP12 bytes12VP8X flags and canvas size, extended format only18 bytes…ICCP, ANIM … optional chunksvaries…VP8 or VP8L the image, or ANMF framesvaries…EXIF, XMP optional metadatavaries
In this reference
- Container and chunks – the RIFF header, the three layouts, VP8X and its flags, ICCP, EXIF, XMP and chunk order
- Animation – ANIM, ANMF, disposal, blending and building the canvas
- Alpha – the ALPH chunk, its filters and compression
- Lossy (VP8) – the frame header, macroblock modes, coefficient tokens, dequantisation, transforms, prediction, loop filter and colour conversion
- Lossless (VP8L) – the header, transforms, predictors, prefix codes, backward references and colour cache
Not described
The pages follow the container and lossless specifications, RFC 9649, and the VP8 data format, RFC 6386. The explorer’s
decoders give the same pixels as libwebp’s dwebp on every test file, and the same animation frames as
libwebp’s animation decoder. These gaps remain.
Known, not yet covered
- Viewer: a
VP8orVP8Lchunk of any size is read through a window of the file (the decoders take 256 KiB at a time), so it decodes in bounded memory. Pictures too large to send whole are shown in bands of rows (the First row option moves the band); every band is decoded from the top of the picture, one row at a time, because prediction and the entropy decoder run from there, so a band near the bottom of a very large image takes as long as the whole image (about 30 seconds for 268 megapixels). A lossy chunk over 1 GiB has been tested only with the real data at its start and zeros after it, and the boolean decoder alone at offsets past 3 GB, since no picture needs a gigabyte of coefficients. - Viewer: an
ALPHchunk is still read into memory whole (at most 268 MB for a raw plane of the largest image). - Viewer: the colour profile is opened by the ICC viewer, and Exif and XMP by the TIFF and XML viewers, as files of their own; the picture is not colour-managed.
Unknown
- Reference: the lossless predictor modes 14 and 15 are not defined by the specification; the page gives what libwebp does with them (lossless).
Links
Software
- GIMP – free image editor that opens and saves WebP (Windows, macOS, Linux)
- Adobe Photoshop – Adobe’s image editor, which opens and saves WebP in current versions (Windows, macOS)
- Paint.NET – free image editor that opens and saves WebP (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert to and from WebP (Windows, macOS, Linux)
- Squoosh – Google’s image compressor that runs in the browser (web)
- Google Chrome – web browser; every current browser displays WebP (Windows, macOS, Linux, mobile)
Developers
Reference
- RFC 9649 – WebP Image Format, the IETF specification
- WebP Container Specification – Google’s description of the RIFF container and its chunks
- WebP Lossless Bitstream Specification – Google’s description of the VP8L format
- RFC 6386 – VP8 Data Format and Decoding Guide, which defines the lossy bitstream