Click here to Skip to main content
15,880,543 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 605.5K   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

 
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 
GeneralRe: How do WMencoder Works [modified] Pin
AngelaM20-Aug-08 19:23
AngelaM20-Aug-08 19:23 
GeneralRe: How do WMencoder Works Pin
Armoghan Asif24-Aug-08 18:42
Armoghan Asif24-Aug-08 18:42 
GeneralWTF doe "System.Runtime.InteropServices.COMException" mean Pin
brian drwecki13-Jul-08 3:55
brian drwecki13-Jul-08 3:55 
So, I'm getting this error, and I have no idea why.

I get this error as soon as I try to do this line of code

Encoder = new WMEncoder

(I put in a listbox that write "fu&k" directly before this line and one that writes "me" directly after this line and I get to see "fu&k" but no "me")


Which means something about my WM 9 encoder is not working.

I can get the encoder 9 program to work via my programs, so the program does work on its own on my computer (I even caputred a video of my self today). (when I say program I am not referring to any code that I wrote, just to program that I downloaded from microsoft called Windows Media Encoder).

I am running Vista 64 bit, the encoder I downloaded was the 64 bit program, I downloaded the hotfix as well, as I saw that worked for someone else. Any help would be greatly appreciated, I mean I want to use this SDK, but I can't get the damned thing to work!

Help
Questioncapture area Pin
Web cam26-Apr-08 0:52
Web cam26-Apr-08 0:52 
GeneralBut how I can get the vedio screen in web Pin
cscrazy16-Mar-08 20:18
cscrazy16-Mar-08 20:18 
GeneralCOM class error Pin
debiannerd15-Mar-08 13:52
debiannerd15-Mar-08 13:52 
GeneralRe: COM class error Pin
debiannerd16-Mar-08 1:33
debiannerd16-Mar-08 1:33 
GeneralNot capturing balloon tips. Pin
AdamPound3-Mar-08 3:48
AdamPound3-Mar-08 3:48 
GeneralRe: Not capturing balloon tips. Pin
Armoghan Asif3-Mar-08 22:32
Armoghan Asif3-Mar-08 22:32 
GeneralConverted the project to VS 2008 caused a problem. Pin
ozonic22-Nov-07 11:26
ozonic22-Nov-07 11:26 
GeneralRe: Converted the project to VS 2008 caused a problem. Pin
ozonic22-Nov-07 13:37
ozonic22-Nov-07 13:37 
GeneralHelp Bug Fixing !!! Pin
Tauhid Shaikh21-Sep-07 0:41
Tauhid Shaikh21-Sep-07 0:41 
GeneralRe: Help Bug Fixing !!! Pin
Armoghan Asif21-Sep-07 18:03
Armoghan Asif21-Sep-07 18:03 
GeneralRe: Help Bug Fixing !!! Pin
Tauhid Shaikh21-Sep-07 19:38
Tauhid Shaikh21-Sep-07 19:38 
GeneralRe: Help Bug Fixing !!! Pin
Armoghan Asif22-Sep-07 1:38
Armoghan Asif22-Sep-07 1:38 
GeneralAudio Out Capture !!! Pin
Tauhid Shaikh21-Sep-07 0:11
Tauhid Shaikh21-Sep-07 0:11 
GeneralRe: Audio Out Capture !!! Pin
Armoghan Asif21-Sep-07 18:00
Armoghan Asif21-Sep-07 18:00 
GeneralRe: Audio Out Capture !!! Pin
Tauhid Shaikh21-Sep-07 19:58
Tauhid Shaikh21-Sep-07 19:58 
GeneralRe: Audio Out Capture !!! Pin
Armoghan Asif22-Sep-07 1:41
Armoghan Asif22-Sep-07 1:41 
GeneralRe: Audio Out Capture !!! Pin
Tauhid Shaikh22-Sep-07 1:47
Tauhid Shaikh22-Sep-07 1:47 

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.