Click here to Skip to main content
Email Password   helpLost your password?

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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralMy vote of 1
(-Itz-Trist-)
17:30 3 Oct '09  
It doesent work!
GeneralGetting Eror while try to start recording
eg_Anubhava
19:31 21 Aug '09  
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.

Newshow to capture a window not all screen C#
mquiz
1:21 27 Apr '09  
i want to select a process and capture not all screen?
how can i do this?
thanks a lot,
xuantuong
GeneralWmEncoder on Vista
GamePlanner
10:57 20 Apr '09  
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 Vista
weihongqin
20:03 6 Sep '09  
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

Generalhow set size of file
avananda
23:50 17 Apr '09  
encoder fie size i slarge so i want to change the file size.
Please help me it's very very urgent.
GeneralRe: how set size of file
Armoghan Asif
4:33 20 Apr '09  
Change profile, which has a smaller file size
GeneralColour quality on captured video
Member 3703548
23:43 30 Mar '09  
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!!!
katran.ek
2:45 4 Mar '09  
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?
Generalhow to decrease resolution screen when recording?
ping_jacob
1:41 16 Feb '09  
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...
Generalhow to improve quality?
ping_jacob
8:10 26 Jan '09  
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?
Armoghan Asif
0:43 28 Jan '09  
Change profile from
Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)"
to
Pro.Name = Screen Video/Audio High (CBR)
Generalnice
Dhavalkumar P Patel
4:18 23 Dec '08  
Cool idea

Dhavalkumar Patel

GeneralHow do WMencoder Works
NiyaHere
23:13 19 Aug '08  
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 Works
Armoghan Asif
23:51 19 Aug '08  
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]
NiyaHere
20:23 20 Aug '08  
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 Works
Armoghan Asif
19:42 24 Aug '08  
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" mean
brian drwecki
4:55 13 Jul '08  
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
Web cam
1:52 26 Apr '08  
Hi , how can i capture an area , not full screan ?thanx
GeneralBut how I can get the vedio screen in web
cscrazy
21:18 16 Mar '08  
I want to get vedio screen and save as picture in asp.net, how I can do

I did like to join the website

GeneralCOM class error
debiannerd
14: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
debiannerd
2:33 16 Mar '08  
it is fine, found the problem, did not have the sdk installed.. bummer Smile
GeneralNot capturing balloon tips.
AdamPound
4:48 3 Mar '08  
is there an opacity setting. i tried everything.
BTW it captures them in Vista.
GeneralRe: Not capturing balloon tips.
Armoghan Asif
23:32 3 Mar '08  
It doesnot have any known opacity issue.
The sample in article is using Windows Media Encoder, and it should show it fine,

Please also try using different profiles , present in comments
GeneralConverted the project to VS 2008 caused a problem.
ozonic
12:26 22 Nov '07  
Since I converted the project to 2008, It won't run passed the following...

Encoder = New WMEncoder

It crashes on that line, any suggestions would be of help.


Last Updated 24 Nov 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010