自定义 DirectShow 捕获过滤器 - 输出 YUV
我编写了一个自定义的 directshow 过滤器,它读取图像并将其输出为 RGB。目前这工作正常。
我想添加以 YUV 输出的选项。 我在谈判阶段仍然遇到一些问题。 在我看来,关于 DirectShow 特定功能的解释非常糟糕,尤其是对于源过滤器。
根据我的理解,我建议使用 GetMediaType() 支持哪些媒体类型。 然后,当选择特定类型时,CheckMediaType() 会验证协商的媒体类型。
根据这个逻辑,我更新了 GetMediaType() 以返回 YUV 媒体类型。 我找不到如何创建 yuv 媒体类型的示例,最终使用了 Pushsource RGB 示例并进行了一些更改。
HRESULT CreateYUVVideoType(CMediaType *pMediaType, long Width, long Height, double Fps)
{
if (Width < 0)
{
return E_INVALIDARG;
}
FreeMediaType(*pMediaType);
VIDEOINFO *pvi = (VIDEOINFO*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFO));
if (pvi == 0)
{
return(E_OUTOFMEMORY);
}
ZeroMemory(pvi, sizeof(VIDEOINFO));
pvi->AvgTimePerFrame = Fps2FrameLength(Fps);
BITMAPINFOHEADER *pBmi = &(pvi->bmiHeader);
pBmi->biSize = sizeof(BITMAPINFOHEADER);
pBmi->biWidth = Width;
pBmi->biHeight = Height;
pBmi->biPlanes = 1;
pBmi->biBitCount = 16;
pBmi->biCompression = MAKEFOURCC('Y','U','Y','2');
pMediaType->SetSubtype(&MEDIASUBTYPE_YUY2);
pvi->bmiHeader.biSizeImage = DIBSIZE(pvi->bmiHeader);
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
return S_OK;
}
1) 这是创建 YUV (4:2:2) 媒体类型的正确方法吗?
2)另外,当我渲染引脚时,它会将VMR与中间的AVI解压缩器连接起来?为什么?
3) 除了 GetMediaType
和 CheckMediaType
之外,我是否需要重写任何其他函数才能支持多种输出媒体类型?
谢谢
I have written a custom directshow filter which read's images and outputs them as RGB. This currently works fine.
I want to add the option of outputting in YUV.
I'm still having some issues in the negotiation phase.
IMO the explanations on the specific functions of DirectShow is just horrible, especially for source filters.
From my understanding, I propose which media types I support with GetMediaType().
Afterwards, when a specific type is chosen, CheckMediaType() validates the negotiated media type.
With this logic, I updated GetMediaType() to return a YUV media type.
I couldn't find examples of how to create a yuv media type and ended up using the pushsource RGB example with some changes.
HRESULT CreateYUVVideoType(CMediaType *pMediaType, long Width, long Height, double Fps)
{
if (Width < 0)
{
return E_INVALIDARG;
}
FreeMediaType(*pMediaType);
VIDEOINFO *pvi = (VIDEOINFO*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFO));
if (pvi == 0)
{
return(E_OUTOFMEMORY);
}
ZeroMemory(pvi, sizeof(VIDEOINFO));
pvi->AvgTimePerFrame = Fps2FrameLength(Fps);
BITMAPINFOHEADER *pBmi = &(pvi->bmiHeader);
pBmi->biSize = sizeof(BITMAPINFOHEADER);
pBmi->biWidth = Width;
pBmi->biHeight = Height;
pBmi->biPlanes = 1;
pBmi->biBitCount = 16;
pBmi->biCompression = MAKEFOURCC('Y','U','Y','2');
pMediaType->SetSubtype(&MEDIASUBTYPE_YUY2);
pvi->bmiHeader.biSizeImage = DIBSIZE(pvi->bmiHeader);
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
return S_OK;
}
1) Is this the correct way to create a YUV (4:2:2) media type?
2) Also, when I render the pin, it connects the VMR with an AVI Decompressor in between? Why ?
3) Do I need to override any other functions besides GetMediaType
and CheckMediaType
in order to support multiple output media types?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也在 GetStreamCaps 函数中设置它
Set it also in GetStreamCaps function