Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create ASF File Using XVID Codecs

87 views
Skip to first unread message

kyo97

unread,
May 18, 2005, 12:44:01 AM5/18/05
to
Hi:

I'm trying to create ASF files using XVID Codecs with the WM Format SDK.
I have read the SDK document carefully and follow its instruction.
I create a new WM_MEDIA_TYPE for XVID codec, and assign the value. But when
I call IWMMediaProps::SetMediaType, it fails with
0xC00D003C (NS_E_INVALID_STREAM). Does anyone know why ? Thanks in advance.

The code is below :

WM_MEDIA_TYPE wmtMediaType;
WMVIDEOINFOHEADER vihVideoInfo;

// Create Video stream
hr = m_pProfile->CreateNewStream( WMMEDIATYPE_Video, &pStreamConfig );

if ( FAILED( hr ) ) break;
assert( pStreamConfig );

// Configure the new stream
hr = pStreamConfig->SetStreamNumber( 1 ); // omit to check hr
hr = pStreamConfig->SetStreamName( L"XVID Video Stream" );
hr = pStreamConfig->SetConnectionName( L"XVID Video Connection" );
hr = pStreamConfig->SetBufferWindow( (DWORD)1024 );
hr = pStreamConfig->SetBitrate( 3 * 640 * 480 * 30 );

// Configure media type
ZeroMemory( &wmtMediaType, sizeof( wmtMediaType ) );
wmtMediaType.majortype = WMMEDIATYPE_Video;
wmtMediaType.subtype = WMMEDIATYPE_XVID;
wmtMediaType.bFixedSizeSamples = TRUE;
wmtMediaType.bTemporalCompression = FALSE;
wmtMediaType.lSampleSize = 3 * 640 * 480 / 8;
wmtMediaType.formattype = WMFORMAT_VideoInfo;
wmtMediaType.pUnk = NULL; // Not used.
wmtMediaType.cbFormat = sizeof( WMVIDEOINFOHEADER );
wmtMediaType.pbFormat = (BYTE*) &vihVideoInfo;

// Set up the WMVIDEOINFOHEADER structure
ZeroMemory( &vihVideoInfo, sizeof( vihVideoInfo ) );
vihVideoInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
vihVideoInfo.bmiHeader.biPlanes = 1;
vihVideoInfo.bmiHeader.biSizeImage = 640 * 480 * 3;
vihVideoInfo.bmiHeader.biWidth = 640;
vihVideoInfo.bmiHeader.biHeight = 480;
vihVideoInfo.bmiHeader.biCompression =
MAKEFOURCC(_T('X'),_T('V'),_T('I'),_T('D') );
vihVideoInfo.rcSource.right=640;
vihVideoInfo.rcSource.bottom=480;
vihVideoInfo.rcTarget.right=640;
vihVideoInfo.rcTarget.bottom=480;

vihVideoInfo.dwBitRate = 3 * 30 * 8;
vihVideoInfo.AvgTimePerFrame = ( (LONGLONG) 10000000 ) / (
(LONGLONG) 30 );

hr = pStreamConfig->QueryInterface( IID_IWMMediaProps, (void**)
&pMediaProps );
if ( FAILED( hr ) )
{
break;
}
assert( pMediaProps );

hr = pMediaProps->SetMediaType( &wmtMediaType );
if ( FAILED( hr ) )
{
break;
}

Dmitry Vergeles (SolveigMM)

unread,
May 18, 2005, 4:44:34 AM5/18/05
to
Hi kyo97,

WMWriter is able to encode a video only by means of windows media codecs.
If you wanna write pre-encoded XVID video to ASF you have to create own ASF
Writer filter.
Also you can make use of SolveigMM ASF Muxer to be designed for such
purposes exactly.

I this case you just build directshow graph f.e. as follows:

File src->AVI Splitter->XVID encoder->SolveigMM ASF Muxer

More info you can read here:
http://www.elecard.ru/forum/viewtopic.php?t=501
http://forum.doom9.org/showthread.php?s=&threadid=92136

Regards,
Dmitry Vergeles


"kyo97" <ky...@discussions.microsoft.com> wrote in message
news:E83E9342-430A-4141...@microsoft.com...

Alessandro Angeli [MVP::DigitalMedia]

unread,
May 19, 2005, 11:53:16 PM5/19/05
to
Dmitry Vergeles (SolveigMM) wrote:

> If you wanna write pre-encoded XVID
> video to ASF you have to create own ASF Writer filter.
> Also you can make use of SolveigMM ASF Muxer to be
> designed for such purposes exactly.

Why can't the OP just use the stock WMASFWriter, properly
configured in pass-through node, to mux DivX-compressed data
into ASF?


--

// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net


Dmitry Vergeles (SolveigMM)

unread,
May 20, 2005, 1:01:29 AM5/20/05
to
Hi Alessandro,

Actually you right, but IMHO it's more hardly since
in terms of a common solution a developer have to provide a realization for
additional tasks e.g.demultilexing.
Moreover the initial issue was to encode and multiplex a video
simultaneously.
For this I think resonably to use DirectShow.

Am I wrong?

Best Regards,
Dmitry Vergeles
www.solveigmm.com


"Alessandro Angeli [MVP::DigitalMedia]" <nob...@nowhere.in.the.net> wrote in
message news:OhO0SHPX...@TK2MSFTNGP10.phx.gbl...

Alessandro Angeli [MVP::DigitalMedia]

unread,
May 20, 2005, 2:24:09 AM5/20/05
to
Dmitry Vergeles (SolveigMM) wrote:

> Hi Alessandro,
>
> Actually you right, but IMHO it's more hardly since
> in terms of a common solution a developer have to provide
> a realization for additional tasks e.g.demultilexing.
> Moreover the initial issue was to encode and multiplex a
> video simultaneously.
> For this I think resonably to use DirectShow.
>
> Am I wrong?

You're right about DirectShow of course. But I was asking
why the WMASFWriter filter provided by the system's
DirectShow wrapper for WMF can not be used to mux
DivX-compressed data into ASF instead of writing a custom
filter or using a third-party one.

Dmitry Vergeles (SolveigMM)

unread,
May 20, 2005, 5:06:33 AM5/20/05
to
That's very interesting question, but as far as I know such ones usually to
be demanded from you :)
Really I don't know why MS has not provided such feature in their WMWriter
DS.

Please correct me if I miss something.

1. WM ASF writer DS filter property page only enumeres profiles with codecs.

So lets have a look into the documentation:

DirectX 9.0 Documentation:
WM ASF writer support IConfigAsfWrite.
By means of IConfigAsfWrite::ConfigureFilterUsingProfile one theoretically
can set uncompressed profile but exepting an appropreated profile
a precompressed data have to be written through IWMWriterAdvanced ::
WriteStreamSample routine.

Do you think MS filter do this automatically based on a profile?

WMFSDK documentation:
WM ASF writer support IWMWriterAdvanced2 interface.
So, one theoretically can call IWMWriterAdvanced :: WriteStreamSample
manually but fisrt this is not already DirectShow and secondly
the documentation says:
"The IWMWriterAdvanced2 interface controls video deinterlacing, and is
useful if the input is an interlaced source, such as DV (digital video). Use
the GetInputSetting and SetInputSetting methods to control deinterlacing. It
is not recommended that clients use any of the other methods on this
interface"


So, do you think/know there is a right way to write precompressed streams
with help of WM ASF Writer DS filter?

Best Regards,
Dmitry Vergeles
www.solveigmm.com

"Alessandro Angeli [MVP::DigitalMedia]" <nob...@nowhere.in.the.net> wrote in

message news:u7Cu0RQX...@TK2MSFTNGP12.phx.gbl...

Terry Campbell

unread,
May 20, 2005, 10:25:58 AM5/20/05
to
You are correct!

XviD can be stored in ASF for DivX playback by the Windows Media Player
using the WMFormat SDK to setup the writer and profile.

(1) Set up your writer profile with DivX as your Subtype (DivX has a WM
codec for reader playback).

(2) PreCompress your input using XviD (or DivX if licensed) and write
the raw samples using IWMWriterAdvanced :: WriteStreamSample. Take
care if using CBR (the writer is picky regarding bit rate vs. input
sample sizes - VBR is best). If using XviD to compress and DivX to
decompress - make sure that you only use XviD settings that are fully
compatible with DivX. Also remember that you will need to set your own
KF's to the writer (the first frame must always be a KF :) ). Also,
remember that when bypassing the internal Codecs on a given stream to
set that stream input to NULL.

I know that this configuration works, because I am currently doing it.
I take DIB input and either send them to the IWMWriter to be compressed
using one of the various WMV codecs, or I pre-compress the input using
XviD and send the samples in raw. I also found that I can stuff raw
jpeg's to the writerAdv as Mjpeg (internally), however, Player 10
will not play the content - although Player 9 did (but I digress).

Of course, nothing is ever as simple as it seems when using the WM
Format SDK so be prepared for any number of annoying little issues, but
as I recall they were all easily compensated for.

Cheers,
Terry

Alessandro Angeli [MVP::DigitalMedia]

unread,
May 23, 2005, 1:29:38 AM5/23/05
to
Dmitry Vergeles (SolveigMM) wrote:

[CUT]


> So, do you think/know there is a right way to write
> precompressed streams with help of WM ASF Writer DS
> filter?

I was thinking of this:

http://msdn.microsoft.com/library/en-us/wmform95/htm/insertingnativestreamformatsintoasffilesqasf.asp

Dmitry Vergeles (SolveigMM)

unread,
May 23, 2005, 1:52:32 AM5/23/05
to
Thanks Alessandro,

I didn't see this topic, really.
So, it has to be tried.

Regards,
Dmitry

"Alessandro Angeli [MVP::DigitalMedia]" <nob...@nowhere.in.the.net> wrote in

message news:uAe%23ki1XF...@TK2MSFTNGP15.phx.gbl...

Dmitry Vergeles (SolveigMM)

unread,
May 23, 2005, 2:41:29 AM5/23/05
to
Hi Terry ,

Thanks you for the explanation, but actually I haven't understood if you are
using DirectShow WM ASF writer.
So, do you?

Regards,
Dmitry


"Terry Campbell" <tcam...@securityandmonitoring.com> wrote in message
news:1116599157.9...@g14g2000cwa.googlegroups.com...

Alessandro Angeli [MVP::DigitalMedia]

unread,
May 23, 2005, 3:26:02 AM5/23/05
to
Dmitry Vergeles (SolveigMM) wrote:

> Thanks you for the explanation, but actually I haven't
> understood if you are using DirectShow WM ASF writer.
> So, do you?

I suppose that, if he uses IWMWriter and IWMWriterAdvanced,
he can not be using DirectShow without hacking the
WMASFWriter filter.

Terry Campbell

unread,
May 23, 2005, 9:00:03 AM5/23/05
to
Hi Dmitry,

No, I do not use the Media9 DirectShow (QASF) wrappers (WM ASF
Reader/Writer).

I use the IWMWriter and its interfaces (IWMWriterAdvanced - etc.)
directly and 'roll' my own custom profiles. I wrap their functionality
as RCW's (runtime callable wrappers) for use in the Dot Net
environment.

I started out using DirectShow and I have a lot of respect for the
technology; however, I came to prefer the WMFormat SDK (at least for
the work that I am doing).

Currently, I do all of my work exclusively using the Windows Media
Format 9.5 SDK. In those cases where I need to wrap 3rd. party codecs
(such as XviD) I use the appropriate 3rd. party API or SDK and plug the
output into the Format SDK (as raw buffers).

I also use the DMO functionality introduced with Format 9.5 for live
streaming - so in a way I touch on a little of DirectX.

Efficiency is always something that I have to be very careful with as
the client that consumes me may be running many con-current (up to 60)
instants of my RCW in various configurations.

The Format SDK is not an easy beast to master (at least I did not think
so), but it has turned out to be a very powerful tool.

My code is currently in production and is running great - so I can
assure you that what you want to do is indeed possible.

Sorry about the lengthy reply.
Best of Luck,
Terry

Dmitry Vergeles (SolveigMM)

unread,
May 24, 2005, 4:52:18 AM5/24/05
to
Hi Terry,

Actually I know the approach you are describing.
Moreover we have own DirectShow WMWriter wrapper to allow an user to write
their precompressed audio/video stteams directly to ASF.
I was wondering if you used DirectShow writer to be configured as Alessandro
wrote.
In any event thank you for your definition.

Best Regards,
Dmitry Vegeles
www.solveigmm.com


"Terry Campbell" <tcam...@securityandmonitoring.com> wrote in message

news:1116853203.7...@g44g2000cwa.googlegroups.com...

Terry Campbell

unread,
May 24, 2005, 8:12:06 AM5/24/05
to
Actually, we started out our design process using DS, but ended up
wrapping our own environment. The "WM ASF Writer" DS Filter did not
offer us the flexibility that we desired. It exposes [most of] the
same interfaces (internally) as the IWMWriter (that it wraps); however,
it was always trying be smarter than we wanted it to be. We found that
it occasionally enforced "extra" processing logic around some of
the internal Format SDK interfaces that it wrapped - particularly
with certain custom profile configurations.

Having said this I offer the possibility that we were doing something
wrong; however, there were certain stream configurations that the QASF
object(s) would completely lose its mind on - but when working directly
with the IWMWriter/IWMReader within the Format SDK environment we
implemented our requirements with no problems.

In the end we built our own [expandable] custom environment built
directly on the WMFormat SDK and abandoned DS altogether because we
required ultra efficiency and massive concurrency. In DS you do
sacrifice a little efficiency for interoperability.

DirectShow is a great way to go in most cases though...

Good luck
Terry

Ragesh N K

unread,
May 25, 2007, 4:58:36 AM5/25/07
to
Hi Terry,

I Want to place video compressed with a custom codec (in place of XVID).
I am New to WMF SDK.
I am also facing teh same problem as kyo097 initially posted in this
discussion.
- ie IWMMediaProps::SetMediaTypefails with 0xC00D003C (NS_E_INVALID_STREAM).


Can you advice me a solution for it?

Thanking you in advance..

Ragesh

Ragesh N K

unread,
May 25, 2007, 5:02:53 AM5/25/07
to
Hi kyo097,

I am facing the same problem you faced..
the setmediatype failed..

Can you tell me how to solve this?

Thanks in advance..
Ragesh

0 new messages