Click here to Skip to main content
15,888,816 members
Articles / Programming Languages / Visual Basic
Article

Capture Activities on Screen in a Movie

Rate me:
Please Sign up or sign in to vote.
4.81/5 (43 votes)
24 Nov 2004CPOL1 min read 609.8K   17K   147   181
An article on how to capture activities on screen as a movie file using Microsoft Windows Media Encoder 9.

Sample Image - CaptureScreenAsVideo.jpg

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.

VB
Encoder = New WMEncoder

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

VB
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.

VB
SrcVid.SetInput("ScreenCap://ScreenCapture1")
SrcAud.SetInput("Device://Default_Audio_Device")

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

VB
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.

VB
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.

VB
' 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.

VB
Dim File As IWMEncFile
File = Encoder.File
File.LocalFileName = "C:\OutputFile.avi"

Start the encoding process:

VB
' Start the encoding process.
Encoder.Start()

Stop the encoding process:

VB
' 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 :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralC++ Equivalent Pin
newinter17-Dec-04 1:49
newinter17-Dec-04 1:49 
GeneralRe: C++ Equivalent Pin
Armoghan Asif19-Dec-04 16:56
Armoghan Asif19-Dec-04 16:56 
GeneralRe: C++ Equivalent Pin
newinter20-Dec-04 23:20
newinter20-Dec-04 23:20 
GeneralRe: C++ Equivalent Pin
Armoghan Asif21-Dec-04 23:40
Armoghan Asif21-Dec-04 23:40 
Generalgreat tutorial Pin
Anonymous13-Dec-04 16:00
Anonymous13-Dec-04 16:00 
GeneralRe: great tutorial Pin
Armoghan Asif13-Dec-04 23:27
Armoghan Asif13-Dec-04 23:27 
GeneralDriver support Pin
Phaniraz4-Dec-04 20:41
Phaniraz4-Dec-04 20:41 
GeneralRe: Driver support Pin
Armoghan Asif5-Dec-04 17:56
Armoghan Asif5-Dec-04 17:56 
Ok. What I think is that there can be three reasons for it.
1. It is unable to find the DLLs which are present with the Exe.
2. The Capture drivers are not correctly installed.
3. You do not have Media Player 10. Download it from MS site

So what you can do is

1. Install Media Player 10
2. install http://www.microsoft.com/windows/windowsmedia/9series/encoder/default.aspx[^] and http://www.microsoft.com/windows/windowsmedia/9series/encoder/extensible.aspx[^] again.

Then open the project using .NET 2003. and see if its references are correct from References node. If they are not. Browse them to the working folder and give it the two DLL.

Also see this comment .
http://www.codeproject.com/vb/net/CaptureScreenAsVideo.asp?df=100&forumid=129831&select=981629#xx981629xx[^]
GeneralSDK Pin
Philip_W1-Dec-04 22:00
Philip_W1-Dec-04 22:00 
GeneralRe: SDK Pin
Armoghan Asif2-Dec-04 1:37
Armoghan Asif2-Dec-04 1:37 
GeneralRedistribution Pin
Zafar Iqbal25-Nov-04 19:36
Zafar Iqbal25-Nov-04 19:36 
GeneralRe: Redistribution Pin
Armoghan Asif25-Nov-04 20:11
Armoghan Asif25-Nov-04 20:11 
GeneralRe: Redistribution Pin
Armoghan Asif25-Nov-04 23:25
Armoghan Asif25-Nov-04 23:25 
GeneralFor Better Resolution of Video Pin
Armoghan Asif25-Nov-04 18:29
Armoghan Asif25-Nov-04 18:29 
GeneralRe: For Better Resolution of Video Pin
mistert00615-Dec-04 15:53
mistert00615-Dec-04 15:53 
GeneralRe: For Better Resolution of Video Pin
Armoghan Asif15-Dec-04 16:44
Armoghan Asif15-Dec-04 16:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.