本文介绍了颜色转换器 DSP ProcessOutput 总是返回 MF_E_TRANSFORM_NEED_MORE_INPUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将视频帧从 RGB32 转换为 IYUV,但颜色转换器 MFT 拒绝处理样本.对于每一帧,我调用 IMFTransform::ProcessInput() 和 IMFTransform::ProcessOutput() 但我收到 MF_E_TRANSFORM_NEED_MORE_INPUT.如果我尝试为 MFT 提供另一个样本,我会收到 MF_E_NOTACCEPTING 错误.

I need to convert video frames from RGB32 to IYUV but the Color Converter MFT refuses to process samples. For every frame I call IMFTransform::ProcessInput() and IMFTransform::ProcessOutput() but I receive MF_E_TRANSFORM_NEED_MORE_INPUT. If I try to feed MFT with another sample i get the MF_E_NOTACCEPTING error.

下面我粘贴了一个代码来显示我的问题.希望大家帮帮忙.

Below I paste a code to show my problem. Hopefully you guys will be able to help.

首先我创建媒体类型:

//DSP input MediaType
CHECK_HR(hr = MFCreateMediaType(&m_pInputMediaType));
CHECK_HR(hr =  m_pInputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
CHECK_HR(hr =  m_pInputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32))
CHECK_HR(hr =  m_pInputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive))
CHECK_HR(hr =  MFSetAttributeSize(m_pInputMediaType, MF_MT_FRAME_SIZE, m_pStreamParams->StreamWidth, m_pStreamParams->StreamHeight))
CHECK_HR(hr =  MFSetAttributeRatio(m_pInputMediaType, MF_MT_FRAME_RATE, m_pStreamParams->StreamFramerate, 1))
CHECK_HR(hr =  MFSetAttributeRatio(m_pInputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));

    //DSP output MediaType
CHECK_HR(hr = MFCreateMediaType(&m_pIntermediateMediaType));
CHECK_HR(hr =  m_pIntermediateMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
CHECK_HR(hr =  m_pIntermediateMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_IYUV));
CHECK_HR(hr =  m_pIntermediateMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
CHECK_HR(hr =  MFSetAttributeSize(m_pIntermediateMediaType, MF_MT_FRAME_SIZE, m_pStreamParams->StreamWidth, m_pStreamParams->StreamHeight));
CHECK_HR(hr =  MFSetAttributeRatio(m_pIntermediateMediaType, MF_MT_FRAME_RATE, m_pStreamParams->StreamFramerate, 1));
CHECK_HR(hr =  MFSetAttributeRatio(m_pIntermediateMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));

然后我初始化 DSP 并设置 MediaTypes

Then I initialize the DSP and set MediaTypes

CHECK_HR(hr = CoCreateInstance(CLSID_CColorConvertDMO, NULL, CLSCTX_ALL, IID_PPV_ARGS(&m_pColorDSP)));
CHECK_HR(hr = m_pColorDSP->SetInputType(0, m_pInputMediaType, 0));
CHECK_HR(hr = m_pColorDSP->SetOutputType(0, m_pIntermediateMediaType, 0));

还有我的帧处理方法

HRESULT LibStreaming3::WriteFrame(DWORD* videoFrameBuffer)

{
IMFSample *pRGBSample = NULL;
IMFMediaBuffer *pBuffer = NULL;


if(!m_bStreaming)
{
    LOG("Failed: Not streaming!");
    return E_FAIL;
}
assert(m_pStreamParams);
assert(m_pH264Encoder);
assert(m_pColorDSP);
const LONG cbWidth = 4 * m_pStreamParams->StreamWidth;
const DWORD cbBuffer = cbWidth * m_pStreamParams->StreamHeight;

BYTE *pData = NULL;

// Create a new memory buffer.
HRESULT hr = MFCreateMemoryBuffer(cbBuffer, &pBuffer);

// Lock the buffer and copy the video frame to the buffer.
if (SUCCEEDED(hr))
{
    hr = pBuffer->Lock(&pData, NULL, NULL);
}
if (SUCCEEDED(hr))
{
    hr = MFCopyImage(
        pData,                      // Destination buffer.
        cbWidth,                    // Destination stride.
        (BYTE*)videoFrameBuffer,    // First row in source image.
        cbWidth,                    // Source stride.
        cbWidth,                    // Image width in bytes.
        m_pStreamParams->StreamHeight                // Image height in pixels.
        );
}
if (pBuffer)
{
    pBuffer->Unlock();
}
do
{

// Set the data length of the buffer.
CHECK_HR(hr = pBuffer->SetCurrentLength(cbBuffer));

// Create a media sample and add the buffer to the sample.
CHECK_HR(hr = MFCreateSample(&pRGBSample));
CHECK_HR(hr = pRGBSample->AddBuffer(pBuffer));

// Set the time stamp and the duration.
CHECK_HR(hr = pRGBSample->SetSampleTime(m_rtStart));
CHECK_HR(hr = pRGBSample->SetSampleDuration(m_rtDuration));
/************************************************************************/
/* CONVERT COLORS                                                       */
/************************************************************************/

MFT_OUTPUT_DATA_BUFFER IYUVOutputDataBuffer;
IYUVOutputDataBuffer.dwStreamID = 0;
IYUVOutputDataBuffer.dwStatus = 0;
IYUVOutputDataBuffer.pEvents = NULL;
IYUVOutputDataBuffer.pSample = NULL;

DWORD dwDSPStatus = 0;
//IMFSample* pIYUVSample = NULL;
MFT_INPUT_STREAM_INFO info;
hr = m_pColorDSP->GetInputStreamInfo(0,&info );
hr = m_pColorDSP->ProcessInput(0, pRGBSample, 0); //Will provide only one sample, every next call will result in MF_E_NOTACCEPTING
hr = m_pColorDSP->ProcessOutput(0, 1, &IYUVOutputDataBuffer,&dwDSPStatus); // Always returns MF_E_TRANSFORM_NEED_MORE_INPUT


} while (false);
m_rtStart += m_rtDuration;
SafeRelease(&pRGBSample);
SafeRelease(&pBuffer);
return hr;
}

最好的问候,
帕维尔

Best regards,
Pawel

推荐答案

我也遇到了同样的错误,这是由于提供了 ProcessInput 和无效的示例.它没有报告错误,而是愉快地忽略了它,因此导致 MF_E_TRANSFORM_NEED_MORE_INPUT 来自 ProcessOutput

I also got the same error and it was due to giving ProcessInput and invalid sample. Instead of reporting an error it happily ignored it and so resulted in a MF_E_TRANSFORM_NEED_MORE_INPUT from ProcessOutput

这篇关于颜色转换器 DSP ProcessOutput 总是返回 MF_E_TRANSFORM_NEED_MORE_INPUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 22:51