Borewit / music-metadata-browser

Browser version of music-metadata parser Supporting a wide range of audio and tag formats.
MIT License
240 stars 21 forks source link

For the same audio, the file information obtained by using different APIs is different #404

Closed yuanliwei closed 3 years ago

yuanliwei commented 3 years ago

mp3-meta-test.zip

test code

const musicMetadata = require('music-metadata-browser');
const fs = require('fs')
const path = require('path')

async function start() {
    let mp3 = path.join(__dirname, 'A8E0CE2D6C590E51F225201FB021885F.mp3')
    let meta = await musicMetadata.parseNodeStream(fs.createReadStream(mp3))
    console.log(meta)
    meta = await musicMetadata.parseBuffer(fs.readFileSync(mp3))
    console.log(meta)
}

start()

output

PS C:\Users\y> node C:\Users\y\Desktop\mp3-meta-test\index.js
{
  format: {
    tagTypes: [ 'ID3v2.3' ],
    trackInfo: [],
    lossless: false,
    container: 'MPEG',
    codec: 'MPEG 1 Layer 3',
    sampleRate: 44100,
    numberOfChannels: 1,
    bitrate: 32000,
    codecProfile: 'CBR'
  },
  native: { 'ID3v2.3': [ [Object] ] },
  quality: { warnings: [ [Object], [Object] ] },
  common: {
    track: { no: null, of: null },
    disk: { no: null, of: null },
    movementIndex: {}
  }
}
{
  format: {
    tagTypes: [ 'ID3v2.3', 'ID3v1' ],
    trackInfo: [],
    lossless: false,
    container: 'MPEG',
    codec: 'MPEG 1 Layer 3',
    sampleRate: 44100,
    numberOfChannels: 1,
    bitrate: 32000,
    codecProfile: 'CBR',
    numberOfSamples: 688896,
    duration: 15.62122448979592
  },
  native: { 'ID3v2.3': [ [Object] ], ID3v1: [ [Object] ] },
  quality: { warnings: [ [Object], [Object] ] },
  common: {
    track: { no: null, of: null },
    disk: { no: null, of: null },
    movementIndex: {},
    genre: [ 'Blues' ]
  }
}

Use ffmpeg to view the audio duration should be 4.44 seconds.

PS C:\Users\y\Desktop\mp3-meta-test> ffprobe.exe .\A8E0CE2D6C590E51F225201FB021885F.mp3                                 ffprobe version N-93863-g58d167bcd5 Copyright (c) 2007-2019 the FFmpeg developers
  built with gcc 8.3.1 (GCC) 20190414
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 27.100 / 56. 27.100
  libavcodec     58. 52.101 / 58. 52.101
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 53.100 /  7. 53.100
  libswscale      5.  4.101 /  5.  4.101
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
[mp3 @ 000002085649c380] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '.\A8E0CE2D6C590E51F225201FB021885F.mp3':
  Metadata:
    genre           : Blues
    id3v2_priv.XMP  : <?xpacket begin="\xef\xbb\xbf" id="W5M0MpCehiHzreSzNTczkc9d"?>\x0a<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27        ">\x0a <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\x0a  <rdf
  Duration: 00:00:04.44, start: 0.000000, bitrate: 122 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, mono, fltp, 112 kb/s
Borewit commented 3 years ago

Regarding the duration, there is a difference between reported and decoded duration, checked with Foobar2000: Error: Reported length is inaccurate : 0:15.556984 vs 0:04.167596 decoded

If you parse as a stream, the ID3v1 header is skipped to prevent the entire file has to be read. This explains the different result.

yuanliwei commented 3 years ago

Will music-metadata-browser handle this situation to get the real duration, or should I close this issue?

Borewit commented 3 years ago

music-metadata-browser (actually music-metadat) intend it is not to decode audio to verify the duration. It is used to extracts the audio files metadata.