Tuesday, May 05, 2009

Windows Media (WM) Screen capturing by window handle

There is a C++ interface MS has provided to do this but in .net C# interop it's not available.

You have to use the IPropertyBag class based on it's GUID

[Guid("55272A00-42CB-11CE-8135-00AA004BB851")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPropertyBag
{
void Read(String propName, out object ptrVar, int errorLog);
void Write(string propName, ref object ptrVar);
}



and copy and past this code before starting

IPropertyBag ipb = (IPropertyBag)
object value = false;

ipb.Write("Screen", ref value);
ipb.Write("CaptureWindow", ref Int32OfHandler);


Also make sure when you set the handle to set the encoding also to screen capturing


object codecName;
int codec_index = 2;

for (int i = 0; i < Profile.VideoCodecCount; ++i)
{
lVid4cc = Profile.EnumVideoCodec(i, out codecName);

//Compare if the current codec is Windows Media Video 9 Screen
if (codecName.ToString().Equals("Windows Media Video 9 Screen"))
{
codec_index = i; exit for;
}
}

// Set the IWMEncAudienceObj
Audnc.set_VideoCodec(0, codec_index);

3 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.