Quantcast
Channel: Media Foundation Development for Windows Desktop forum
Viewing all articles
Browse latest Browse all 1079

H.264 SetOutPutType returns E_FAIL error

$
0
0

Hi guys,

I am writing a video processing application. I am utilizing a media session. My pipeline consists of source reader, decoder MFT (used by MfEnum, I query the MFTs capable of outputting one of my 4 desired video formats), Color Converter DSP (to convert YUY2, NV12, YV12 outputs of the decoder into RGB32), and my custom sink. My custom sink writes the samples of with no issues. I am planning on adding a variation to my pipeline. I want to inject an H264 encoder between the color converter and the sink. In this scenario my custom sink will be replaced by the built in MPEG4 sink.

Having said above, my original pipeline without the encoder and MPEG4 sink works fine.

I query the system for an H264 encoder with YUY2 input and H264 output and it returns one match. I create an instance and try to set up the input and output types. SetOutputType fails. MFTrace does not give me much except it fails.


I tried both using an already setup Media Type and creating the media type from scratch. Per the documentation I have filled up all of the pieces. I am setting the output first and then the input. Only thing is that I am doing this on Windows 8. I need to setup my VM to check on windows 7.


Here is the sample code.

                        

HRESULT MediaFoundationManager::FindEncoder(IMFTransform **decoder, IMFMediaType *type)
        {
            HRESULT hr = S_OK;
            UINT32 count = 0;

            CLSID *ppCLSIDs = NULL;

            MFT_REGISTER_TYPE_INFO info = { 0 };
            info.guidMajorType = MFMediaType_Video;
            info.guidSubtype = MFVideoFormat_YUY2;

            MFT_REGISTER_TYPE_INFO outInfo = {0};
            outInfo.guidMajorType = MFMediaType_Video;
            outInfo.guidSubtype = MFVideoFormat_H264;

            hr = MFTEnum(    MFT_CATEGORY_VIDEO_ENCODER,
                    0,          // Reserved
                    &info,       // Input type
                    &outInfo,      // Output type
                    NULL,       // Reserved
                    &ppCLSIDs,
                    &count
                    );

                if (SUCCEEDED(hr) && count == 0)
                    hr = MF_E_TOPO_CODEC_NOT_FOUND;


                if (SUCCEEDED(hr))
                    hr = CoCreateInstance(ppCLSIDs[0], NULL, CLSCTX_ALL, IID_PPV_ARGS(decoder));

                if (SUCCEEDED(hr))
                {                   
                    ConfigureMFTFromScratch(*decoder,info.guidSubtype,outInfo.guidSubtype, true);                   
                }
            }

            CoTaskMemFree(ppCLSIDs);
            return hr;
 }

void MediaFoundationManager::ConfigureMFTFromScratch(IMFTransform *transform, GUID inputFormat, GUID outputFormat, bool outputFirst)
{
            CComPtr<IMFMediaType> inputMediaType = NULL;
            CComPtr<IMFMediaType> outputMediaType = NULL;

            Helper::CheckHR(MFCreateMediaType(&inputMediaType),"Create Media Type");
            Helper::CheckHR(MFCreateMediaType(&outputMediaType),"Create Media Type");

            Helper::CheckHR(inputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),"Set major type");
            Helper::CheckHR(inputMediaType->SetGUID(MF_MT_SUBTYPE, inputFormat),"Set Sub type");
            Helper::CheckHR(MFSetAttributeSize(inputMediaType, MF_MT_FRAME_SIZE,_inputInfo.FrameWidth, _inputInfo.FrameHeight),"Set Frame Size");
            Helper::CheckHR(inputMediaType->SetUINT64(MF_MT_FRAME_RATE, _inputInfo.FrameRate),"Set Frame rate");
            Helper::CheckHR(inputMediaType->SetUINT32(MF_MT_AVG_BITRATE, _inputInfo.BitRate),"Set Bit rate");
            Helper::CheckHR(inputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlaceMode::MFVideoInterlace_Progressive),"Set Interlace Mode");
            Helper::CheckHR(MFSetAttributeRatio(inputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1),"Set Aspect Ratio");

            Helper::CheckHR(outputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),"Set major type");
            Helper::CheckHR(outputMediaType->SetGUID(MF_MT_SUBTYPE, outputFormat),"Set Sub type");
            Helper::CheckHR(MFSetAttributeSize(outputMediaType, MF_MT_FRAME_SIZE,_inputInfo.FrameWidth, _inputInfo.FrameHeight),"Set Frame Size");
            Helper::CheckHR(outputMediaType->SetUINT64(MF_MT_FRAME_RATE, _inputInfo.FrameRate),"Set Frame rate");
            Helper::CheckHR(outputMediaType->SetUINT32(MF_MT_AVG_BITRATE, _inputInfo.BitRate),"Set Bit rate");
            Helper::CheckHR(outputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlaceMode::MFVideoInterlace_Progressive),"Set Interlace Mode");
            Helper::CheckHR(MFSetAttributeRatio(outputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1),"Set Aspect Ratio");    
                
            if (outputFirst)
            {
                UINT32 level = -1;
                outputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, level);
                Helper::CheckHR(outputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE , eAVEncH264VProfile_Main),"Set Profile Mode");
                Helper::CheckHR(transform->SetOutputType(0, outputMediaType, 0),"Set output type");    
                Helper::CheckHR(transform->SetInputType(0, inputMediaType, 0),"Set input type");                   
            }
            else
            {        
                Helper::CheckHR(transform->SetInputType(0, inputMediaType, 0),"Set input type");    
                Helper::CheckHR(transform->SetOutputType(0, outputMediaType, 0),"Set output type");                   
            }
}

HRESULT 80004005 is thrown at Helper::CheckHR(transform->SetOutputType(0, outputMediaType, 0),"Set output type");

Any ideas?






Viewing all articles
Browse latest Browse all 1079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>