AV1 Image File Format
image/avif
Magic Bytes
Offset: 4
66 74 79 70 61 76 69 66
The AV1 Image File Format (AVIF) is an open, royalty-free image specification maintained by the Alliance for Open Media. It leverages the AV1 video codec to provide efficient storage for web-based graphics, photography, and animated sequences. As a contemporary format supported by major web browsers, it is considered safe for general use, though decoders must be kept updated to mitigate potential vulnerability risks associated with complex media parsing.
Validation Code
How to validate .avif files in Python
Python
def is_avif(file_path: str) -> bool:
"""
Check if file is a valid AVIF by magic bytes.
Signature offset: 4 bytes
"""
signature = bytes([0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66])
with open(file_path, "rb") as f:
f.seek(4)
return f.read(8) == signature
How to validate .avif files in Node.js
Node.js
function isAVIF(buffer: Buffer): boolean {
// Signature offset: 4 bytes
const signature = Buffer.from([0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66]);
if (buffer.length < 12) return false;
return buffer.subarray(4, 12).equals(signature);
}
Go
func IsAVIF(data []byte) bool {
// Signature offset: 4 bytes
signature := []byte{0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66}
if len(data) < 12 {
return false
}
return bytes.Equal(data[4:12], signature)
}
API Endpoint
GET
/api/v1/avif
curl https://filesignature.org/api/v1/avif