bojand / infer

Small crate to infer file and MIME type by checking the magic number signature
MIT License
299 stars 28 forks source link

Support Opus #71

Closed ygabuev closed 2 years ago

ygabuev commented 2 years ago

Let's add support for Opus!

I don't have any substantial knowledge on the matter, but afaik all Opus-encoded files are packed in Ogg containers. Correct me if I am wrong, but according to Ogg and Opus specifications, the matching function for an Ogg Opus buffer should look something like

pub fn is_oggopus(buf: &[u8]) -> bool {
    buf.len() > 35
        // Ogg
        && buf[0] == 0x4F
        && buf[1] == 0x67
        && buf[2] == 0x67
        && buf[3] == 0x53
        // Opus
        && buf[28] == 0x4F
        && buf[29] == 0x70
        && buf[30] == 0x75
        && buf[31] == 0x73
        && buf[32] == 0x48
        && buf[33] == 0x65
        && buf[34] == 0x61
        && buf[35] == 0x64
}