This repository contains a demo implentation of a strict minimal file structure.
The RIFF container from WebP was not fully used. Some overhead can be reduced:
There are two ways of signaling a container value:
An image has the following chunks in order:
Chunk | Optional | Content | Coding |
---|---|---|---|
Header | No | Width/height etc. | Bit-packing |
ICC profile | Optional | Color space | VarInt chunk size + encoded bytes |
Preview | Optional | Image approximation | VarInt chunk size + encoded bytes |
Codec impl | No | Pixels | VarInt chunk size + encoded bytes |
XMP | Optional | Appended as is | VarInt chunk size + encoded bytes |
EXIF | Optional | Appended as is | VarInt chunk size + encoded bytes |
Being 10-byte long, the main header contains the most important information about the image, such as the format tag, width, height, orientation, has alpha, is animated, etc.
It uses bit-packing for easy encoding and decoding on top of providing a fixed header size.
All remaining data is stored sequentially in regular chunks, whether it is a preview, pixels, XMP etc. A chunk is preceded by its size encoded as a variable-length integer, limiting it to ~500 megabytes.
Work in progress. See container.h.
WrapContainer()
and UnwrapContainer()
functions can be used to encapsulate encoded pixels in any format into a minimal image container. EncodeRawPixels()
and DecodeRawPixels()
are just a convenient demo for a generic “codec”.
mkdir ../container_build && \ cd ../container_build && \ cmake -DCMAKE_BUILD_TYPE=Debug ../container && \ make && \ ctest .
AVIF is a MIAF/ISOBMFF wrapper around an OBU bitstream, which is itself usually made of a sequence header, a frame header and an AV1 tile group.
Stripping everything but the AV1 tile group and the necessary fields in the sequence and frame headers would produce lighter web image files:
Work in progress.
Start with an AVIF file (avifenc img.png -o img.avif -c aom
).
Convert from AVIF:
./convert img.avif -o img.pic
Convert back to AVIF:
./convert img.pic -o img.avif
Taken from https://aomediacodec.github.io/av1-spec.
Comparison between a minimal header (left) and a Sequence Header OBU (right):
Frame header OBU: