转载地址:http://www.cnblogs.com/idebuger/archive/2010/10/31/1865542.html
*. Filter Graph 如下:
[NOTE] AVI MUX filter 接入视频流从capture filter的capture pin端口上,然后打包生成AVI流;
对于声音流也能够连接到AVI MUX filter上,这样的话mux将会交错(interleave)两个流
对于File Write filter是将avi stream写入硬盘。
1.构建File Write Filter。 通过ICaptureGraphBuilder2::SetOutPutFileName方法
1
|
/*假设ICaptureGraphBuilder2对象实例化完成,pBuild*/
<br>
|
1
2
3
4
5
6
|
IBaseFilter *pMux;
hr = pBuild->SetOutPutFileName(
&MEDIASUBTYPE_Avi,
L
"C:\\Example.avi"
,
&pMux,
//用来接受指向mux的指针,实例化了IBaseFilter
NULL, );
//(Optional) Receives a pointer to the file sink.
|
2.调用ICaptureGraphBuilder2::RenderStream方法来连接capture filter到avi mux.
1
2
3
4
5
6
7
8
9
|
/*假设ICaptureGraphBuilder2对象实例化完成,pBuild*/
hr = pBuild->RenderStream(
&PIN_CATEGORY_CAPTURE,
&MEIDATYPE_Video,
pCap,
//pointer to capture filter
NULL,
//中间filter,可选
pMux);
//Mux or file sink filter
//释放mux filter
pMux->Release();
|
3.捕获音频
为了捕获音频,调用RenderStream函数时类型设置为MEDIATYPE_Audio.如果你需要同时捕获video 和 audio从不同的设备上,那么请你试用Master Stream.其能防止视频音频的抖动。原理是avi mux filter 会匹配视频流的回放playback rate,其来匹配声音流. 调用IConfigAviMux::SetMasterStream函数,在avi mux filter上。
1
2
3
4
5
6
7
8
|
/*假设IBaseFilter * pMux 已经初始化成功,*/
IConfigAviMux *pConfigMux = NULL;
hr = pMux->QueryInterface( IID_IConfigAviMux, (
void
**)&pConfigMux);
if
( SUCCESSED(hr))
{
pConfigMux->SetMasterStream(1);
//谁First RenderStream,Audio or video; 0,1
pConfigMux->Release();
}
|
4.how avi mux filter 交错audio 和 video.
通过调用IConfigInterleaving::put_Mode方法。在avi mux filter对象上操作
1
2
3
4
5
6
7
8
9
|
/*假设IBaseFilter * pMux 已经初始化成功,*/
IConfigInterleaving *pInterleave = NULL;
hr = pMux->QueryInterface( IID_IConfigInterleaving, (
void
**)&pInterleave);
if
( SUCCESSED(hr))
{
pInterleave->put_Mode( INTERLEAVE_CAPTURE );
pInterleave->Release();
}
//the flag INTERLEAVE_CAPTURE表示AVI Mux 执行交错时按照一个特定率,该率是与视频捕获率匹配
|
5.编码视频流
你可以在capture filter 和 Avi mux filter之间添加编码器Encoder利用System Device Enumerator 或者Filter Mapper来选择一个编码filter.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
IBaseFilter *pEncoder;
/*创建该编码器filter,System Device Enumerator OR Filter mapper*/
pGraph->AddFilter( pEncoder, L
"Encoder"
);
/*调用SetOutputFileName 生成writer file filter 和 mux filter*/
//渲染流 ,(连接各个filter)
hr = pBuilder->RenderStream( &PIN_CATEGORY_CAPTURE,
&MEDIATYPE_Video,
pCap,
pEncoder,
//主角登场
pMux);
pEncoder->Release();
|
1
|
//编码器可能支持IAMVideoCompression或者气压接口用来设置编码参数<br>
|