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   
QuestionDoes not workmemberGandalpho7 May '13 - 8:29 
Hi, thank you for your project but it does not work, it crashes in the line where Encoder = New Encoder is with error "80040154" (whatever this is?)
I tried to install the SDK but your links are all 404.
Greetings from Leben England Wink | ;)
Questionvc++ formmemberAaa1.0017 Jul '12 - 16:45 
can you please make a vc++ form of your program and all of the files with it.
GeneralMy vote of 1memberkslawy14 Jul '12 - 20:55 
good
QuestionNo more Windows Media Encoder 9?memberNeWi17 Dec '10 - 11:12 
I have some code which uses the Windows Media Encoder COM interfaces. Records movies very nicely. But Microsoft has stopped support for it. You cant download and install the encoder anymore. Their web site says that is has been replaced with Expression Encoder, and installing that does not install the COM classes (running under Win 7, 64-bit but running 32-bit apps). I think somewhere else on here is an article about making AVI movies, and it can also be done using Apple's sdk.
 
See: http://www.microsoft.com/expression/products/Encoder4_Overview.aspx
 
"Windows Media Encoder is being retired by mid 2010."
 
Thanks, Microsoft. Mad | :mad:
GeneralMy vote of 1memberSrinath G Nath24 Mar '10 - 19:43 
Not working properly
GeneralMy vote of 1member(-Itz-Trist-)3 Oct '09 - 16:30 
It doesent work!
GeneralGetting Eror while try to start recordingmembereg_Anubhava21 Aug '09 - 18:31 
I run your software it's run perfect but when i try to start recording it generates error:
 
Error is given below.
 
Retrieving the com class factory for component with CLSID.
 
If you can think then I Can.

Questionhow to capture a window not all screen C#membermquiz27 Apr '09 - 0:21 
i want to select a process and capture not all screen?
how can i do this?
thanks a lot,
xuantuong
GeneralWmEncoder on VistamemberGamePlanner20 Apr '09 - 9:57 
I added some fancy stuff to your code so it works on Vista too. Added some menus in notify icon to list separate profiles under audio/video and audio-video ones. See http://mycomponent.blogspot.com/2009/04/capture-screen-activitiesvideo-using.html[^]
Also, for vista compatibility, you might like to see http://support.microsoft.com/kb/929182[^]
 
http://www.mycomponent.blogspot.com

GeneralRe: WmEncoder on Vistamemberweihongqin6 Sep '09 - 19:03 
CamePlanner:
I have developed a app to record screen and audio to a wmv file. I configured the profile throught a local .prx file. It can work fine under XP, but when runing under Vista, always error happpened.
the Vista is installed both wmencoder 9 and hotfix(kb/929182).
can u tell me some special thing should to do to support vista?
also you can send to my mail directly: weihongqin@hotmail.com
 
best regards,
thomas
 
whq

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
GeneralRe: How do WMencoder Works [modified]memberNiyaHere20 Aug '08 - 19:23 
Hi,
 
Thanks for ur reply... Smile | :)
 
Could u pls tell me what will be the default frame rate for this? n How to set the same...
 
n still m confused about setting the time interval, like i wanna capture screen shot every 2 seconds. how can i do that by code?
 
Thanks
 
Niya
 
modified on Thursday, August 21, 2008 5:57 AM

GeneralRe: How do WMencoder WorksmemberArmoghan Asif24 Aug '08 - 18:42 
Hi
you just have to change the following line
 
Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)"
 
with the new profile you make using the method present in my previous comment.
 
Once you run the WMProEdt.exe and import pre existing profiles, you will get an idea how to set the framerate. You can make frame rate = 0.5 per second, should capture screen after two seconds.
GeneralWTF doe "System.Runtime.InteropServices.COMException" meanmemberbrian 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 areamemberWeb cam26 Apr '08 - 0:52 
Hi , how can i capture an area , not full screan ?thanx
GeneralBut how I can get the vedio screen in webmembercscrazy16 Mar '08 - 20:18 
I want to get vedio screen and save as picture in asp.net, how I can do
 
I did like to join the website

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

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