Setting codec for compressed input
WMPTalk.com Forum Index WMPTalk.com
Discuss Windows Media Player
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web wmptalk.com
Setting codec for compressed input

 
Post new topic   Reply to topic    WMPTalk.com Forum Index -> SDK
Author Message
Matthew Schuyler Peck
Guest





Posted: Wed Oct 06, 2004 10:01 pm    Post subject: Setting codec for compressed input Reply with quote

I am trying to build an ASF file from existing G.711 mu-law data that I have.
I can't get the writer to actually set the codec information properly. The
resulting file won't play. It loads and shows in the playlist with the
appropriate time, but doesn't begin. Clicking the play button does nothing.
Clicking on the progress bar jumps ahead and plays a burst of static. Right
clicking and selecting properties on the playlist entry shows that the file
has no codec set. What am I doing wrong?

IWMProfile *profile;
IWMWriter *writer;
IWMWriterAdvanced *writerAdvanced;
IWMProfileManager *profileManager;
WMCreateProfileManager(&profileManager);
profileManager->CreateEmptyProfile(WMT_VER_9_0, &profile);
WMCreateWriter(NULL, &writer);
writer->SetOutputFilename(wFilename);
writer->QueryInterface(IID_IWMWriterAdvanced, (void**)&writerAdvanced);
IWMStreamConfig *config;
WM_MEDIA_TYPE mediaType;
WAVEFORMATEX formatEx;
profile->CreateNewStream(WMMEDIATYPE_Audio, &config);
config->SetBitrate(record->getFrequency() * 8);
config->SetBufferWindow(-1);
config->SetConnectionName(L"audiostream");
config->SetStreamName(L"audiostream");
config->SetStreamNumber(1);
formatEx.wFormatTag = WAVE_FORMAT_MULAW;
formatEx.nChannels = 1;
formatEx.nSamplesPerSec = 8000L;
formatEx.nBlockAlign = 1;
formatEx.nAvgBytesPerSec = 8000L;
formatEx.wBitsPerSample = 8;
formatEx.cbSize = 0;
mediaType.majortype = WMMEDIATYPE_Audio;
mediaType.subtype = KSDATAFORMAT_SUBTYPE_MULAW;
mediaType.bFixedSizeSamples = true;
mediaType.bTemporalCompression = false;
mediaType.lSampleSize = 160;
mediaType.formattype = WMFORMAT_WaveFormatEx;
mediaType.pUnk = 0;
mediaType.cbFormat = sizeof(WAVEFORMATEX);
mediaType.pbFormat = (BYTE*)(&formatEx);
IWMMediaProps *props;
config->QueryInterface(IID_IWMMediaProps, (void**)&props);
props->SetMediaType(&mediaType);
profile->AddStream(config);
writer->SetProfile(profile);
writer->BeginWriting();

Thanks in advance,
Matthew Schuyler Peck

Back to top
Chris P. [MVP]
Guest





Posted: Wed Oct 06, 2004 10:22 pm    Post subject: Re: Setting codec for compressed input Reply with quote

Matthew Schuyler Peck wrote:
Quote:
I am trying to build an ASF file from existing G.711 mu-law data that
I have. I can't get the writer to actually set the codec information
properly. The resulting file won't play. It loads and shows in the
playlist with the appropriate time, but doesn't begin. Clicking the
play button does nothing. Clicking on the progress bar jumps ahead
and plays a burst of static. Right clicking and selecting properties
on the playlist entry shows that the file has no codec set. What am I
doing wrong?

IWMProfile *profile;
IWMWriter *writer;
IWMWriterAdvanced *writerAdvanced;
IWMProfileManager *profileManager;
WMCreateProfileManager(&profileManager);
profileManager->CreateEmptyProfile(WMT_VER_9_0, &profile);
WMCreateWriter(NULL, &writer);
writer->SetOutputFilename(wFilename);
writer->QueryInterface(IID_IWMWriterAdvanced,
(void**)&writerAdvanced); IWMStreamConfig *config;
WM_MEDIA_TYPE mediaType;
WAVEFORMATEX formatEx;
profile->CreateNewStream(WMMEDIATYPE_Audio, &config);
config->SetBitrate(record->getFrequency() * 8);
config->SetBufferWindow(-1);
config->SetConnectionName(L"audiostream");
config->SetStreamName(L"audiostream");
config->SetStreamNumber(1);
formatEx.wFormatTag = WAVE_FORMAT_MULAW;
formatEx.nChannels = 1;
formatEx.nSamplesPerSec = 8000L;
formatEx.nBlockAlign = 1;
formatEx.nAvgBytesPerSec = 8000L;
formatEx.wBitsPerSample = 8;
formatEx.cbSize = 0;
mediaType.majortype = WMMEDIATYPE_Audio;
mediaType.subtype = KSDATAFORMAT_SUBTYPE_MULAW;
mediaType.bFixedSizeSamples = true;
mediaType.bTemporalCompression = false;
mediaType.lSampleSize = 160;
mediaType.formattype = WMFORMAT_WaveFormatEx;
mediaType.pUnk = 0;
mediaType.cbFormat = sizeof(WAVEFORMATEX);
mediaType.pbFormat = (BYTE*)(&formatEx);
IWMMediaProps *props;
config->QueryInterface(IID_IWMMediaProps, (void**)&props);
props->SetMediaType(&mediaType);
profile->AddStream(config);
writer->SetProfile(profile);
writer->BeginWriting();

If your passing anything other than uncompressed PCM audio then you have to
tell it by calling SetMediaType on IWMInputMediaProps interface. Hopefully
it should then pass the stream through unaltered.
Back to top
Matthew Schuyler Peck
Guest





Posted: Wed Oct 06, 2004 10:53 pm    Post subject: Re: Setting codec for compressed input Reply with quote

Quote:
If your passing anything other than uncompressed PCM audio then you have to
tell it by calling SetMediaType on IWMInputMediaProps interface. Hopefully
it should then pass the stream through unaltered.

I added this code:

IWMInputMediaProps *inputProps;
writer->GetInputProps(0, &inputProps);
inputProps->SetMediaType(&mediaType);
hr = writer->BeginWriting();

I'm now getting NS_E_AUDIO_CODEC_NOT_INSTALLED from
IWMWriter::BeginWriting(). Am I specifying the MULAW codec improperly?

Matthew Schuyler Peck

Back to top
Chris P. [MVP]
Guest





Posted: Wed Oct 06, 2004 11:53 pm    Post subject: Re: Setting codec for compressed input Reply with quote

Matthew Schuyler Peck wrote:
Quote:
If your passing anything other than uncompressed PCM audio then you
have to tell it by calling SetMediaType on IWMInputMediaProps
interface. Hopefully it should then pass the stream through
unaltered.

I added this code:

IWMInputMediaProps *inputProps;
writer->GetInputProps(0, &inputProps);
inputProps->SetMediaType(&mediaType);
hr = writer->BeginWriting();

I'm now getting NS_E_AUDIO_CODEC_NOT_INSTALLED from
IWMWriter::BeginWriting(). Am I specifying the MULAW codec improperly?

It's correct as far as I can determine. I've never actually tried anything
other than uncompressed myself, but according to the docs it is possible.
Your types and format appear to be correct.
Back to top
Iain
Guest





Posted: Thu Oct 07, 2004 2:04 am    Post subject: Re: Setting codec for compressed input Reply with quote

On Wed, 6 Oct 2004 15:53:23 -0400, Chris P. [MVP] wrote:

Quote:
Matthew Schuyler Peck wrote:
If your passing anything other than uncompressed PCM audio then you
have to tell it by calling SetMediaType on IWMInputMediaProps
interface. Hopefully it should then pass the stream through
unaltered.

I added this code:

IWMInputMediaProps *inputProps;
writer->GetInputProps(0, &inputProps);
inputProps->SetMediaType(&mediaType);
hr = writer->BeginWriting();

I'm now getting NS_E_AUDIO_CODEC_NOT_INSTALLED from
IWMWriter::BeginWriting(). Am I specifying the MULAW codec improperly?

It's correct as far as I can determine. I've never actually tried anything
other than uncompressed myself, but according to the docs it is possible.
Your types and format appear to be correct.

It may be that your code is correct but that the codec on your system is
not one which WMFSDK can access. I'm not at all sure about this (Chris P
normally comes in around here to set me right...), but it may be that
WMFDSK won't use any non DMO codecs for converting the input stream.

I also have only used uncompressed.

Iain
Back to top
Chris P. [MVP]
Guest





Posted: Thu Oct 07, 2004 6:40 pm    Post subject: Re: Setting codec for compressed input Reply with quote

Iain wrote:
Quote:
On Wed, 6 Oct 2004 15:53:23 -0400, Chris P. [MVP] wrote:


It's correct as far as I can determine. I've never actually tried
anything other than uncompressed myself, but according to the docs
it is possible. Your types and format appear to be correct.

It may be that your code is correct but that the codec on your system
is not one which WMFSDK can access. I'm not at all sure about this
(Chris P normally comes in around here to set me right...), but it
may be that WMFDSK won't use any non DMO codecs for converting the
input stream.

I also have only used uncompressed.

That's a possibility, I will try and get clarification on that if I can.
However I was under the impression (from something someone from MS said
here) that if it sees that the input and output media types are the same, it
should just pass the stream through unaltered.

Alternative solution is to decompress your MuLaw data to 16-bit PCM and set
the source format as PCM, then allow it to recompress to MuLaw. Obviously
this is not efficient, but there shouldn't be any loss of signal as MuLaw is
a per sample compression scheme and is pretty lightweight CPU wise. Now if
you're trying to do a few hundred of these simultaneously in real-time that
could definately be a problem.

-Chris
Back to top
Geoff Dunbar [MSFT]
Guest





Posted: Mon Oct 11, 2004 10:30 pm    Post subject: Re: Setting codec for compressed input Reply with quote

2 additional steps:

1) On the input props for the stream, set the media type to NULL. This tells
the writer not to try to create it's own codec. (Since you have already
compressed the data, you don't need the writer to create a codec at all).
2) Instead of IWMWriter::WriteSample, use
IWMWriterAdvanced::WriteStreamSample.

In theory that should work. However, I do recall various issues getting the
old ACM decoders (on the read side) to decode data properly, so unless
you're also writing your own decoder (and can debug and modify it's
behavior), I can't make any guarantees.

Hope this helps,
Geoff

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Matthew Schuyler Peck" <Matthew Schuyler Peck@discussions.microsoft.com>
wrote in message news:D1EE045D-46B7-4F88-BF8F-B38EEC7DA0B7@microsoft.com...
Quote:
I am trying to build an ASF file from existing G.711 mu-law data that I
have.
I can't get the writer to actually set the codec information properly. The
resulting file won't play. It loads and shows in the playlist with the
appropriate time, but doesn't begin. Clicking the play button does
nothing.
Clicking on the progress bar jumps ahead and plays a burst of static.
Right
clicking and selecting properties on the playlist entry shows that the
file
has no codec set. What am I doing wrong?

IWMProfile *profile;
IWMWriter *writer;
IWMWriterAdvanced *writerAdvanced;
IWMProfileManager *profileManager;
WMCreateProfileManager(&profileManager);
profileManager->CreateEmptyProfile(WMT_VER_9_0, &profile);
WMCreateWriter(NULL, &writer);
writer->SetOutputFilename(wFilename);
writer->QueryInterface(IID_IWMWriterAdvanced, (void**)&writerAdvanced);
IWMStreamConfig *config;
WM_MEDIA_TYPE mediaType;
WAVEFORMATEX formatEx;
profile->CreateNewStream(WMMEDIATYPE_Audio, &config);
config->SetBitrate(record->getFrequency() * 8);
config->SetBufferWindow(-1);
config->SetConnectionName(L"audiostream");
config->SetStreamName(L"audiostream");
config->SetStreamNumber(1);
formatEx.wFormatTag = WAVE_FORMAT_MULAW;
formatEx.nChannels = 1;
formatEx.nSamplesPerSec = 8000L;
formatEx.nBlockAlign = 1;
formatEx.nAvgBytesPerSec = 8000L;
formatEx.wBitsPerSample = 8;
formatEx.cbSize = 0;
mediaType.majortype = WMMEDIATYPE_Audio;
mediaType.subtype = KSDATAFORMAT_SUBTYPE_MULAW;
mediaType.bFixedSizeSamples = true;
mediaType.bTemporalCompression = false;
mediaType.lSampleSize = 160;
mediaType.formattype = WMFORMAT_WaveFormatEx;
mediaType.pUnk = 0;
mediaType.cbFormat = sizeof(WAVEFORMATEX);
mediaType.pbFormat = (BYTE*)(&formatEx);
IWMMediaProps *props;
config->QueryInterface(IID_IWMMediaProps, (void**)&props);
props->SetMediaType(&mediaType);
profile->AddStream(config);
writer->SetProfile(profile);
writer->BeginWriting();

Thanks in advance,
Matthew Schuyler Peck
Back to top
 
Post new topic   Reply to topic    WMPTalk.com Forum Index -> SDK All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Microsoft Office Forum New Topics
Powered by phpBB