Click here to Skip to main content
Licence CPOL
First Posted 24 Nov 2004
Views 272,588
Bookmarked 135 times

Capture Activities on Screen in a Movie

By | 24 Nov 2004 | Article
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.

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.

SrcVid.SetInput("ScreenCap://ScreenCapture1")
SrcAud.SetInput("Device://Default_Audio_Device")

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
Next

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.
Encoder.Start()

Stop the encoding process:

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

About the Author

Armoghan Asif

Architect

Pakistan Pakistan

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNo more Windows Media Encoder 9? PinmemberNeWi11:12 17 Dec '10  
GeneralMy vote of 1 PinmemberSrinath G Nath19:43 24 Mar '10  
GeneralMy vote of 1 Pinmember(-Itz-Trist-)16:30 3 Oct '09  
GeneralGetting Eror while try to start recording Pinmembereg_Anubhava18:31 21 Aug '09  
Questionhow to capture a window not all screen C# Pinmembermquiz0:21 27 Apr '09  
GeneralWmEncoder on Vista PinmemberGamePlanner9:57 20 Apr '09  
GeneralRe: WmEncoder on Vista Pinmemberweihongqin19:03 6 Sep '09  
Questionhow set size of file Pinmemberavananda22:50 17 Apr '09  
AnswerRe: how set size of file PinmemberArmoghan Asif3:33 20 Apr '09  
GeneralColour quality on captured video PinmemberMember 370354822:43 30 Mar '09  
QuestionHelp with making snapshot!!! Pinmemberkatran.ek1:45 4 Mar '09  
Questionhow to decrease resolution screen when recording? Pinmemberping_jacob0:41 16 Feb '09  
Questionhow to improve quality? Pinmemberping_jacob7:10 26 Jan '09  
AnswerRe: how to improve quality? PinmemberArmoghan Asif23:43 27 Jan '09  
Generalnice PinmemberDhavalkumar P Patel3:18 23 Dec '08  
QuestionHow do WMencoder Works PinmemberNiyaHere22:13 19 Aug '08  
AnswerRe: How do WMencoder Works PinmemberArmoghan Asif22:51 19 Aug '08  
GeneralRe: How do WMencoder Works [modified] PinmemberNiyaHere19:23 20 Aug '08  
GeneralRe: How do WMencoder Works PinmemberArmoghan Asif18:42 24 Aug '08  
GeneralWTF doe "System.Runtime.InteropServices.COMException" mean Pinmemberbrian drwecki3:55 13 Jul '08  
Questioncapture area PinmemberWeb cam0:52 26 Apr '08  
GeneralBut how I can get the vedio screen in web Pinmembercscrazy20:18 16 Mar '08  
GeneralCOM class error Pinmemberdebiannerd13:52 15 Mar '08  
Hello,
 
I get this erreur when running in "debug" mode the code source on this website
 
"Retrieving the COM class factory for component with CLSID {632B606A-BBC6-11D2-A329-006097C4E476} failed due to the following error: 80040154."
 
and that is at the line "Encoder = New WMEncoder"
 
Now I dunno what is wrong... any idea? (I use VS 2008 and I have XP)
 
Thanks a lot Smile | :)
GeneralRe: COM class error Pinmemberdebiannerd1:33 16 Mar '08  
GeneralNot capturing balloon tips. PinmemberAdamPound3:48 3 Mar '08  

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.

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