请问捕获了视频后,怎样获取捕获了的视频流并保存下来?
请问捕获了视频后,怎样获取捕获了的视频流并保存下来?
还有`压缩视频数据是不是获取了视频数据后,再对数据进行压缩?还是通过别的方法进行的?这几天都买不了陆老师的开发精选`。。。又因为急着解决``请教```
问题点数:50、回复次数:2Top
1 楼contonazhao(计算机的松鼠)回复于 2005-04-21 11:30:09 得分 50
应该是先建一个capture graph吧.建议你看看DX9.0SDK自带的StillCap例子看看,应该就在下面这段程序里面实现的.AMCap里面也应该有,不过我还没看明白^_^.
HRESULT CStillCapDlg::InitCaptureGraph( TCHAR * pFilename )
{
HRESULT hr;
// make a filter graph
//
m_pGraph.CoCreateInstance( CLSID_FilterGraph );
if( !m_pGraph )
{
Error(TEXT("Could not create filter graph"));
return E_FAIL;
}
// get whatever capture device exists
//
CComPtr< IBaseFilter > pCap;
GetDefaultCapDevice( &pCap );
if( !pCap )
{
Error( TEXT("No video capture device was detected on your system.\r\n\r\n")
TEXT("This sample requires a functional video capture device, such\r\n")
TEXT("as a USB web camera. Video capture will be disabled.") );
return E_FAIL;
}
// add the capture filter to the graph
//
hr = m_pGraph->AddFilter( pCap, L"Cap" );
if( FAILED( hr ) )
{
Error( TEXT("Could not put capture device in graph"));
return hr;
}
// make a capture builder graph (for connecting help)
//
CComPtr< ICaptureGraphBuilder2 > pBuilder;
hr = pBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder2 );
if( !pBuilder )
{
Error( TEXT("Could not create capture graph builder2"));
return hr;
}
hr = pBuilder->SetFiltergraph( m_pGraph );
if( FAILED( hr ) )
{
Error( TEXT("Could not set filtergraph on capture graph builder2"));
return hr;
}
CComPtr< IBaseFilter > pMux;
CComPtr< IFileSinkFilter > pSink;
USES_CONVERSION;
hr = pBuilder->SetOutputFileName( &MEDIASUBTYPE_Avi, T2W( pFilename ),
&pMux, &pSink );
if( FAILED( hr ) )
{
Error( TEXT("Could not create/hookup mux and writer"));
return hr;
}
hr = pBuilder->RenderStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
pCap, NULL,pMux );
if( FAILED( hr ) )
{
Error( TEXT("Could not connect capture pin"));
return hr;
}
hr = pBuilder->RenderStream( &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
pCap, NULL, NULL );
if( FAILED( hr ) )
{
Error( TEXT("Could not render capture pin"));
return hr;
}
if( hr == VFW_S_NOPREVIEWPIN )
{
// preview was faked up using the capture pin, so we can't
// turn capture on and off at will.
hr = 0;
}
// find the video window and stuff it in our window
//
CComQIPtr< IVideoWindow, &IID_IVideoWindow > pWindow = m_pGraph;
if( !pWindow )
{
Error( TEXT("Could not get video window interface"));
return hr;
}
// set up the preview window to be in our dialog
// instead of floating popup
//
HWND hwndPreview = NULL;
GetDlgItem( IDC_PREVIEW, &hwndPreview );
RECT rc;
::GetWindowRect( hwndPreview, &rc );
hr = pWindow->put_Owner( (OAHWND) hwndPreview );
hr = pWindow->put_Left( 0 );
hr = pWindow->put_Top( 0 );
hr = pWindow->put_Width( rc.right - rc.left );
hr = pWindow->put_Height( rc.bottom - rc.top );
hr = pWindow->put_Visible( OATRUE );
hr = pWindow->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS );
// run the graph
//
CComQIPtr< IMediaControl, &IID_IMediaControl > pControl = m_pGraph;
hr = pControl->Run( );
if( FAILED( hr ) )
{
Error( TEXT("Could not run graph"));
return hr;
}
UpdateStatus(_T("Capturing Video To Disk"));
return 0;
}Top
2 楼klfjdlkfjasl1()回复于 2005-04-21 17:59:41 得分 0
谢谢啊Top




