Click here to Skip to main content
15,887,083 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 609K   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

 
Generalusing C++ but have a red border Pin
Brian Lion12-Jan-06 19:20
Brian Lion12-Jan-06 19:20 
GeneralRe: using C++ but have a red border Pin
Armoghan Asif13-Feb-06 22:51
Armoghan Asif13-Feb-06 22:51 
GeneralRe: using C++ but have a red border Pin
Brian Lion17-Feb-06 17:12
Brian Lion17-Feb-06 17:12 
Questiondisable video capture Pin
Lorien.NET5-Jan-06 20:39
Lorien.NET5-Jan-06 20:39 
AnswerRe: disable video capture Pin
Armoghan Asif13-Feb-06 22:47
Armoghan Asif13-Feb-06 22:47 
QuestionDo u hav ur own logic for capturing and encoding that using WMEncoder ???? Pin
hiroli4-Jan-06 1:26
hiroli4-Jan-06 1:26 
AnswerRe: Do u hav ur own logic for capturing and encoding that using WMEncoder ???? Pin
Armoghan Asif13-Feb-06 22:49
Armoghan Asif13-Feb-06 22:49 
GeneralUnable to run the Program Pin
hiroli1-Jan-06 0:15
hiroli1-Jan-06 0:15 
hey guyz, when i am running this program using VB.Net 2003 , i am not able to run it. I am getting Following error.

An unhandled exception of type 'System.NullReferenceException' occurred in CaptureScreen.exe

Additional information: Object reference not set to an instance of an object.


So, plz help me, what to do , and also how to add Audio ????
If u hav SOURCE CODE for it with audio recording, please send me plz.

E-Mail ID: harisin_47@yahoo.com
QuestionHow can i write hours into movie file! Pin
Andlah28-Sep-05 12:21
Andlah28-Sep-05 12:21 
AnswerRe: How can i write hours into movie file! Pin
Armoghan Asif28-Sep-05 19:15
Armoghan Asif28-Sep-05 19:15 
GeneralScreen Captue Pin
wsiler3-Aug-05 12:49
wsiler3-Aug-05 12:49 
GeneralRe: Screen Captue Pin
Armoghan Asif3-Aug-05 19:35
Armoghan Asif3-Aug-05 19:35 
GeneralRe: Screen Captue Pin
wsiler4-Aug-05 6:16
wsiler4-Aug-05 6:16 
GeneralReal Media output Pin
dunecherng21-Jul-05 1:55
dunecherng21-Jul-05 1:55 
GeneralRe: Real Media output Pin
Armoghan Asif22-Jul-05 1:23
Armoghan Asif22-Jul-05 1:23 
GeneralWindows Media Encoder Controls Pin
S!D11-Jul-05 21:29
S!D11-Jul-05 21:29 
GeneralRe: Windows Media Encoder Controls Pin
Armoghan Asif11-Jul-05 23:55
Armoghan Asif11-Jul-05 23:55 
GeneralSpeed up my screen capture server application Pin
S!D6-Jul-05 21:39
S!D6-Jul-05 21:39 
GeneralRe: Speed up my screen capture server application Pin
Armoghan Asif7-Jul-05 6:12
Armoghan Asif7-Jul-05 6:12 
GeneralRe: Speed up my screen capture server application Pin
Animous13-Jul-05 2:09
sussAnimous13-Jul-05 2:09 
GeneralRe: Speed up my screen capture server application Pin
Armoghan Asif13-Jul-05 3:34
Armoghan Asif13-Jul-05 3:34 
GeneralRemote screen capturing Pin
S!D30-Jun-05 22:50
S!D30-Jun-05 22:50 
GeneralRe: Remote screen capturing Pin
Armoghan Asif30-Jun-05 23:15
Armoghan Asif30-Jun-05 23:15 
Generalerror creating the profile Pin
Member 161799910-Jun-05 5:43
Member 161799910-Jun-05 5:43 
GeneralRe: error creating the profile Pin
Armoghan Asif12-Jun-05 19:55
Armoghan Asif12-Jun-05 19:55 

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.