您的位置:首页 > 其它

Window Media Encoder 捕捉音频视频

2010-04-27 21:48 489 查看
需要保存视频头录像及麦克录音,试了很多库,如ffmpeg,最后还是用微软自己的WME搞定,需要安装 Window Media Encoder sdk及media视频编码器9系列。

使用时,需引入using WMEncoderLib;

WMEncoderApp   EncoderApp   =   new   WMEncoderApp();
IWMEncoder   Encoder   =   EncoderApp.Encoder;
EncoderApp.Visible   =true;
IWMEncSourceGroupCollection   SrcGrpColl   =   Encoder.SourceGroupCollection;
IWMEncSourceGroup   SrcGrp   =   SrcGrpColl.Add("SG_1");
IWMEncSource   SrcAud   =   SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
IWMEncVideoSource2   SrcVid   =   (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcAud.SetInput("Default_Audio_Device",   "Device",   "");
SrcVid.SetInput("Default_Video_Device",   "Device",   "");
IWMEncProfile   Pro;
IWMEncProfileCollection   ProColl   =   Encoder.ProfileCollection;
for   (int   i   =   0;   i   <   ProColl.Count;   i++)
{
Pro   =   ProColl.Item(i);
if   (Pro.Name   ==   "Windows   Media   Video   8   for   Local   Area   Network   (384   Kbps)")
{
SrcGrp.set_Profile(Pro);
break;
}
}

Encoder.Start();

Encoder.Stop();


其中 encoder.start()开始编码,encoder.stop()停止编码。当停止编码后,media encoder主界面EncoderApp还是存在的,无法关闭,可以kill掉对应的进程
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: