如何将源滤波器连接到编码器DMO?

时间:2015-10-22 14:09:53

标签: winapi video directshow wmv dmo

我有一个用于生成静音视频的DirectShow应用程序,其过滤器图形为

my video frame generator -> selectable video compressor -> AVI mux -> file writer

或只是

my video frame generator -> AVI mux -> file writer

这主要按预期工作,除非所选压缩器是DMO,在这种情况下,从源到压缩器的pFilterGraph-> Connect()调用失败 - 通常使用VFW_E_TYPE_NOT_ACCEPTED或VFW_E_CANNOT_CONNECT。我想让DMOs也能运作。我发现了一个不推荐使用的样本(AVIEncoderDShow),我能够通过WMV9 DMO来调整压缩输入AVI文件,这在这个分数上看起来很有希望。其过滤器图是

pFilterGraph->AddSourceFilter(AVI file) -> AVI splitter -> DMO wrapper for WMV -> AVI mux -> file writer

所以我想我可以换掉我的过滤器的源过滤器(或它所基于的弹跳球DirectShow样本)。尝试这只会给出相同的连接失败。我提供的源是32位RGB,WMV9应该接受。它可能是什么绊脚石?

编辑: 我首选媒体类型的详细信息如下:

majortype: MEDIATYPE_Video
subtype: MEDIASUBTYPE_RGB32
bFixedSizeSamples: 1
bTemporalCompression: 0
lSampleSize: 3145728
formattype: CLSID_KsDataTypeHandlerVideo
pUnk: NULL
cbFormat: 1128
pbFormat: 0x12ce4bf0

并且VFW_E_TYPE_NOT_ACCEPTED的确切失败点是

hr = pReceivePin->ReceiveConnection((IPin *)this, pmt);
CBasePin::AttemptConnection(IPin * pReceivePin, const CMediaType * pmt) Line 1796   C++
CBasePin::AgreeMediaType(IPin * pReceivePin, const CMediaType * pmt) Line 1939  C++
CBasePin::Connect(IPin * pReceivePin, const _AMMediaType * pmt) Line 1728   C++
CFilterGraph::ConnectDirectInternal(struct IPin *,struct IPin *,struct _AMMediaType const *)    Unknown
CFilterGraph::ConnectDirect(struct IPin *,struct IPin *,struct _AMMediaType const *)    Unknown
ConnectFilters(IBaseFilter * pUpstream, IBaseFilter * pDownstream, IGraphBuilder * pGraph, _AMMediaType * pmt) Line 332 C++

我的媒体类型的pbFormat被设置为VIDEOINFO,它似乎与VIDEOINFOHEADER具有相同的结构,但在其末尾添加了额外的数据。它看起来像这样:

rcSource    {LT(0, 0) RB(0, 0)  [0 x 0]}    tagRECT
rcTarget    {LT(0, 0) RB(0, 0)  [0 x 0]}    tagRECT
dwBitRate   0   unsigned long
dwBitErrorRate  0   unsigned long
AvgTimePerFrame 0   __int64
bmiHeader   {biSize=40 biWidth=1024 biHeight=768 ...}   tagBITMAPINFOHEADER
    biSize  40  unsigned long
    biWidth 1024    long
    biHeight    768 long
    biPlanes    1   unsigned short
    biBitCount  32  unsigned short
    biCompression   0   unsigned long
    biSizeImage 3145728 unsigned long
    biXPelsPerMeter 0   long
    biYPelsPerMeter 0   long
    biClrUsed   0   unsigned long
    biClrImportant  0   unsigned long
bmiColors   0x0d381c60 {{rgbBlue=0 '\0' rgbGreen=0 '\0' rgbRed=0 '\0' ...}, {rgbBlue=0 '\0' rgbGreen=0 '\0' rgbRed=...}, ...}   tagRGBQUAD[256]
dwBitMasks  0x0d381c60 {0, 0, 0}    unsigned long[3]
    [0] 0   unsigned long
    [1] 0   unsigned long
    [2] 0   unsigned long
TrueColorInfo   {dwBitMasks=0x0d381c60 {0, 0, 0} bmiColors=0x0d381c6c {{rgbBlue=0 '\0' rgbGreen=0 '\0' rgbRed=0 '\0' ...}, ...} }

1 个答案:

答案 0 :(得分:0)

某些过滤器(尤其是多路复用器,有时是编码器)要求您指定视频流的帧速率。否则,媒体类型将被拒绝,并带有通用错误代码,而没有提及帧速率是原因。

WMV9编码器DMO确实接受输入上的32位RGB,因此您应该在媒体类型的AvgTimePerFrame结构中使用正VIDEOINFOHEADER值进行试用:

enter image description here