Discussion:
Media Format SDK C++
(too old to reply)
Chr1snv
2010-05-03 22:13:01 UTC
Permalink
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 ) )
exit(1);

//set its profile

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

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

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



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 ) )
return;

(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?

and

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





Greatly Appreciated,

Chris Hoffman
Alessandro Angeli
2010-05-04 19:52:21 UTC
Permalink
From: "Chr1snv"
Post by Chr1snv
From reading the documentation, I understand that a IWMWriter is
configured with a profile which consists of streams.
An ASF file, just like any other system stream, contains the elementary
streams' data plus metadata that describes the streams themselves
(usually called header and index).

A WMProfile is just a way of representing the stream headers and, as
such, is a collection of IWMStreamConfig's.
Post by Chr1snv
And that samples have headers of some sort, but I'm still confused
They don't. They have framing headers in the ASF file, but media samples
passed to the IWMWriter are just buffers of unstructured data.
Post by Chr1snv
DWORD sampleSize = 10240; //guess
How to know how big a sample is when you allocate it?
How to know what resolution of a video you are encoding?
Both questions have the same answer: when you fetch your input data from
whatever source you have, the source provides you a way to know how big
in terms of pixels and byte the pictures are.

Since you are the only one who knows how you are fetching the pictures
and from where, you are the only one who can answer that.
--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm
Loading...