WMAV2 MFT编码器

时间:2016-11-04 04:45:23

标签: c++ audio multimedia ms-media-foundation mft

我试图在MFT中使用WMA8编码器来编码音频数据。整个音频持续时间为10秒,ProcessInput和ProcessOut都正确/成功运行。编码音频数据的时间戳也是正确的。问题是,编码后的音频在写入文件后(使用我自己的复用器)似乎不正确。

我注意到的一件事是,从mftrace的输出来看,输出类型似乎有一个奇怪的对齐和每秒字节数。下面是编码器设置代码和mftrace的输出。

CLSID* pCLSIDs = NULL;   // Pointer to an array of CLISDs.       
UINT32 nCount = 0;      
MFT_REGISTER_TYPE_INFO encoderInfo;      
encoderInfo.guidMajorType = MFMediaType_Audio;      
encoderInfo.guidSubtype = MFAudioFormat_WMAudioV8;      
HRESULT hr = fpMFTEnum(MFT_CATEGORY_AUDIO_ENCODER, 0, NULL, &encoderInfo, NULL, &pCLSIDs, &nCount);      
if (nCount == 0) {
    LFTRACE("Can't enumerate Audio encoders, returned encoder amount = 0");      
}
ciEncoder.CreateObject(pCLSIDs[0], IID_IMFTransform);      
if (ciEncoder.IsInvalid()) {             
    LFDEBUG("ciEncoder.CreateObject failed");         
    break;
}      
// encoder created now       
// to set input      
LComObject<IMFMediaType> ciInputType;  // Input media type of the encoder      
hr = fpMFCreateMediaType((IMFMediaType**)(ciInputType.GetAssignablePtrRef()));      
hr = ciInputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);      
hr = ciInputType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);      
hr = ciInputType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16); // bits per sample      
hr = ciInputType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 22050); // input sample rate      
hr = ciInputType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, 2); // channels      
//alignment = uint16_t(pwfx->nChannels * uint16_t((BitsPerSample <= 8) ? 1 : ((BitsPerSample <= 16) ? 2 : 4)));      
hr = ciInputType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, 4);      
hr = ciInputType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 22050 * 4); // sample rate * alignment      
hr = ciEncoder->SetInputType(0, ciInputType.get(), 0);      
LComInterface<IMFMediaType> ciOutPutType;      
hr = ciEncoder->GetOutputAvailableType(0, 1, (IMFMediaType**)ciOutPutType.GetAssignablePtrRef());      
hr = ciEncoder->SetOutputType(0, ciOutPutType.get(), 0);    
hr = ciEncoder->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL);


4276,B78 04:27:33.76791 CMFTransformDetours::SetInputType @09A36E70 Succeeded MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=88200;MF_MT_AUDIO_BLOCK_ALIGNMENT=4;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=22050;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM
4276,B78 04:27:33.76795 CMFTransformDetours::SetOutputType @09A36E70 Succeeded MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=2751;MF_MT_AUDIO_BLOCK_ALIGNMENT=1022;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=22050;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_USER_DATA=00 44 00 00 0f 00 00 00 00 00 ;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_WMAudioV8
4276,B78 04:27:33.76796 CMFTransformDetours::ProcessMessage @09A36E70 Message type=0x10000000 MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, param=00000000

从跟踪中你可以设置音频输出类型的块对齐为1022,每秒字节数为2751.输出采样率为22050,这是否意味着每个样本只有0.1byte?

从跟踪中,编码的音频样本具有正确的时间戳。任何人都可以提出问题所在的提示吗? (顺便说一下,每次我可以使用ProcessIput()时,是否需要为编码器提供固定数量的样本?)

4276,B78 04:27:33.80126 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 0ms, Duration 232ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1 
4276,B78 04:27:33.80130 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 232ms, Duration 232ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1   
4276,B78 04:27:33.80134 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 464ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1   
4276,B78 04:27:33.81006 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 743ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1   
4276,B78 04:27:33.81010 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 1021ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.81012 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 1300ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.82536 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 1578ms, Duration 325ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.82540 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 1904ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.82541 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 2182ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.83379 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 2461ms, Duration 325ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.83383 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 2786ms, Duration 336ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.84831 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 3123ms, Duration 313ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.84835 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 3436ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.85838 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 3808ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.85842 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 4179ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.87418 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 4551ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.87425 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 4922ms, Duration 325ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.88375 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 5247ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.88379 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 5619ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.89730 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 5990ms, Duration 417ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.89734 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 6408ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.90466 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 6780ms, Duration 417ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.90470 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 7198ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.91802 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 7569ms, Duration 325ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.91806 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 7894ms, Duration 371ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.93442 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 8266ms, Duration 464ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.93447 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 8730ms, Duration 417ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.93449 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 9148ms, Duration 417ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.93451 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 9566ms, Duration 278ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1  
4276,B78 04:27:33.93453 CMFTransformDetours::ProcessOutput @09A36E70 Stream ID 0, Sample @085C0568, Time 9845ms, Duration 150ms, Buffers 1, Size 1022B, MFSampleExtension_CleanPoint=1

由于

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。

我所做的更改包括:

通过所有这些更改,可以正确播放编码的ASF。