Screen capture using Windows Media Encoder

If you have to screen capture using Windows Media Encoder please follow the steps below.

Start Windows Media Encoder (WM Encoder).

To download WM encoder please refers to the link https://www.microsoft.com/downloads/details.aspx?FamilyID=5691ba02-e496-465a-bba9-b2f1182cdf24&displaylang=en.

The file is “WMEncoder.exe” which is of size 9.45 MB approximately. Install it and you get Windows Media under Start-> All Programs.

 To capture the screen here are the steps.

1. Start Windows Media Encoder.

2. Select “Capture screen” from the “New Session” dialog.

3. Click at OK.

4. Specify what you would like to capture. You could capture a specific window, or a particular region of the screen or the entire screen.

5. Click at “Next” and specify a file name where you would like to save the media.

6. Select the compression factor to either low or medium or high.

7. Click at next. You could also set the display information.

8. Finally click “Finish”. It will give you the option to start encoding immediately or you could start it later from the menu.

In a typical example with compression factor set to high we see the following statistics:

The codec used is “Windows Media Video 9 Screen”.

The Windows Media Video 9 Screen codec is optimized for compressing sequential screenshots and highly static video that is captured from the computer display, which makes it ideal for delivering demos or demonstrating computer use for training. The codec takes advantage of the typical image simplicity and relative lack of motion to achieve a very high compression ratio.

This codec is available from Windows Media Player 6.4 or later and so it obviously available from Windows XP.

For more reading please refer to the link https://www.microsoft.com/windows/windowsmedia/forpros/codecs/video.aspx.

Let us look into some code. To set up you need to have Windows Media Encoder 9 Series SDK. Download it from the link https://www.microsoft.com/downloads/details.aspx?familyid=000A16F5-D62B-4303-BB22-F0C0861BE25B&displaylang=en.

Install it and you would get it added to your Start-> All Programs menu.

 

You also get the “Windows Media Encoder SDK” help file.

Please see the topic “Using a Screen Capture as a Source” from the help menu. It has the managed as well as the unmanaged reference.

Here is some unmanaged reference code that you could start with.

// ScreenCapture.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

// Include libraries.

#include <windows.h>

#include <atlbase.h>

#include <comdef.h>

#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"

// Define the screen capture properties.

#define WMSCRNCAP_CAPTUREWINDOW CComBSTR("CaptureWindow")

#define WMSCRNCAP_WINDOWLEFT CComBSTR("Left")

#define WMSCRNCAP_WINDOWTOP CComBSTR("Top")

#define WMSCRNCAP_WINDOWRIGHT CComBSTR("Right")

#define WMSCRNCAP_WINDOWBOTTOM CComBSTR("Bottom")

#define WMSCRNCAP_FLASHRECT CComBSTR("FlashRect")

#define WMSCRNCAP_ENTIRESCREEN CComBSTR("Screen")

#define WMSCRNCAP_WINDOWTITLE CComBSTR("WindowTitle")

int _tmain(int argc, _TCHAR* argv[])

{

    // Declare variables.

    HRESULT hr = S_OK;

    IWMEncoder* pEncoder;

    IWMEncSourceGroupCollection* pSrcGrpColl;

    IWMEncSourceGroup* pSrcGrp;

    IWMEncSource* pSrc;

    IWMEncVideoSource2* pSrcVid;

    IPropertyBag* pPropertyBag;

    CComVariant varValue;

    // Initialize the COM library and retrieve a pointer to an IWMEncoder interface.

    hr = CoInitialize(NULL);

    if ( SUCCEEDED( hr ) )

    {

        hr = CoCreateInstance(CLSID_WMEncoder,

            NULL,

            CLSCTX_INPROC_SERVER,

            IID_IWMEncoder,

            (void**) &pEncoder);

    }

    // Retrieve the source group collection.

    if ( SUCCEEDED( hr ) )

    {

        hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);

    }

    // Add a source group to the collection.

    if ( SUCCEEDED( hr ) )

    {

        hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);

    }

    if ( SUCCEEDED( hr ) )

    {

        hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrc);

    }

    // Retrieve an IWMEncVideoSource2 pointer.

    if ( SUCCEEDED( hr ) )

    {

        hr = pSrc->QueryInterface(IID_IWMEncVideoSource2, (void**)&pSrcVid);

    }

    // Add a video source to the source group.

    if ( SUCCEEDED( hr ) )

    {

        hr = pSrcVid->SetInput(CComBSTR("ScreenCap://ScreenCapture1"));

    }

    // Retrieve a pointer to the property bag.

    if ( SUCCEEDED( hr ) )

    {

        hr = pSrcVid->QueryInterface(IID_IPropertyBag, (void**)&pPropertyBag);

    }

    // Set full screen capture.

    {

        varValue = true;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_ENTIRESCREEN, &varValue );

        }

    }

    // Set the capture area.

    {

        // nLeft, nRight, nTop, and nBottom are the dimensions to capture

        int nLeft, nRight, nTop, nBottom;

        nLeft = nTop = 0;

         // Get screen size

         nRight = GetSystemMetrics(SM_CXSCREEN);

         nBottom = GetSystemMetrics(SM_CYSCREEN);

        // Initialize the capture area. The size must be even.

        varValue = false;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_ENTIRESCREEN, &varValue );

        }

        varValue = nLeft;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_WINDOWLEFT, &varValue );

        }

        varValue = nRight;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_WINDOWRIGHT, &varValue );

        }

        varValue = nTop;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_WINDOWTOP, &varValue );

        }

        varValue = nBottom;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_WINDOWBOTTOM, &varValue );

        }

        varValue = true;

        if ( SUCCEEDED( hr ) )

        {

            hr = pPropertyBag->Write( WMSCRNCAP_FLASHRECT, &varValue );

        }

        // Continue configuring the encoding session.

        // Release pointers.

        if ( pSrcGrpColl )

        {

            pSrcGrpColl->Release();

            pSrcGrpColl = NULL;

        }

        if ( pSrcGrp )

        {

            pSrcGrp->Release();

            pSrcGrp = NULL;

        }

        if ( pSrcVid )

        {

            pSrcVid->Release();

            pSrcVid = NULL;

        }

        if ( pSrc )

        {

            pSrc->Release();

            pSrc = NULL;

        }

        if ( pPropertyBag )

        {

            pPropertyBag->Release();

            pPropertyBag = NULL;

        }

        if ( pEncoder )

        {

            pEncoder->Release();

            pEncoder = NULL;

        }

    }

    return 0;

}

 

-Shamik