• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

WMAV2 MFT编码器

c/c++ 来源:rhbc73 4次浏览

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

有一件事我注意到,从输出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 

感谢

===========解决方案如下:

我已经解决了这个问题。我做

的变化包括:

  • 设置输出设置输入之前。 我用IMFTransform.GetOutputAvailableType()IMFMediaType.GetRepresentation(),这样我就可以选择我想要的平均字节率。
  • 根据https://msdn.microsoft.com/en-us/library/windows/desktop/ff819081(v=vs.85).aspx我需要额外的数据并将其设置为复用器。
  • 我设立从输出媒体类型的块对准到复用器

所有这些变化,所编码的ASF可以正确地播放。


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)