答案 0 :(得分:3)
对媒体进行编码或解码时,IMFTransform
是Media Foundation API中公开的接口编解码器。也就是说,你没有实现它 - 你利用了现有的编解码器实现(当你想扩展API并提供额外的编解码器时实现它)。
Stock Windows为您提供:
CLSID_CMSAACDecMFT
CLSID_AACMFTEncoder
CLSID_CMSH264DecoderMFT
,在适用的情况下利用DXVA硬件辅助解码CLSID_CMSH264EncoderMFT
,软件(后备)编码器可能会为其他硬件加速编码器提供硬件驱动程序。上面提到的所有内容都以IMFTransform
的形式提供,可以直接使用或使用更高级别的Media Foundation API。
答案 1 :(得分:2)
您可以实现CLSID_CMSH264DecoderMFT
接口来解码和编码H264和AAC。请参阅CLSID_CMSAACDecMFT
和CLSID_CMSH264EncoderMFT
解码H264和ACC,同时解析CLSID_AACMFTEncoder
和 IUnknown *_transformUnk;
IMFTransform *_encoder;
HRESULT MediaEncoder::InitialiseEncoder(EncoderType encoder)
{
HRESULT hr = S_OK;
// Has the encoder been init.
if (!_isOpen)
{
_encoderType = encoder;
// Init the COM.
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// Create a new close event handler.
_hCloseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// If event was not created.
if (_hCloseEvent == NULL)
{
// Get the result value.
hr = __HRESULT_FROM_WIN32(GetLastError());
}
// If successful creation of the close event.
if (SUCCEEDED(hr))
{
// Start up Media Foundation platform.
hr = MFStartup(MF_VERSION);
_isOpen = true;
}
if (SUCCEEDED(hr))
{
// Select the encoder.
switch (encoder)
{
case Nequeo::Media::Foundation::EncoderType::H264:
// Create the H264 encoder.
hr = CreateEncoder(CLSID_CMSH264EncoderMFT);
break;
case Nequeo::Media::Foundation::EncoderType::AAC:
// Create the AAC encoder.
hr = CreateEncoder(CLSID_AACMFTEncoder);
break;
case Nequeo::Media::Foundation::EncoderType::MP3:
// Create the MP3 encoder.
hr = CreateEncoder(CLSID_MP3ACMCodecWrapper);
break;
default:
hr = ((HRESULT)-1L);
break;
}
}
if (SUCCEEDED(hr))
{
// Query for the IMFTransform interface
hr = _transformUnk->QueryInterface(IID_PPV_ARGS(&_encoder));
// Encoder has been created.
_created = true;
}
}
// Return the result.
return hr;
}
HRESULT MediaEncoder::CreateEncoder(const CLSID encoder)
{
HRESULT hr = S_OK;
// Create the decoder.
hr = CoCreateInstance(encoder, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&_transformUnk);
// Return the result.
return hr;
}
以对H264和ACC进行编码。
编码器示例:初始化编码器。
IUnknown *_transformUnk;
IMFTransform *_decoder;
HRESULT MediaDecoder::InitialiseDecoder(DecoderType decoder)
{
HRESULT hr = S_OK;
// Has the decoder been init.
if (!_isOpen)
{
_decoderType = decoder;
// Init the COM.
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// Create a new close event handler.
_hCloseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// If event was not created.
if (_hCloseEvent == NULL)
{
// Get the result value.
hr = __HRESULT_FROM_WIN32(GetLastError());
}
// If successful creation of the close event.
if (SUCCEEDED(hr))
{
// Start up Media Foundation platform.
hr = MFStartup(MF_VERSION);
_isOpen = true;
}
if (SUCCEEDED(hr))
{
// Select the decoder.
switch (decoder)
{
case Nequeo::Media::Foundation::DecoderType::H264:
// Create the H264 decoder.
hr = CreateDecoder(CLSID_CMSH264DecoderMFT);
break;
case Nequeo::Media::Foundation::DecoderType::AAC:
// Create the AAC decoder.
hr = CreateDecoder(CLSID_CMSAACDecMFT);
break;
case Nequeo::Media::Foundation::DecoderType::MP3:
// Create the MP3 decoder.
hr = CreateDecoder(CLSID_CMP3DecMediaObject);
break;
case Nequeo::Media::Foundation::DecoderType::MPEG4:
// Create the MPEG4 decoder.
hr = CreateDecoder(CLSID_CMpeg4sDecMFT);
break;
default:
hr = ((HRESULT)-1L);
break;
}
}
if (SUCCEEDED(hr))
{
// Query for the IMFTransform interface
hr = _transformUnk->QueryInterface(IID_PPV_ARGS(&_decoder));
// Decoder has been created.
_created = true;
}
}
// Return the result.
return hr;
}
HRESULT MediaDecoder::CreateDecoder(const CLSID decoder)
{
HRESULT hr = S_OK;
// Create the decoder.
hr = CoCreateInstance(decoder, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&_transformUnk);
// Return the result.
return hr;
}
解码器示例:初始化解码器。
DataFrame.all()