I'm trying to write a C++ Video class using the Video For Windows interface, based on concepts from this NeHe tutorial, but with more modern code (for OpenGL 3/4). In my function that initially loads the video (not retrieve the frames), I refer to AVIStreamGetFrameOpen()
, which according to MSDN:
Returns a GetFrame object that can be used with the AVIStreamGetFrame function.
The same page also says:
If the system cannot find a decompressor that can decompress the stream to the given format, or to any RGB format, the function returns NULL.
My problem is that AVIStreamGetFrameOpen()
returns NULL
, which as stated, means no decompressor was found that matches the file. However, my file can be played with Windows Media Player without issues, which I believe means a decompressor should be available.
There seems to be a lack of documentation when it comes to VFW, and MSDN pages aren't always extremely useful. Anyone know what could be causing this issue?
Here's the code for the function in question:
bool Video::Load(std::string FileName) {
try {
if (this->bLoaded)
this->UnLoad();
AVIFileInit();
if (AVIStreamOpenFromFile(&pavi, FileName.c_str(), streamtypeVIDEO, 0, OF_READ, NULL) != 0)
throw "Failed to open the AVI video stream.";
AVIStreamInfo(pavi, &psi, sizeof(psi)); // Reads Information About The Stream Into psi
this->szWidth = psi.rcFrame.right - psi.rcFrame.left; // Width Is Right Side Of Frame Minus Left
this->szHeight = psi.rcFrame.bottom - psi.rcFrame.top; // Height Is Bottom Of Frame Minus Top
ulnLastFrame = AVIStreamLength(pavi); // The Last Frame Of The Stream
this->dDuration = AVIStreamSampleToTime(pavi, ulnLastFrame) / 1000.0f;
this->dSecondsPerFrame = this->dDuration / ulnLastFrame;
pgf = AVIStreamGetFrameOpen(pavi, NULL); // Create The PGETFRAME Using Our Request Mode
if (pgf == NULL)
// ===== ERROR THROWN HERE =====
throw "Failed to open the AVI GetFrame object.";
glGenTextures(1, &this->unTexID);
glBindTexture(GL_TEXTURE_2D, this->unTexID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, this->szWidth, this->szHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
}
catch (const char* e) {
Message((std::string("Error: ") + e + "\nFile: \"" + FileName + "\"").c_str(), "Error");
return false;
}
this->bLoaded = true;
return true;
}
Ignore my weird variable prefixes.