Click here to Skip to main content
15,890,282 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 610.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

 
GeneralRe: Resizing the Video Pin
Armoghan Asif6-May-07 20:01
Armoghan Asif6-May-07 20:01 
QuestionRe: Resizing the Video Pin
thenucklehead24-Aug-07 20:12
thenucklehead24-Aug-07 20:12 
AnswerRe: Resizing the Video Pin
Armoghan Asif27-Aug-07 1:31
Armoghan Asif27-Aug-07 1:31 
GeneralRe: Resizing the Video Pin
thenucklehead27-Aug-07 20:40
thenucklehead27-Aug-07 20:40 
Questionunhandled exception Pin
cannalane28-Apr-07 9:58
cannalane28-Apr-07 9:58 
AnswerRe: unhandled exception Pin
Armoghan Asif2-May-07 20:31
Armoghan Asif2-May-07 20:31 
AnswerRe: unhandled exception Pin
windrago12-Sep-07 8:02
windrago12-Sep-07 8:02 
GeneralError Pin
shakti538526-Mar-07 21:44
shakti538526-Mar-07 21:44 
Windows Media Video 8 for Color Pocket PCs (225 Kbps)
Windows Media Video 8 for Color Pocket PCs (150 Kbps)
Windows Media Video 8 for Dial-up Modems or Single-channel ISDN (28.8 to 56 Kbps)
Windows Media Video 8 for LAN, Cable Modem, or xDSL (100 to 768 Kbps)
Windows Media Video 8 for Dial-up Modems or LAN (28.8 to 100 Kbps)
Windows Media Video 8 for Dial-up Modems (28.8 Kbps)
Windows Media Video 8 for Dial-up Modems (56 Kbps)
Windows Media Video 8 for Local Area Network (100 Kbps)
Windows Media Video 8 for Local Area Network (256 Kbps)
Windows Media Video 8 for Local Area Network (384 Kbps)
Windows Media Video 8 for Local Area Network (768 Kbps)
Windows Media Video 8 for Broadband (NTSC, 700 Kbps)
Windows Media Video 8 for Broadband (NTSC, 1400 Kbps)
Windows Media Video 8 for Broadband (PAL, 384 Kbps)
Windows Media Video 8 for Broadband (PAL, 700 Kbps)
Windows Media Audio 8 for Dial-up Modem (Mono, 28.8 Kbps)
Windows Media Audio 8 for Dial-up Modem (FM Radio Stereo, 28.8 Kbps)
Windows Media Audio 8 for Dial-up Modem (32 Kbps)
Windows Media Audio 8 for Dial-up Modem (Near CD quality, 48 Kbps)
Windows Media Audio 8 for Dial-up Modem (CD quality, 64 Kbps)
Windows Media Audio 8 for ISDN (Better than CD quality, 96 Kbps)
Windows Media Audio 8 for ISDN (Better than CD quality, 128 Kbps)
Windows Media Video 8 for Dial-up Modem (No audio, 28.8 Kbps)
Windows Media Video 8 for Dial-up Modem (No audio, 56 Kbps)
Windows Media 8 Fair Quality based VBR for Broadband
Windows Media 8 High Quality based VBR for Broadband.
Windows Media 8 Best Quality based VBR for Broadband.
Screen Video High (CBR)
Screen Video/Audio High (CBR)
Screen Video (CBR)
Screen Video/Audio
Screen Video Medium (CBR)
Screen Video/Audio Medium (CBR)

above I am getting in the for loop
For i = 0 To lLength - 1
Console.WriteLine(ProColl.Item(i).Name)
ComboBox1.Items.Add(ProColl.Item(i).Name)
Next

But I want that the user select the quality from the combo box, but some time I get the error that the ComExpection

Whay this is not working for the allConfused | :confused:

Nothing is Impossible in Life Need Is Try for It
Think Big Get Big
Don’t Forget To Rank Best Post

GeneralRe: Error [modified] Pin
Armoghan Asif10-Apr-07 19:54
Armoghan Asif10-Apr-07 19:54 
QuestionPlayback Pin
Jarrod Retzloff16-Mar-07 20:58
Jarrod Retzloff16-Mar-07 20:58 
AnswerRe: Playback Pin
Armoghan Asif10-Apr-07 20:13
Armoghan Asif10-Apr-07 20:13 
QuestionOutputting AVI files? Pin
Judah Gabriel Himango28-Feb-07 16:34
sponsorJudah Gabriel Himango28-Feb-07 16:34 
AnswerRe: Outputting AVI files? Pin
Armoghan Asif10-Apr-07 20:50
Armoghan Asif10-Apr-07 20:50 
Questioncan you capture just one app e.g. just the Form1 Pin
pjmpaulmarsh21-Nov-06 5:34
pjmpaulmarsh21-Nov-06 5:34 
AnswerRe: can you capture just one app e.g. just the Form1 Pin
Armoghan Asif22-Nov-06 1:58
Armoghan Asif22-Nov-06 1:58 
GeneralRe: can you capture just one app e.g. just the Form1 Pin
pjmpaulmarsh27-Nov-06 3:16
pjmpaulmarsh27-Nov-06 3:16 
GeneralRe: can you capture just one app e.g. just the Form1 Pin
Armoghan Asif28-Nov-06 2:29
Armoghan Asif28-Nov-06 2:29 
GeneralRe: can you capture just one app e.g. just the Form1 Pin
Judah Gabriel Himango31-Jan-07 16:55
sponsorJudah Gabriel Himango31-Jan-07 16:55 
GeneralRe: can you capture just one app e.g. just the Form1 Pin
Armoghan Asif4-Feb-07 18:47
Armoghan Asif4-Feb-07 18:47 
GeneralRe: can you capture just one app e.g. just the Form1 Pin
Member 370354830-Mar-09 22:25
Member 370354830-Mar-09 22:25 
GeneralRe: can you capture just one app e.g. just the Form1 Pin
Member 37035481-Apr-09 4:28
Member 37035481-Apr-09 4:28 
QuestionDirectX Pin
Badg3r19772-Nov-06 2:31
Badg3r19772-Nov-06 2:31 
AnswerRe: DirectX Pin
Ri Qen-Sin4-Jan-07 7:08
Ri Qen-Sin4-Jan-07 7:08 
QuestionCan the audio add to the movie? Pin
Fionafei5-Oct-06 3:12
Fionafei5-Oct-06 3:12 
AnswerRe: Can the audio add to the movie? Pin
Armoghan Asif5-Oct-06 18:03
Armoghan Asif5-Oct-06 18:03 

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.