Musical Instrument Digital Interface (.midi)
.midi file signature | audio/midi
Musical Instrument Digital Interface (MIDI) sound file
Magic Bytes
Offset 0
4D 54 68 64
Sources: Apache Tika, Wikipedia, Gary Kessler
Extension
.midi
MIME Type
audio/midi
Byte Offset
0
Risk Level
Safe
Validation Code
How to validate .midi files in Python
def is_midi(file_path: str) -> bool:
"""Check if file is a valid MIDI by magic bytes."""
signature = bytes([0x4D, 0x54, 0x68, 0x64])
with open(file_path, "rb") as f:
return f.read(4) == signature
How to validate .midi files in Node.js
function isMIDI(buffer: Buffer): boolean {
const signature = Buffer.from([0x4D, 0x54, 0x68, 0x64]);
return buffer.subarray(0, 4).equals(signature);
}
How to validate .midi files in Go
func IsMIDI(data []byte) bool {
signature := []byte{0x4D, 0x54, 0x68, 0x64}
if len(data) < 4 {
return false
}
return bytes.Equal(data[:4], signature)
}
API Endpoint
/api/v1/midi
curl https://filesignature.org/api/v1/midi
See the full API documentation for all endpoints and parameters.
Frequently Asked Questions
What is a .midi file?
A .midi file is a Musical Instrument Digital Interface file. Musical Instrument Digital Interface (MIDI) sound file
What are the magic bytes for .midi files?
The magic bytes for Musical Instrument Digital Interface files are 4D 54 68 64 at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.
How do I validate a .midi file?
To validate a .midi file, read the first bytes of the file and compare them against the known magic bytes (4D 54 68 64) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.
What is the MIME type for .midi files?
The primary MIME type for .midi files is audio/midi.
Is it safe to open .midi files?
Musical Instrument Digital Interface (.midi) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.