Issue parsing multiple large video files quickly using mediainfodll library

178 Views Asked by At

I have being using MediaInfoLib, to find duration of a media file, in my project without issue until I observed lately that when I try to parse multiple large video files ( MXF, MP4 and AVI formats) quickly in a loop, MediaInfo is unable to return all the information. My C++ project snippet is produced below. I have tried waiting till the mediaInfoDll object is ready. All the skipped video files work if they are individually parsed. Any clue? I found ffprobe application to be too slow and vlc library is not accurate for different media types. Thanks

bool getMediaInfo(CString filename, long& duration)
{
  MediaInfoDLL::MediaInfo movieInfo;
  if( movieInfo.Open(filename.GetString())) return false;   
  std::chrono::high_resolution_clock::time_point start = 
  std::chrono::high_resolution_clock::now();
  while (true) {
        std::chrono::high_resolution_clock::time_point present = std::chrono::high_resolution_clock::now();
        std::chrono::seconds lapse = std::chrono::duration_cast<std::chrono::seconds>(present - start);
        if (lapse >= std::chrono::seconds(3)) {
            movieInfo.Close();
            return false;
        }
        if (!movieInfo.IsReady()) continue;
        auto strDura = movieInfo.Get(MediaInfoDLL::Stream_General, 0, L"Duration"); //in msec
        duration = std::atol(CStringA(strDura.c_str()));
        movieInfo.Close();
        break;
    }
  return true;
}
1

There are 1 best solutions below

0
SargeATM On

Retry getMediaInfo(...)

for(int i = 0; i < 3; i++)
{
    if(getMediaInfo(filename, &duration))
    {
        return true;
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

return false;

How could I even dare to suggest such hackery?

Without more information and based on the symptoms, it seems this bug shows up indeterministically. If high load is causing MediaInfoLib to act up, then this will tell you that and also give you a workaround until the bug is found in MediaInfoLib. [begin dry sly wit] And if this doesn't work, we have successfully found another way to not make it work. Thus, narrowing the search.