使用 IMFSourceReader 打开视频文件 [英] Using IMFSourceReader to open a video file
问题描述
我想使用 IMFSourceReader
打开一个视频文件以访问其作为 IMFSample 的帧.在 WinRT C++ 类中,我发送视频文件的 RandomAccessStream
并使用以下代码创建一个 IMFSourceReader
对象.
I want to open a video file using IMFSourceReader
to access its Frames as IMFSample.
In a WinRT C++ Class I send the RandomAccessStream
of a video file and use the following code to create an IMFSourceReader
object.
HRESULT hr = S_OK;
ComPtr<IMFSourceReader> pSourceReader;
ComPtr<IMFByteStream> spByteStream;
if (SUCCEEDED(hr))
{
// Initialize the Media Foundation platform.
hr = MFStartup(MF_VERSION);
hr = MFCreateMFByteStreamOnStreamEx((IUnknown*)InputVideoStream, &spByteStream);
ComPtr<IMFAttributes> Atrr;
hr = MFCreateAttributes(&Atrr, 10);
hr = Atrr->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, true);
hr = MFCreateSourceReaderFromByteStream(spByteStream.Get(), Atrr.Get(), &pSourceReader);
}
但是函数 MFCreateSourceReaderFromByteStream() 的 HRESULT 正在返回 不支持给定 URL 的字节流类型
.
But the HRESULT of the function MFCreateSourceReaderFromByteStream() is returning The Byte Stream Type of the Given URL is unsupported
.
我不知道我做错了什么.谁能告诉我正确的方法?我使用的是 Windows 8.1.
I don't know what i'm doing wrong. Can anyone show me the correct way? I'm using Windows 8.1.
推荐答案
我找到了解决IMFSourceReader
The Byte Stream Type of the Given URL is unsupported问题的解决方案>.我可以读取 WMV
文件的字节流,一些 MP4
文件,但不是所有类型的视频文件.所以在使用 MFCreateSourceReaderFromByteStream()
之前,我将视频流转换为 VC-1/WMV
格式,MFCreateSourceReaderFromByteStream()
可以读取该格式.我使用 MSDN 的 媒体转码示例 将视频转换为WMV 视频.现在我可以毫无错误地使用 MFCreateSourceReaderFromByteStream()
.
I have found a solution to the The Byte Stream Type of the Given URL is unsupported
problem of IMFSourceReader
. I could read Byte Stream of WMV
files, some MP4
files but not all kind of video files. So before using MFCreateSourceReaderFromByteStream()
I converted the video stream to VC-1/WMV
format which the MFCreateSourceReaderFromByteStream()
is able to read. I used the Transcoding media sample of MSDN to convert he video into WMV video. Now I am able to use MFCreateSourceReaderFromByteStream()
without any error.
这篇关于使用 IMFSourceReader 打开视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!