|
From: minhdanh on 27 Jun 2008 10:30 I am using on the CameraCaptureSample to capture a video. Although the sample on its own works well, I want to improved it to grab the raw camera data and work on it. I have successfully written and added my null transform filter (CTransInPlaceFilter) to the graph by using the following code: ..... // prepare the preview graph hr = m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, m_pVideoCaptureFilter, NULL, NULL); //find the default renderer hr = pFilterGraph->FindFilterByName(L"Video Renderer", &pVidRenderer); //get input pin of the default renderer IPin* ipin = GetPin(pVidRenderer, PINDIR_INPUT); //find out who the renderer is connected to and disconnect from them IPin* opin; hr = ipin->ConnectedTo(&opin); hr = ipin->Disconnect(); //disconnect default renderer output pin hr = opin->Disconnect(); //disconnect video source output pin //create our null transform filter hr = pNullTransform.CoCreateInstance(CLSID_NullNull); hr = pFilterGraph->AddFilter(pNullTransform, L"NullNull"); //find the input pin of the null transform filter and connect it to the output of the video source IPin* nullRendIn = GetPin(pNullTransform, PINDIR_INPUT); hr = pFilterGraph->Connect(opin, nullRendIn); //connect the output of the null transform filter to the default renderer IPin* nullRendOut = GetPin(pNullTransform, PINDIR_OUTPUT); hr = pFilterGraph->Connect(nullRendOut, ipin); //media control object hr = pFilterGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); //run the graph hr = pMediaControl->Run(); ......... After this I can see that my null transform filter can receive the media sample in its function HRESULT Transform(IMediaSample *pSample) and I can successfully convert the buffer into the a bitmap file. This means, the null transform filter is working well. However, with the presence of the null transform filter in the graph, I can no longer capture video into ASF file by using the sample code. I initialize the WM9 encoder as followed (copied from the sample code): // Create the video encoder CHK( pVideoEncoder.CoCreateInstance( CLSID_DMOWrapperFilter )); CHK( pVideoEncoder.QueryInterface( &pWrapperFilter )); // Load the WMV9 DMO CHK( pWrapperFilter->Init( CLSID_CWMV9EncMediaObject, DMOCATEGORY_VIDEO_ENCODER )); // Everything succeeded, let's add the encoder to the graph CHK( pFilterGraph->AddFilter( pVideoEncoder, L"WMV9 DMO Encoder" )); // file to save video to CHK( m_pCaptureGraphBuilder->SetOutputFileName(&MEDIASUBTYPE_Asf, L\\test.asf, &pASFMultiplexer, &pFileSinkFilter )); // Connect the video capture filter, the encoder and the multiplexer together CHK( m_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pVideoCaptureFilter, pVideoEncoder, pASFMultiplexer)); This code is put just before pMediaControl->Run() and there is no error. To start capturing: LONGLONG dwStart = 0, dwEnd = 0; WORD wStartCookie = 1, wEndCookie = 2; CaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, NULL, &dwStart, &dwEnd, wStartCookie, wEndCookie ); To stop capturing: dwStart = 0; CHK( pFilterGraph->QueryInterface( &pMediaSeeking )); CHK( pMediaSeeking->GetCurrentPosition( &dwEnd )); CHK( m_pCaptureGraphBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, NULL, &dwStart, &dwEnd, wStartCookie, wEndCookie )); There are no errors, all HRESULTs return S_OK, but the video file is not created! If, however, I removed my custom filter from the graph then the video is captured properly. Any ideas what the problem is? Thanks a lot!
|
Pages: 1 Prev: Can we develop a J2ME application and deploy it on Windows Mob Next: How to run the script? |