0

I would like to play only audio from video file. For this I'm using directshow SampleGrabber with Major_type set to MEDIATYPE_Audio and DirectSound Audio Renderer.

This works fine for .wmv files. However when I try to play .mp4 files. The RenderStream fails.

I then tried creating filter in GrapStudioNext with following filtet

File Source->LAV Splitter (Automatically load)->SampleGrabber->MS DTV-DVD Audio Decoder->Default DirectSoude Device

The above filter works fine and I'm to listen to the audio.

However when I create the same filter graph manually in vc++. The RenderStream calls fails while connecting source filter to SampleGrabber

HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&m_pGraph);
if(FAILED(hr))
{
ReleaseResource();
return hr;
}

hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, 
        (void **)&m_pBuilder);
    if (SUCCEEDED(hr))
    {
        m_pBuilder->SetFiltergraph(m_pGraph);
    }
else
{
std::cout<<"Failed to Created Capture Graph"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IMediaControl, (void**)&m_pControl);
if(FAILED(hr))
{
std::cout<<"Failed to Get Media Control Interface"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void**)&m_pEvent);
if(FAILED(hr))
{
std::cout<<"Failed to Get Media Event"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IMediaSeeking, (void**)&m_pMediaSeek);
if(FAILED(hr))
{
std::cout<<"Failed to Get Media Seeking"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IBasicAudio, (void**)&m_pBasicAudio);
if(FAILED(hr))
{
std::cout<<"Failed to Get Basic Audio"<<std::endl;
ReleaseResource();
return hr;
}
#if 0
hr = CoCreateInstance(CLSID_AudioRender, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pBaseFilter);
#endif

hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pBaseFilter);

if(FAILED(hr))
{
std::cout<<"Failed to Create Audio Render"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->AddFilter(m_pBaseFilter, L"Audio Filter");
if(FAILED(hr))
{
std::cout<<"Failed to Add Audio Render"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->AddSourceFilter((LPCWSTR)wxStr,L"SourceFlt", &m_pSourceFilter);
if(FAILED(hr))
{
std::cout<<"Failed to Add Source Filter"<<std::endl;
ReleaseResource();
return hr;
}

hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pBaseFilterSG);
if(FAILED(hr))
{
std::cout<<"Failed to Create Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pGraph->AddFilter(m_pBaseFilterSG, L"Sample_Grabber");
if(FAILED(hr))
{
std::cout<<"Failed to Add Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pBaseFilterSG->QueryInterface(IID_ISampleGrabber, (void**)&m_pSampleGrabber);

if(FAILED(hr))
{
std::cout<<"Query Interface Failed for Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}
ZeroMemory(&mt, sizeof(mt));
mt.majortype = MEDIATYPE_Audio;
mt.subtype = MEDIASUBTYPE_RAW_AAC1;
 hr = m_pSampleGrabber->SetMediaType(&mt);

  if(FAILED(hr))
{
std::cout<<"Failed to Set Media Type"<<std::endl;
ReleaseResource();
return 1;
}

hr = CoCreateInstance(CLSID_CMPEG2AudDecoderDS , NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pMSAduioDecoder);
if(FAILED(hr))
{
std::cout<<"Failed to Create Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pGraph->AddFilter(m_pMSAduioDecoder, L"Audio_Decoder");
if(FAILED(hr))
{
std::cout<<"Failed to Add Adudio Decoder"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pBuilder->RenderStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Audio,m_pSourceFilter, m_pBaseFilterSG,m_pMSAduioDecoder);
 if(FAILED(hr))
{
std::cout<<"Failed to Render First Chain"<<std::endl;
ReleaseResource();
return hr;
}

  hr = m_pBuilder->RenderStream(NULL, NULL,m_pMSAduioDecoder,NULL,  m_pBaseFilter);
 if(FAILED(hr))
{
std::cout<<"Failed to Render Second Chain"<<std::endl;
ReleaseResource();
return hr;
}

Also when I SetMediaType to MEDIATYPE_Video the first chain connects properly. But seconds one fails even after using PIN_CATEOGARY_CAPTURE and MediaType_Audio.

Also the error I'm getting in RenderStream invalid args.

Please suggest what could be going wrong. Thanks in advance.

Pradeep

4

1 回答 1

0

这是完全错误的。您根本没有捕获源,因此首先尝试利用 Capture Graph Builder 很弱。您的图表中没有一个引脚,PIN_CATEGORY_CAPTURE因此它失败了。

您知道需要使用的所有过滤器CoCreateInstanceIGraphBuilder::AddFilter并且IPin::Connect足以构建图形,您根本不需要捕获图形构建器。

于 2013-02-20T20:44:59.070 回答