gpt4 book ai didi

c++ - VFW:AVIStreamGetFrameOpen() 返回 NULL

转载 作者:行者123 更新时间:2023-11-30 05:23:35 26 4
gpt4 key购买 nike

我正在尝试根据 this NeHe tutorial 中的概念使用 Video For Windows 界面编写一个 C++ Video 类,但具有更现代的代码(对于 OpenGL 3/4)。在我最初加载视频(不检索帧)的函数中,我引用了 AVIStreamGetFrameOpen(),根据 MSDN :

Returns a GetFrame object that can be used with the AVIStreamGetFrame function.

同一页还说:

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.

我的问题是 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;
}

忽略我奇怪的变量前缀。

最佳答案

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.

您关于解压器应该可用的假设是不正确的。

Windows 提供了几个与视频和音频相关的基准 API:Video for Windows、DirectShow、Media Foundation 以及 Windows Media。在其之上还有层(AudioVideoPlayback、MediaElement 等。

API 之间存在一定的互操作性:有时编解码器和其他对象在 API 之间共享,或者一个 API 提供对其他对象的兼容性包装。

然而,在您的场景中并非如此。 Video For Windows 是旧版 API,它无法将编解码器用于较新的 API。 Windows Media Player 依次使用 Media Foundation 作为主要 API,并使用 DirectShow 作为复杂场景的后备 API,在这种情况下它会提供第二次播放文件的机会。基本上,Video For Windows 仍然存在于当前版本的 Windows 中的唯一原因是对遗留应用程序的支持:新可用的视频/音频相关功能对 VFW 不可用,不仅是 Microsoft,第三方也不可用。

此外,32位编解码器和64位编解码器是独立的,某些代码只能使用各自位数的编解码器。

也就是说,就使用相同的 API 而言,Windows Media Player 和您的代码之间没有交集。 Windows Media Player 播放该文件的事实并不意味着您的 VFW 代码也应该能够播放该文件。您遇到的问题是没有安装合适的解码器来从文件中读取和解码视频(您没有提到格式,这里盲目猜测它是带有 H.264 视频的 AVI)。

关于c++ - VFW:AVIStreamGetFrameOpen() 返回 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39059959/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com