SIGN UP MEMBER LOGIN:    
ARTICLE

Capture Desktop Activities As a Movie

Posted by Armoghan Asif Articles | GDI+ & Graphics February 18, 2005
This article shows to capture screen activities as a movie using Windows Media Encoder 9 SDK and C#.
Reader Level:

Introduction

This is my first article on this site. I wanted to capture screen activities as a Movie. While looking for it I found Windows Media Encoder 9. Which was free and had this facility. 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 in C#.

Prerequisites

You will be needing Windows Media Encoder 9 Series
http://www.microsoft.com/windows/windowsmedia/9series
/encoder/default.aspx

and SDK
http://www.microsoft.com/windows/windowsmedia/9series
/encoder/extensible.aspx

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

IWMEncSourceGroup2 SrcGrp;
IWMEncSourceGroupCollection SrcGrpColl;
SrcGrpColl = Encoder.SourceGroupCollection;
SrcGrp = (IWMEncSourceGroup2)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("ScreenCapture1","ScreenCap","");
SrcAud.SetInput("Default_Audio_Device","Device", ""); 

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

// All Profiles listed
// for( i = 0 ; i < lLength - 1; i++)
// Console.WriteLine (ProColl.Item(i).Name);
ProColl = Encoder.ProfileCollection
lLength = ProColl.Count
for (i = 0; i <= lLength - 1; i++)
{
Pro = ProColl.Item(i);
if (Pro.Name == "Screen Video/Audio High (CBR)")
{
SrcGrp.set_Profile((IWMEncProfile) Pro);
break;
}
}

Specify header inforamtion of the Encoder. I.e. Description or Attributes.

IWMEncDisplayInfo Descr;
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";
IWMEncAttributes Attr;
Attr = Encoder.Attributes;
Attr.Add("URL", "
www.adnare.com");

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.

IWMEncFile File;
File = Encoder.File;
File.LocalFileName = @"C:\OutputFile.wmv";

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.

Login to add your contents and source code to this article
share this article :
post comment
 

i am getting following error plz help me.The system cannot find file specified. {System.ComponentModel.Win32Exception: The system cannot find file specified.}project having zero errors , when i clicks on button then this error message appears. plz help me ........... or suggest changes at"suraj.nimse@rediffmail.com"

Posted by s nimse May 23, 2012

its good code but its not working in windows 7

Posted by Sapna Sahu Sep 30, 2011

I want code that can be capture screen as movie and can be send it by local network all that must be done by using c#.

Posted by mohammed ahmef Apr 09, 2010

I have used this application and it works quite nice. But i noticed a major issue in this application is that mouse double click does not working while capturing screen activities. Can you help me how to solve this issue

Thanx
KIRAN

Posted by KIRAN K S Nov 17, 2009

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

Posted by Niya Here Aug 20, 2008
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor