用录制视频代替我们的截图,你准备好了吗?

1.第一步

在本机上安装解码器:WMEncoder_cn.exe
下载地址:http://download.csdn.net/download/wanggsh/485996
2.第二步
在安装结束后,进入到安装目录,将WMEncEng.dl文件添加到引用中l
例如我的安装目录如下:
C:\Program Files\Windows Media Components\Encoder
3.代码如下
首先要using WMEncoderLib

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMEncoderLib;
namespace ConsoleTest
{
public class WMEncoderManage
{
private static WMEncoder _encoder = null;
public static WMEncoder GetWMEncoder
{
get
{
if (_encoder == null)
{
_encoder = new WMEncoder();
}

return _encoder;
}
}


private static string _defaultFormat = "屏幕视频/音频 - 高(CBR)";
public static string DefaultFormat
{
get
{
return _defaultFormat;
}

set { _defaultFormat = value; }
}

/// <summary>
/// 视频录制方法
/// </summary>
private void Coder()
{
try
{
WMEncoder Encoder = WMEncoderManage.GetWMEncoder;
IWMEncSourceGroup SrcGrp;
IWMEncSourceGroupCollection SrcGrpColl;
SrcGrpColl = Encoder.SourceGroupCollection;
SrcGrp = SrcGrpColl.Add("SG_1");

IWMEncSource SrcVid;
IWMEncSource SrcAud;
SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);


SrcAud.SetInput("Default_Audio_Device", "Device", "");
SrcVid.SetInput("ScreenCapture1", "ScreenCap", "");


IWMEncProfileCollection ProColl;
IWMEncProfile Pro;
int i;
long lLength;

ProColl = Encoder.ProfileCollection;
lLength = ProColl.Count;

for (i = 0; i < lLength - 1; i++)
{
Pro = ProColl.Item(i);

if (Pro.Name == WMEncoderManage.DefaultFormat)
{
SrcGrp.set_Profile(Pro);
break;
}
}

IWMEncDisplayInfo Descr;
Descr = Encoder.DisplayInfo;
Descr.Author = "qiaojibing";
Descr.Copyright = "qiaojibing";
Descr.Description = "qiaojibing";
Descr.Rating = "qiaojibing";
Descr.Title = "qiaojibing";

IWMEncAttributes Attr;
Attr = Encoder.Attributes;
Attr.Add("URL", "www.51autotest.com");

IWMEncFile File;
File = Encoder.File;
File.LocalFileName = @"c:\\1.wmv";

Encoder.Start();

}
catch (Exception)
{

throw;
}
}

public void stopEncoder() {
WMEncoderManage.GetWMEncoder.Stop();

}
public static void Main(string[] args){
WMEncoderManage wm=new WMEncoderManage();
wm.Coder();
System.Threading.Thread.Sleep(10000);
wm.stopEncoder();

}

}



}

 试一下,ok了.....
大家可以给这个写成一个类库
然后每个case启动之前调用start
每个case启动之后调用stop

看完之后,我想问大家一个问题,为什么会选择录制视频呢,录制视频和截图有什么好处?做一下调查

你可能感兴趣的:(视频)