tags:

views:

9

answers:

0

Hi, I have been struggling for a while now to get my filter graph to run .I am trying to crop a .wmv file into smaller duration .wmv files .It looks quite a simple task I dont know why its is getting so complicated.I follow this

Source-> SampleGrabber->WMA sf writer. Here is my code

IBaseFilter* pASFWriter;
ICaptureGraphBuilder2 * pBuilder=NULL; CoCreateInstance(CLSID_CaptureGraphBuilder2,NULL,CLSCTX_INPROC_SERVER,IID_ICaptureGraphBuilder2,(LPVOID*)&pBuilder);
pBuilder->SetFiltergraph(pGraphBuilder);
pBuilder->SetOutputFileName(&MEDIASUBTYPE_Asf,OUTFILE,&pASFWriter,NULL);
IConfigAsfWriter *pConfig=NULL;
HRESULT hr80 = pASFWriter->QueryInterface(IID_IConfigAsfWriter, (void**)&pConfig);
if (SUCCEEDED(hr80)) {
// Configure the ASF Writer filter.
pConfig->Release();
}

IBaseFilter *pSource=NULL;
pGraphBuilder->AddSourceFilter(FILENAME,L"Source",&pSource);
IBaseFilter *pGrabberF2=NULL;
ISampleGrabber *pGrabber2=NULL;
CoCreateInstance(CLSID_SampleGrabber,NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&pGrabberF2));
pGraphBuilder->AddFilter(pGrabberF2,L"Sample Grabber2");
AM_MEDIA_TYPE mt1;  
ZeroMemory(&mt1,sizeof(mt1));
mt1.majortype=MEDIATYPE_Video;
mt1.subtype=MEDIASUBTYPE_RGB24;
 pGrabberF2->QueryInterface(IID_ISampleGrabber,(void**)(&pGrabber2));
 pGrabber2->SetBufferSamples(TRUE);
 pGrabber2->SetOneShot(FALSE);  pGrabber->SetMediaType(&mt1);
    pSource->EnumPins(&pEnum2);
pEnum2->Next(1,&pPin2,NULL);


HRESULT hr108=ConnectFilters(pGraphBuilder,pPin2,pGrabberF2);//Source to Grabber
pGrabberF2->EnumPins(&pEnum3);
IEnumPins *pEnum4=NULL;
pASFWriter->EnumPins(&pEnum4);
IPin* pPin4=NULL;

while (S_OK==pEnum3->Next(1,&pPin3,NULL)&& S_OK==pEnum4->Next(1,&pPin4,NULL)){

    pGraphBuilder->Connect(pPin3,pPin4);//Grabber to FileWriter

}

pGraphBuilder->RenderFile(FILENAME,NULL);//FILENAME=INPUTFILENAME (.wmv format)  
    pMediaPosition->put_CurrentPosition(start);
pMediaPosition->put_StopTime(stop);
HRESULT test1=pMediaControl->Run();

All of it runs fine(returns S_OK) .But test1 returns E_FAIL and no file is created.Can somebody help?