我正在尝试使用 Video For Windows 界面编写 C++ Video 类,基于此 NeHe 教程中的概念,但使用更现代的代码(用于 OpenGL 3/4)。在我最初加载视频(不检索帧)的函数中,我指的是AVIStreamGetFrameOpen()
,根据MSDN:
返回可与 AVIStreamGetFrame 函数一起使用的 GetFrame 对象。
同一页面还说:
如果系统找不到可以将流解压缩为给定格式或任何 RGB 格式的解压缩器,则该函数返回 NULL。
我的问题是返回AVIStreamGetFrameOpen()
,如前所述NULL
,这意味着没有找到与文件匹配的解压缩器。但是,我的文件可以毫无问题地使用 Windows Media Player 播放,我相信这意味着应该可以使用解压缩器。
VFW 似乎缺乏文档,而且 MSDN 页面并不总是非常有用。任何人都知道可能导致此问题的原因是什么?
这是相关函数的代码:
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;
}
忽略我奇怪的变量前缀。