Click here to Skip to main content
15,867,835 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 603.3K   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

 
AnswerThe real solution is just a one-liner Pin
Sergey Alexandrovich Kryukov4-Jan-21 11:59
mvaSergey Alexandrovich Kryukov4-Jan-21 11:59 
QuestionGet an error Pin
Appie van Zon22-Dec-16 5:03
Appie van Zon22-Dec-16 5:03 
QuestionDoesn't work in Windows 8.1 Pin
Gerry Lindsay17-Jan-15 2:22
Gerry Lindsay17-Jan-15 2:22 
QuestionWindows 7 x64 GPT Pin
Quadrum20-Nov-13 11:55
Quadrum20-Nov-13 11:55 
QuestionMEncoderLib.dll for recording video desktop activity Pin
vinodsujata11-Oct-13 1:49
vinodsujata11-Oct-13 1:49 
QuestionDoes not work Pin
Gandalpho7-May-13 8:29
Gandalpho7-May-13 8:29 
Questionvc++ form Pin
Aaa1.0017-Jul-12 16:45
Aaa1.0017-Jul-12 16:45 
GeneralMy vote of 1 Pin
kslawy14-Jul-12 20:55
kslawy14-Jul-12 20:55 
QuestionNo more Windows Media Encoder 9? Pin
NeWi17-Dec-10 11:12
NeWi17-Dec-10 11:12 
I have some code which uses the Windows Media Encoder COM interfaces. Records movies very nicely. But Microsoft has stopped support for it. You cant download and install the encoder anymore. Their web site says that is has been replaced with Expression Encoder, and installing that does not install the COM classes (running under Win 7, 64-bit but running 32-bit apps). I think somewhere else on here is an article about making AVI movies, and it can also be done using Apple's sdk.

See: http://www.microsoft.com/expression/products/Encoder4_Overview.aspx

"Windows Media Encoder is being retired by mid 2010."

Thanks, Microsoft. Mad | :mad:
GeneralMy vote of 1 Pin
Srinath Gopinath24-Mar-10 19:43
Srinath Gopinath24-Mar-10 19:43 
GeneralMy vote of 1 Pin
(-Itz-Trist-)3-Oct-09 16:30
(-Itz-Trist-)3-Oct-09 16:30 
GeneralGetting Eror while try to start recording Pin
Anubhava Dimri21-Aug-09 18:31
Anubhava Dimri21-Aug-09 18:31 
Questionhow to capture a window not all screen C# Pin
mquiz27-Apr-09 0:21
mquiz27-Apr-09 0:21 
GeneralWmEncoder on Vista Pin
GamePlanner20-Apr-09 9:57
GamePlanner20-Apr-09 9:57 
GeneralRe: WmEncoder on Vista Pin
weihongqin6-Sep-09 19:03
weihongqin6-Sep-09 19:03 
Questionhow set size of file Pin
avananda17-Apr-09 22:50
avananda17-Apr-09 22:50 
AnswerRe: how set size of file Pin
Armoghan Asif20-Apr-09 3:33
Armoghan Asif20-Apr-09 3:33 
GeneralColour quality on captured video Pin
Member 370354830-Mar-09 22:43
Member 370354830-Mar-09 22:43 
QuestionHelp with making snapshot!!! Pin
katran.ek4-Mar-09 1:45
katran.ek4-Mar-09 1:45 
Questionhow to decrease resolution screen when recording? Pin
ping_jacob16-Feb-09 0:41
ping_jacob16-Feb-09 0:41 
Questionhow to improve quality? Pin
ping_jacob26-Jan-09 7:10
ping_jacob26-Jan-09 7:10 
AnswerRe: how to improve quality? Pin
Armoghan Asif27-Jan-09 23:43
Armoghan Asif27-Jan-09 23:43 
Generalnice Pin
D V L23-Dec-08 3:18
professionalD V L23-Dec-08 3:18 
QuestionHow do WMencoder Works Pin
AngelaM19-Aug-08 22:13
AngelaM19-Aug-08 22:13 
AnswerRe: How do WMencoder Works Pin
Armoghan Asif19-Aug-08 22:51
Armoghan Asif19-Aug-08 22:51 

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.