Windows Media Format Newbe RRS feed

  • Question

  • Hi Everyone,

    I'm new to the Windows Media Format SDK, and have been playing around with it a bit, and after [semi] reading the documentation, I'm a bit stuck.

    Basically I'm trying to grab some rendered frames from the graphics card, and encode them into a windows media file in real time.

    But, I don't quite understand how to go about writing a raw frame to the IWMWriter.


    The code I am using is (taken mostly from the media format sdk help file):

    (called once at the start of the program)

    //create the writer
        HRESULT hr;
        hr = WMCreateWriter(NULL, &pWriter);
        if ( FAILED ( hr ) )

        //set its profile
        //set a defualt codec
        hr = pWriter->SetProfileByID(WMProfile_V80_56VideoOnly);
        if ( FAILED ( hr ) )

    //set its output file
        hr = pWriter->SetOutputFilename( L"test.wmv" );
        if ( FAILED ( hr ) )

        //ready it for data
        hr = pWriter->BeginWriting();
        if( FAILED ( hr ) )


    and then (per frame)


    //write the frame to the video for encoding
             DWORD sampleSize = 10240; //guess
             INSSBuffer* pSample = NULL;
             hr = pWriter->AllocateSample( sampleSize, &pSample );
             if( FAILED ( hr ) )

    (plus the actual writing of the data to the sample, and the WriteSample call)


    From reading the documentation, I understand that a IWMWriter is configured with a profile which consists of streams.

    And that samples have headers of some sort, but I'm still confused about:


    How to know how big a sample is when you allocate it?


    How to know what resolution of a video you are encoding?



    Greatly Appreciated,

    Chris Hoffman

    Wednesday, April 21, 2010 5:40 AM