#665 Wrong metadata when using buffer


this code gives wrong results when used with a MPEG-TS or a m2v video (works with AC-3 though):

bool Utils::ReadMetadata(MediaInfo& info, filtering_istream& in, long filesize)
if(!info.Open_Buffer_Init(filesize, 0)) return false;

const int buffer\_size = 64\*1024;
char\* buffer = new char\[buffer\_size\];

int bytes\_read;
do \{
    in.read\(buffer, buffer\_size\);
    bytes\_read = in.gcount\(\);
    if\(info.Open\_Buffer\_Continue\(reinterpret\_cast<MediaInfo\_int8u\*>\(buffer\), bytes\_read\) == 0\)

    long newPos = info.Open\_Buffer\_Continue\_GoTo\_Get\(\);
    if\(newPos == -1\)
    in.seekg\(newPos, ios::beg\);
    long pos = in.tellg\(\);
    info.Open\_Buffer\_Init\(filesize, pos\);

\} while\(bytes\_read > 0\);

delete\[\] buffer;
return true;


If I use the "Open" method instead, I can get the duration correctly.


  • Jerome Martinez

    Jerome Martinez - 2012-03-31
    • status: open --> pending-works-for-me
  • Jerome Martinez

    Jerome Martinez - 2012-03-31

    I tested my "with buffer" C++ example, from there:
    (the commented part)
    I tried with a TS file, duration is same as with Open().

    If you want me to debug something, please provide:
    - a standalone source file I could compile directly
    - a sample file to test
    So I could have quickly your environment

    Note: I quickly reviewed your code, I think this is due ti the test of info.Open_Buffer_Continue returned value.
    Returned value is:
    /// bit 0: Is Accepted (format is known)
    /// bit 1: Is Filled (main data is collected)
    /// bit 2: Is Updated (some data have beed updated, example: duration for a real time MPEG-TS stream)
    /// bit 3: Is Finalized (No more data is needed, will not use further data)
    /// bit 4-15: Reserved
    /// bit 16-31: User defined

    --> == 0 is from a very old API, I changed the API a long time ago. Where did you see this example?
    It shoudl be if(info.Open_Buffer_Continue(reinterpret_cast<MediaInfo_int8u*>(buffer), bytes_read) & 0x08)

  • Sebastien Darveau

    • status: pending-works-for-me --> open-works-for-me
  • Sebastien Darveau

    Is the function "Open_Buffer_Continue_GoTo_Get" deprecated? Otherwise, which return code indicate that I must call it?

    Using your recommendation I've fixed the issue but the file is often entirely read so not very efficient.

  • Jerome Martinez

    Jerome Martinez - 2012-04-03

    It is not deprecated.
    "if (MI.Open_Buffer_Continue_GoTo_Get()!=(MediaInfo_int64u)-1)"
    in the example.
    for TS, it is expected to read lot of bytes (if your TS stream has some CEA-608/708 captions, this may be 50-60 MB to read before requesting a seek) in order to have all the necessary data. Do you use it on big files (how big)?

  • Sebastien Darveau

    Got it! My stream was not seekable and I thought it was. With the code updated and a seekable stream, it works fine.

  • Jerome Martinez

    Jerome Martinez - 2012-04-07
    • status: open-works-for-me --> closed-works-for-me

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks