Capture Activities on Screen in a Movie

王朝other·作者佚名  2006-01-09
宽屏版  字体: |||超大  

Download source and demo files - 82.4 Kb

Introduction

bkniazi asked me a question on experts-exchange.com, about how to capture the activities going on on a machine as a movie. I found the question interesting, so looked for it, but could not find any good solution for it. Though, I found some software which do this kind of work. I found Windows Media Encoder 9 very interesting. While looking into it, I found its SDK and I started looking into it. It is quite interesting. So I made this small sample after looking into the API and seeing some samples.

Prerequisites

You will be needing Windows Media Encoder 9 Series and SDK.

Using the code

Best thing about this API is that it is totally interface based. WMEncoder is the main class. Set its parameters and start the encoder to start encoding. Stop it to save in file.

Encoder = New WMEncoder

Create a Source Group named SG_1 in Encoder's Collection.

Dim SrcGrp As IWMEncSourceGroup2

Dim SrcGrpColl As IWMEncSourceGroupCollection

SrcGrpColl = Encoder.SourceGroupCollection

SrcGrp = SrcGrpColl.Add("SG_1")

Specify the input types for Video and Audio. Specify the screen capture plug-in to set up the video source.

SrcVid.SetInput("ScreenCap://ScreenCapture1")

SrcAud.SetInput("Device://Default_Audio_Device")

Find the profile and set Encoder's group profile from all the profiles available.

ProColl = Encoder.ProfileCollection

lLength = ProColl.Count

For i = 0 To lLength - 1

Pro = ProColl.Item(i)

If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then

SrcGrp.Profile = Pro

Exit For

End If

Next

Specify header information of the Encoder. I.e., description or attributes.

Dim Descr As IWMEncDisplayInfo

Descr = Encoder.DisplayInfo

Descr.Author = "Armoghan Asif"

Descr.Copyright = "Copyright information"

Descr.Description = "Text description of encoded content"

Descr.Rating = "Rating information"

Descr.Title = "Title of encoded content"

' Add an attribute to the collection.

Dim Attr As IWMEncAttributes

Attr = Encoder.Attributes

Attr.Add("URL", "IP address")

You may do some cropping of the Encoder if required.

' Crop 2 pixels from each edge of the video image.

SrcVid.CroppingBottomMargin = 2

SrcVid.CroppingTopMargin = 2

SrcVid.CroppingLeftMargin = 2

SrcVid.CroppingRightMargin = 2

Specify the Local File as output. You may also set additional fields of the file, like size of file, seconds of file etc.

Dim File As IWMEncFile

File = Encoder.File

File.LocalFileName = "C:\OutputFile.avi"

Start the encoding process:

' Start the encoding process.

Encoder.Start()

Stop the encoding process:

' Stop the encoding process.

Encoder.Stop()

Points of Interest

No fancy things are placed in the demo. It just illustrates the screen capture. It can be easily added in any existing application. Nothing else :)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有