Giter Site home page Giter Site logo

Comments (2)

Pheo-Player avatar Pheo-Player commented on July 20, 2024

As far as I can see, this is because musicmetadata does not try to read Xing headers, and always waits for all frames to be counted for a duration calculation (which is what you should do, when you get a file with no Xing headers). See here (id3v2.js, l. 133-142):

// once we know the file is VBR attach listener to end of
// stream so we can do the duration calculation when we
// have counted all the frames
if (readDuration && frameCount === 4) {
  stream.once('end', function () {
    callback('duration', calcDuration(frameCount,
      header.samples_per_frame, header.sample_rate))
    done()
  })
}

taglib, on the other hand, does this. It seems to implement a fairly simple class for these headers (xingheader.cpp, l. 91-115):

void MPEG::XingHeader::parse(const ByteVector &data)
{
  // Check to see if a valid Xing header is available.

  if(!data.startsWith("Xing") && !data.startsWith("Info"))
    return;

  // If the XingHeader doesn't contain the number of frames and the total stream
  // info it's invalid.

  if(!(data[7] & 0x01)) {
    debug("MPEG::XingHeader::parse() -- Xing header doesn't contain the total number of frames.");
    return;
  }

  if(!(data[7] & 0x02)) {
    debug("MPEG::XingHeader::parse() -- Xing header doesn't contain the total stream size.");
    return;
  }

  d->frames = data.toUInt(8U); // publicly accessible as totalFrames()
  d->size   = data.toUInt(12U); // publicly accessible as totalSize()

  d->valid = true; // publicly accessible as isValid()
}

which is used like this (mpegproperties.cpp, l. 212-225):

// Read the length and the bitrate from the Xing header.

if(d->xingHeader->isValid() &&
   firstHeader.sampleRate() > 0 &&
   d->xingHeader->totalFrames() > 0)
{
    double timePerFrame =
      double(firstHeader.samplesPerFrame()) / firstHeader.sampleRate();

    double length = timePerFrame * d->xingHeader->totalFrames();

    d->length = int(length);
    d->bitrate = d->length > 0 ? (int)(d->xingHeader->totalSize() * 8 / length / 1000) : 0;
}

This doesn't look too hard to implement to me, but I haven't read deep into this library's code and don't feel capable of doing this.

The following might be helpful too: http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header#XINGHeader

from musicmetadata.

leetreveil avatar leetreveil commented on July 20, 2024

Closing this now, feel free to reopen if this is still an issue for you.

from musicmetadata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.