Click here to Skip to main content
Click here to Skip to main content

Capture Activities on Screen in a Movie

, 24 Nov 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
An article on how to capture activities on screen as a movie file using Microsoft Windows Media Encoder 9.

Sample Image - CaptureScreenAsVideo.jpg


bkniazi asked me a question on, 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.


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.

Encoder = New WMEncoder

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

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.


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

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

Specify header information of the Encoder. I.e., description or attributes.

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.

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

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

Start the encoding process:

' Start the encoding process.

Stop the encoding process:

' Stop the encoding process.

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 Smile | :)


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


About the Author

Armoghan Asif
Pakistan Pakistan
No Biography provided

Comments and Discussions

QuestionDoesn't work in Windows 8.1 PinmemberGerry Lindsay17-Jan-15 3:22 
QuestionWindows 7 x64 GPT PinmemberQuadrum20-Nov-13 12:55 
QuestionMEncoderLib.dll for recording video desktop activity Pinmembervinodsujata11-Oct-13 2:49 
QuestionDoes not work PinmemberGandalpho7-May-13 9:29 
Questionvc++ form PinmemberAaa1.0017-Jul-12 17:45 
GeneralMy vote of 1 Pinmemberkslawy14-Jul-12 21:55 
QuestionNo more Windows Media Encoder 9? PinmemberNeWi17-Dec-10 12:12 
GeneralMy vote of 1 PinmemberSrinath G Nath24-Mar-10 20:43 
GeneralMy vote of 1 Pinmember(-Itz-Trist-)3-Oct-09 17:30 
GeneralGetting Eror while try to start recording Pinmembereg_Anubhava21-Aug-09 19:31 
Questionhow to capture a window not all screen C# Pinmembermquiz27-Apr-09 1:21 
GeneralWmEncoder on Vista PinmemberGamePlanner20-Apr-09 10:57 
GeneralRe: WmEncoder on Vista Pinmemberweihongqin6-Sep-09 20:03 
Questionhow set size of file Pinmemberavananda17-Apr-09 23:50 
AnswerRe: how set size of file PinmemberArmoghan Asif20-Apr-09 4:33 
GeneralColour quality on captured video PinmemberMember 370354830-Mar-09 23:43 
QuestionHelp with making snapshot!!! Pinmemberkatran.ek4-Mar-09 2:45 
Questionhow to decrease resolution screen when recording? Pinmemberping_jacob16-Feb-09 1:41 
Questionhow to improve quality? Pinmemberping_jacob26-Jan-09 8:10 
AnswerRe: how to improve quality? PinmemberArmoghan Asif28-Jan-09 0:43 
Generalnice PinmemberDhavalkumar P Patel23-Dec-08 4:18 
QuestionHow do WMencoder Works PinmemberNiyaHere19-Aug-08 23:13 
AnswerRe: How do WMencoder Works PinmemberArmoghan Asif19-Aug-08 23:51 
GeneralRe: How do WMencoder Works [modified] PinmemberNiyaHere20-Aug-08 20:23 
GeneralRe: How do WMencoder Works PinmemberArmoghan Asif24-Aug-08 19:42 
GeneralWTF doe "System.Runtime.InteropServices.COMException" mean Pinmemberbrian drwecki13-Jul-08 4: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!
Questioncapture area PinmemberWeb cam26-Apr-08 1:52 
GeneralBut how I can get the vedio screen in web Pinmembercscrazy16-Mar-08 21:18 
GeneralCOM class error Pinmemberdebiannerd15-Mar-08 14:52 
GeneralRe: COM class error Pinmemberdebiannerd16-Mar-08 2:33 
GeneralNot capturing balloon tips. PinmemberAdamPound3-Mar-08 4:48 
GeneralRe: Not capturing balloon tips. PinmemberArmoghan Asif3-Mar-08 23:32 
GeneralConverted the project to VS 2008 caused a problem. Pinmemberozonic22-Nov-07 12:26 
GeneralRe: Converted the project to VS 2008 caused a problem. Pinmemberozonic22-Nov-07 14:37 
GeneralHelp Bug Fixing !!! PinmemberTauhid Shaikh21-Sep-07 1:41 
GeneralRe: Help Bug Fixing !!! PinmemberArmoghan Asif21-Sep-07 19:03 
GeneralRe: Help Bug Fixing !!! PinmemberTauhid Shaikh21-Sep-07 20:38 
GeneralRe: Help Bug Fixing !!! PinmemberArmoghan Asif22-Sep-07 2:38 
GeneralAudio Out Capture !!! PinmemberTauhid Shaikh21-Sep-07 1:11 
GeneralRe: Audio Out Capture !!! PinmemberArmoghan Asif21-Sep-07 19:00 
GeneralRe: Audio Out Capture !!! PinmemberTauhid Shaikh21-Sep-07 20:58 
GeneralRe: Audio Out Capture !!! PinmemberArmoghan Asif22-Sep-07 2:41 
GeneralRe: Audio Out Capture !!! PinmemberTauhid Shaikh22-Sep-07 2:47 
GeneralVideo Quality !!! PinmemberTauhid Shaikh19-Sep-07 22:13 
GeneralRe: Video Quality !!! PinmemberArmoghan Asif19-Sep-07 23:32 
GeneralRe: Video Quality !!! PinmemberTauhid Shaikh21-Sep-07 1:07 
GeneralRe: Video Quality !!! PinmemberArmoghan Asif21-Sep-07 18:54 
GeneralRe: Video Quality !!! PinmemberTauhid Shaikh21-Sep-07 19:49 
QuestionDouble-click Pinmemberdennisss8015-Aug-07 1:59 
AnswerRe: Double-click PinmemberArmoghan Asif16-Aug-07 23:54 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 24 Nov 2004
Article Copyright 2004 by Armoghan Asif
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid