MP3: Failed to determine audio format
redvivi opened this issue · 3 comments
Hello,
I get this error message: Failed to determine audio format
on this file https://bubbleawsdemo.s3.amazonaws.com/first_folder/second_folder/ttt.mp3
Package.json
{
"dependencies":{
"music-metadata":”7.12.6” // Can’t upgrade to latest version yet
}
}
Sample Code
const mm = require('music-metadata');
// Download the file from the URL
function getDataFromURL(url) {
return new Promise((resolve, reject) => {
const options = {
uri: url,
gzip: true,
encoding: null,
method: 'GET',
};
let response = context.request(options);
if (response.statusCode == 206 || response.statusCode == 200) {
resolve(response.body);
} else {
reject(response.statusCode + " " + response.statusMessage);
};
});
};
function detectingFileMetadata(filedata) {
return new Promise((resolve, reject) => {
// Calling the service
mm.parseBuffer(filedata, {
duration: true
})
.then(
resolve({
...
})
)
.catch((error) => {
reject(error);
});
});
};
getDataFromURL(url)
.then(
(data) => {
detectingFileMetadata(data)
.then(
(dataFromFunction) => {
callback(undefined, dataFromFunction);
})
.catch(
(err) => {
callback(err);
})
})
.catch(
(err) => {
callback(err);
});
Is there a bug?
Thanks.
I have no access to that URL pointing to the MP3 file @redvivi .
As you don't pass the content-type to music-metadata you rely on the auto-detection. Usually that works, yet I recommend to pass the content-type from you HTTP response to options.mimeType
as shown in this example.
You could also consider using streams instead of buffering the entire HTTP body in a buffer.
Alternatively there is specialized why reading from Amazon: tokenizer-s3, utilizing partial reads which should improve performance, especially with limited bandwith.
The detection of the file type is done by file-type. Reason it is not detected, is that the MP3 bit stream is not immediately starting after the ID3 header, a series of zeroes is in between.
Other reason the detection could fail, is in case the ID3 header exceeds the size of the sample buffer. Easily achieved by putting in some cover art. Hence the advice to use content-type.