sindresorhus / file-type

Detect the file type of a file, stream, or data
MIT License
3.64k stars 345 forks source link

audio/mpeg detected as video/webm or video/mp4 #599

Closed bramvbilsen closed 10 months ago

bramvbilsen commented 1 year ago

Very similar to this issue https://github.com/sindresorhus/file-type/issues/488.

I am using the MediaRecorder API to record audio in the audio/mpeg format. Upon checking the mimetype using file-type, I get either video/mp4 on Safari and video/webm on all other browsers.

As I do not support video uploads, it is an easy workaround. But a workaround nonetheless. Is this something others can reproduce as well?

Borewit commented 10 months ago

I close the issue as this cannot be reproduced.

ThePendulum commented 8 months ago

Same issue here. I initially thought it had to do with using 16.5.4 for CommonJS compatability, but 18.x still seems to identify them as video/webm

chrome.webm firefox.webm

The Magic-Bytes.js demo does come up with audio/webm for these files, but instead of video/webm, it seems to be struggling to distinguish it from Matroska instead.

This is the code I used to record it:

navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
    let chunks = [];

    mediaRecorder.value = new MediaRecorder(stream, {
        mimeType: 'audio/webm',
    });

    mediaRecorder.value.addEventListener('dataavailable', (event) => chunks.push(event.data));

    mediaRecorder.value.addEventListener('stop', () => {
        const blob = new Blob(chunks, { type: 'audio/webm' });
        const audioUrl = URL.createObjectURL(blob);

        console.log(audioUrl); // save or set as player src

        chunks = [];
    });
});