Capture Desktop Activities As a Movie


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.

Up Next
    Ebook Download
    View all
    Learn
    View all