MPEG audio file framesynch pattern
audio/mpeg
Magic Bytes
Offset: 0
49 44 33
MPEG-1 Audio Layer III is a digital audio compression format designed by the Moving Picture Experts Group (MPEG) to reduce file size while maintaining sound quality. It is universally adopted for consumer music streaming, podcast distribution, and efficient storage of audio collections on various hardware devices. Although technically superseded by more efficient codecs like AAC, it remains the dominant standard for digital audio, utilizing metadata containers to store track information and album artwork.
Validation Code
How to validate .mp3 files in Python
Python
def is_mp3(file_path: str) -> bool:
"""Check if file is a valid MP3 by magic bytes."""
signature = bytes([0x49, 0x44, 0x33])
with open(file_path, "rb") as f:
return f.read(3) == signature
How to validate .mp3 files in Node.js
Node.js
function isMP3(buffer: Buffer): boolean {
const signature = Buffer.from([0x49, 0x44, 0x33]);
return buffer.subarray(0, 3).equals(signature);
}
Go
func IsMP3(data []byte) bool {
signature := []byte{0x49, 0x44, 0x33}
if len(data) < 3 {
return false
}
return bytes.Equal(data[:3], signature)
}
API Endpoint
GET
/api/v1/mp3
curl https://filesignature.org/api/v1/mp3