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

Configuring the WM Asf writer for compressed video

452 views
Skip to first unread message

Bwian

unread,
Mar 6, 2008, 4:40:00 PM3/6/08
to
I am attempting to write compressed samples from a stream to a wmv file,
using directshow. My first attempt is to play video from a wmv-file encoded
by WMVideoEncoder9 and feed it directly to the ASF-writer filter.

The first obstacle is to use configuring the asf writer filter is to provide
it with the correct profile.

I load my profile from a .prx-file which I have tested with media-encoder (
I ripped the stream configuration from the media encoder profile). The asf
writer accepts the profile, but the mediatypes are strange (the readers video
output pin has subtype WMV3, the asf writer has subtype null. The asf writers
format type is null as well). Here follows a stripped down vesion of my code
(error checking and diagnostic functions omitted):


_asfReader = Common.createFilter(AsfReaderGuid);
//Graphbuilder is a IGarphbuilder interface
hr = _graphBuilder.AddFilter(_asfReader, "ASFReader");

_asfReaderSource = _asfReader as IFileSourceFilter;
_asfReaderSource.Load(@"C:\vidiview\test\Film.wmv", null);
_asfReaderOutput = DsFindPin.ByDirection(_asfReader, PinDirection.Output, 0);

_asfWriter = Common.AddFilter(_graphBuilder, AsfWriterGuid, "AsfWriter");
IFileSinkFilter2 outputSink = _asfWriter as IFileSinkFilter2;

outputSink.SetMode(AMFileSinkFlags.OverWrite);
hr = outputSink.SetFileName(fileName, outputMediaType);

IWMProfileManager profileManager = null;
WMFSDKFunctions.WMCreateProfileManager(out profileManager);

IConfigAsfWriter2 asfConfig = _asfWriter as IConfigAsfWriter2;
hr = asfConfig.SetParam(ASFWriterConfig.DontCompress, 1, 0);
hr = asfConfig.ConfigureFilterUsingProfile(profile);

//The writer has the correct number of pins, find the video input
_asfWriterInput = DsFindPin.ByDirection(_asfWriter, PinDirection.Input, 0);

//Fails because there is no common mediatype
hr = _graphBuilder.ConnectDirect(_asfReaderOutput, _asfWriterInput, null);

//Start the graph
hr=_mediaControl.Run();

If anyone knows what I am doing wrong when configuring the writer, I would
be grateful.

Thank you in advance

Alessandro Angeli

unread,
Mar 6, 2008, 5:31:13 PM3/6/08
to
From: "Bwian"

> The first obstacle is to use configuring the asf writer
> filter is to provide it with the correct profile.

[...]

Q20 in my FAQ (link below) provides the C++ source code for
an ASF muxer that is *much* friendlier than the stock
WMASFWriter (but does not support re-compression). Even if
you to keep using the WMASFWriter, you can extract the code
to create a profile from a set of media types (you need most
of the code in VAsfMuxFilter::VAsfMuxFilter() and
CAsfMuxFilter::CheckMediaType()). Even steps that seem
unnecessary, like setting the bitrate to an arbitrary large
value, must be there if you want this to work without major
headaches.


--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm


Bwian

unread,
Mar 7, 2008, 3:34:02 AM3/7/08
to
Thank you for the fast reply. I'll examine your code and see what I can learn
from it.

babgvant

unread,
Mar 10, 2008, 5:20:34 PM3/10/08
to
On Mar 6, 5:31 pm, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

>
> Q20 in my FAQ (link below) provides the C++ source code for
> an ASF muxer that is *much* friendlier than the stock
> WMASFWriter (but does not support re-compression).

Should the sample muxer accept input from the WMVideo9 Encoder DMO? It
does accept input from the WMAudio Encoder DMO.

Great sample btw, so many things to try out :)

Alessandro Angeli

unread,
Mar 11, 2008, 2:55:39 PM3/11/08
to
From: "babgvant"

> Should the sample muxer accept input from the WMVideo9
> Encoder DMO? It does accept input from the WMAudio
> Encoder DMO.

It should. I never tried the DMO, but it has no problems
with WMV data coming from a file. What error do you get? Are
you correctly copying the 4 or 5 extra bytes after the
BITMAPINFOHEADER into the media type's format block?

babgvant

unread,
Mar 11, 2008, 5:26:46 PM3/11/08
to
On Mar 11, 1:55 pm, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

> It should. I never tried the DMO, but it has no problems
> with WMV data coming from a file. What error do you get? Are
> you correctly copying the 4 or 5 extra bytes after the
> BITMAPINFOHEADER into the media type's format block?

Initially I wasn't doing anything to configure it and I was getting a
memory access violation error, the wma dmo worked perfectly w/o config
so I was hoping the wmv one would too. I downloaded the WMAVCodec
SDK, when I get a chance I'll take a look to see how to configure the
DMO. The last time I looked at the sample that uses the DMO to
compress an AVI file it looked reasonably complex.

Do you think it would be easier to do that or for me to modify your
sample to perform compression? I saw two things that I would have to
change (not nulling the input media types, and using the wmwriter
instead of the advanced writer), but there are probably others that I
missed.

One other thing I was thinking of trying was incorporating the VC-1
encoder class that MS released recently in the WriteStreamSample
method to encode video samples, but leaving the audio alone (using the
wma dmo to encode it since that works perfectly). Do you think that
would work?

Alessandro Angeli

unread,
Mar 11, 2008, 6:20:45 PM3/11/08
to
From: "babgvant"

[...]


> One other thing I was thinking of trying was
> incorporating the VC-1 encoder class that MS released
> recently in the WriteStreamSample method to encode video
> samples, but leaving the audio alone (using the wma dmo
> to encode it since that works perfectly). Do you think
> that would work?

It should, but it seems more work than just using the stock
WMASFWriter. The WM[ASF]Writer will use the WMA DMO for you
and the VC-1 DMO as well (IIRC, the WMV9AP encoder that you
can select in the profile is just the WM name for the VC-1
encoder that ships with the WMF11 runtime, that is 'WVC1'
aka WMMEDIASUBTYPE_WVC1).

babgvant

unread,
Mar 12, 2008, 10:45:45 AM3/12/08
to
On Mar 11, 5:20 pm, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:
>

> It should, but it seems more work than just using the stock
> WMASFWriter. The WM[ASF]Writer will use the WMA DMO for you
> and the VC-1 DMO as well (IIRC, the WMV9AP encoder that you
> can select in the profile is just the WM name for the VC-1
> encoder that ships with the WMF11 runtime, that is 'WVC1'
> aka WMMEDIASUBTYPE_WVC1).
>

The WMAsfWriter doesn't support multi-channel audio encoding, and
using the WMA DMO to encode the audio pre-writer doesn't work with
WMF11 (it did with v9).

Is the VC-1 DMO you mentioned different than the WM9Video DMO
configured to output VC-1? The encoder included in the VC-1 SDK is
supposed to be faster and easier to configure than the WMV9Video DMO,
so that's why I was looking at it v. the WM9Video DMO configured to
output VC-1 approach.

Alessandro Angeli

unread,
Mar 12, 2008, 2:06:19 PM3/12/08
to
From: "babgvant"

> Is the VC-1 DMO you mentioned different than the WM9Video
> DMO configured to output VC-1?

No, I think it's just one DMO that encodes to all WMV
versions according to the configuration.

> The encoder included in
> the VC-1 SDK is supposed to be faster and easier to
> configure than the WMV9Video DMO, so that's why I was
> looking at it v. the WM9Video DMO configured to output
> VC-1 approach.

When I looked at the VC-1 Enc SDK it didn't seem to provide
any DMO but only a link library, so you would have to write
a DMO or filter or VCM codec around it.


> The WMAsfWriter doesn't support multi-channel audio
> encoding, and using the WMA DMO to encode the audio
> pre-writer doesn't work with WMF11 (it did with v9).


Well, my muxer uses the WMWriter just like the WMASFWriter
does so it may have the same problem muxing pre-compressed
WMA with v11 of the runtime (even though it doesn't seem to,
I have tried multi-channel PCM and stereo WMA).

I don't remember the details of the thread, but is there a
reason why you are using DirectShow instead of the WMWriter
directly? The WMWriter accepts multichannel PCM as
compression input and you would be able to feed it the
output of the VC-1 Enc SDK without any DS-compatible
wrapper.

babgvant

unread,
Mar 12, 2008, 5:47:58 PM3/12/08
to
On Mar 12, 1:06 pm, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:
>

> When I looked at the VC-1 Enc SDK it didn't seem to provide
> any DMO but only a link library, so you would have to write
> a DMO or filter or VCM codec around it.
>

That was my impression of the SDK as well. My thinking was that I
could use take the uncompressed sample and feed it through the encoder
when your filter receives them. I have no idea if this is even
remotely viable, but it was an idea I was tossing around.

> Well, my muxer uses the WMWriter just like the WMASFWriter
> does so it may have the same problem muxing pre-compressed
> WMA with v11 of the runtime (even though it doesn't seem to,
> I have tried multi-channel PCM and stereo WMA).

The problem is specific to the WMASFWriter, your muxer works great.

> I don't remember the details of the thread, but is there a
> reason why you are using DirectShow instead of the WMWriter
> directly? The WMWriter accepts multichannel PCM as
> compression input and you would be able to feed it the
> output of the VC-1 Enc SDK without any DS-compatible
> wrapper.
>

The files I'm trying to convert to wmv are dvr-ms files, DirectShow is
the best way that I'm aware of to decompress the content so it can be
converted to WMV.

Alessandro Angeli

unread,
Mar 12, 2008, 6:12:11 PM3/12/08
to
From: "babgvant"

> That was my impression of the SDK as well. My thinking
> was that I could use take the uncompressed sample and
> feed it through the encoder when your filter receives
> them. I have no idea if this is even remotely viable,
> but it was an idea I was tossing around.

Sure it is possible: you have the source code, so you can do
whatever you want to the data before calling
IWMWriterAdvanced3::WriteStreamSample().

babgvant

unread,
Mar 13, 2008, 10:05:50 AM3/13/08
to
On Mar 12, 5:12 pm, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:
>

> Sure it is possible: you have the source code, so you can do
> whatever you want to the data before calling
> IWMWriterAdvanced3::WriteStreamSample().
>

Do you think doing video compression at that stage would introduce
issues (synchronization, timing, etc), since the audio will already be
compressed?

Alessandro Angeli

unread,
Mar 13, 2008, 12:24:20 PM3/13/08
to
From: "babgvant"

> Do you think doing video compression at that stage would
> introduce issues (synchronization, timing, etc), since
> the audio will already be compressed?

The WriteStreamSample() method has code to block in order to
maintain the streams properly interleaved. As long as you
perform the compression before that block of code and
outside the autolock, it will work as expected, no matter
whether the compression is done in WriteStreamSample()
(video) or in the code that calls it (audio, the code that
calls it is executed before the interleaving autolocked
block).

babgvant

unread,
Mar 16, 2008, 10:17:47 PM3/16/08
to
On Mar 13, 11:24 am, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

>
> The WriteStreamSample() method has code to block in order to
> maintain the streams properly interleaved. As long as you
> perform the compression before that block of code and
> outside the autolock, it will work as expected, no matter
> whether the compression is done in WriteStreamSample()
> (video) or in the code that calls it (audio, the code that
> calls it is executed before the interleaving autolocked
> block).

Great. Thanks again for the insight and the sample.

Cheers.


babgvant

unread,
Mar 23, 2008, 9:57:57 PM3/23/08
to
I ended up modifying the application to use the IWMWriter to compress
the samples, after trying to get it working with the WM9 DMO.

I didn't see any licensing info in the sample; what license is it
distributed under? I would like to publish the application and the
source under a reciprocal type source license if that's ok with you.

Thanks again.

Alessandro Angeli

unread,
Mar 24, 2008, 10:03:37 AM3/24/08
to

From: "babgvant"

> I didn't see any licensing info in the sample; what
> license is it distributed under?

I have been lazy and just published the code :-)

> I would like to publish
> the application and the source under a reciprocal type
> source license if that's ok with you.

Sure, the Ms-RL or anything similar is ok. Just let me know
so I can put a link to your modified source code.

babgvant

unread,
Mar 24, 2008, 9:52:27 PM3/24/08
to
On Mar 24, 9:03 am, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

> I have been lazy and just published the code :-)

It really is too bad that we have to deal with that aspect of writing
code.

> Sure, the Ms-RL or anything similar is ok. Just let me know
> so I can put a link to your modified source code.

Perfect. I like to use a slightly modified version of the Ms-RL.
http://babgvant.com/files/folders/misc/entry8690.aspx

The code is still very rough. I need to do several things to make it
really consumable (changing the project name and the guids to name a
couple), It doesn't help that I don't know how to do anything in C+
+ :)

I didn't know how you prefer to be accredited, let me know if "This
application is based on the work of Alessandro Angeli. The original
application can be downloaded from his website http://www.riseoftheants.com/mmx/faq.htm"
is OK. I'm happy to add whatever you want.

Thanks again.

Alessandro Angeli

unread,
Mar 26, 2008, 2:55:02 PM3/26/08
to
From: "babgvant"

> I didn't know how you prefer to be accredited, let me
> know if "This
> application is based on the work of Alessandro Angeli.
> The original
> application can be downloaded from his website
> http://www.riseoftheants.com/mmx/faq.htm" is OK. I'm
> happy to add whatever you want.

That's perfect, thank you.

0 new messages