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

Capture Activities on Screen in a Movie

By , 24 Nov 2004
 

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
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionhow set size of filememberavananda17 Apr '09 - 22:50 
encoder fie size i slarge so i want to change the file size.
Please help me it's very very urgent.
AnswerRe: how set size of filememberArmoghan Asif20 Apr '09 - 3:33 
Change profile, which has a smaller file size
GeneralColour quality on captured videomemberMember 370354830 Mar '09 - 22:43 
I have noticed that when you capture video using the Windows Media Encoder example (Under most settings) the colour quality is poor and only in a low colour depth. The only way i can get the capture video to appear in 16.7million colours is to set the codec to 'Full Frames Uncompressed', is there a better method then this?. Surely Microsoft cant expect users to be satisfied with low colour depth when using the high quality setting 'Screen Video/Audio High (CBR)' setting.
 
Any help much appreciated.
QuestionHelp with making snapshot!!!memberkatran.ek4 Mar '09 - 1:45 
I wonder if anybody knows howto get snapshot while encoder write video to wmv file. I need my app to make available writing video from webcam and screen, but I also need to make snapshot from my webcam in my app without stopping video writing. Does wmencoder has an opurtunity to read data from stream?
Questionhow to decrease resolution screen when recording?memberping_jacob16 Feb '09 - 0:41 
when i record file, i need to decrease resolution screen by code
 
i don't want to configuration in WMEncoder's profile.
 
how can i do it?
 
please give some tip or hint to me
 
thank so much...
Questionhow to improve quality?memberping_jacob26 Jan '09 - 7:10 
i tested this application but so blur
 
any text can't read
 
how to improve?, config framrate?
 
please give some hint or tip to me
 
thanks a lot
AnswerRe: how to improve quality?memberArmoghan Asif27 Jan '09 - 23:43 
Change profile from
Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)"
to
Pro.Name = Screen Video/Audio High (CBR)
GeneralnicememberDhavalkumar P Patel23 Dec '08 - 3:18 
Cool idea
 
Dhavalkumar Patel

QuestionHow do WMencoder WorksmemberNiyaHere19 Aug '08 - 22:13 
Hi,
 
Have a small query...Pls tell me whether WMencoder saves the screen shots anywhere in the local machine? or is it directly creating the .wav file ?
 
If it is creating temporary images/ screen shots , pls tell me where it is getting saved?
 
And whether I can set the encoder to take a screen shot in every 2 seconds or so..
 
Thanks in Advance
 
Niya
AnswerRe: How do WMencoder WorksmemberArmoghan Asif19 Aug '08 - 22:51 
WMEncoder saves stream to the file directly, no temporary place saving.
As it is saving video accoding to the profile, so you can set frames per second etc
 
Create a new profile by running following exe
C:\Program Files\Windows Media Components\Encoder\WMProEdt.exe
and set its FrameRate, Video Bit rate etc

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

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