MFT编码器(h264)高CPU使用率 [英] MFT Encoder (h264) High CPU utilization

查看:335
本文介绍了MFT编码器(h264)高CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用Media Foundation Transform(MFT)成功地通过H264编码数据,但是不幸的是我有一个非常高的CPU(当我在程序中注释该函数的调用时,我得到了一个低CPU).这是几个步骤跟着去获取编码,所以我无能为力吗?有什么主意可以帮忙

I am able successfully to encode the data by H264 using Media Foundation Transform (MFT) but unfortunately I got a very high CPU(when I comment in the program the calling of this function I got low CPU).It is few steps followed to get the encoding so I can't do anything to improve it?Any idea can help

    HRESULT MFTransform::EncodeSample(IMFSample *videosample, LONGLONG llVideoTimeStamp, MFT_OUTPUT_STREAM_INFO &StreamInfo, MFT_OUTPUT_DATA_BUFFER &encDataBuffer)
{
    HRESULT hr;
    LONGLONG llSampleDuration;
    DWORD mftEncFlags, processOutputStatus;
    //used to set the output sample
    IMFSample *mftEncodedSample;
    //used to set the output sample
    IMFMediaBuffer *mftEncodedBuffer = NULL;
    memset(&encDataBuffer, 0, sizeof encDataBuffer);
    if (videosample)
    {
        //1=set the time stamp for the sample
        hr = videosample->SetSampleTime(llVideoTimeStamp);
        #ifdef _DEBUG
        printf("Passing sample to the H264 encoder with sample time %i.\n", llVideoTimeStamp);
        #endif
        if (SUCCEEDED(hr))
        {
            hr = MFT_encoder->ProcessInput(0, videosample, 0);
        }
        if (SUCCEEDED(hr))
        {
            MFT_encoder->GetOutputStatus(&mftEncFlags);
        }
        if (mftEncFlags == MFT_OUTPUT_STATUS_SAMPLE_READY)
        {
            hr = MFT_encoder->GetOutputStreamInfo(0, &StreamInfo);

            //create empty encoded sample
            if (SUCCEEDED(hr))
            {
                hr = MFCreateSample(&mftEncodedSample);
            }
            if (SUCCEEDED(hr))
            {
                hr = MFCreateMemoryBuffer(StreamInfo.cbSize, &mftEncodedBuffer);
            }
            if (SUCCEEDED(hr))
            {
                hr = mftEncodedSample->AddBuffer(mftEncodedBuffer);
            }
            if (SUCCEEDED(hr))
            {
                encDataBuffer.dwStatus = 0;
                encDataBuffer.pEvents = 0;
                encDataBuffer.dwStreamID = 0;
                //Two shall after this step points on the same address
                encDataBuffer.pSample = mftEncodedSample;
                hr = MFT_encoder->ProcessOutput(0, 1, &encDataBuffer, &processOutputStatus);


            }
        }
    }
    SafeRelease(&mftEncodedBuffer);

    return hr;
}

推荐答案

第一个关键是确保您为接收器配置了MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS.我还设置了MF_LOW_LATENCY属性.

The first key is to ensure you have configured the sink with MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS. I also set the MF_LOW_LATENCY attribute.

// error checking omitted for brevity
hr = attributes->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, TRUE);
hr = attributes->SetUINT32(MF_SINK_WRITER_DISABLE_THROTTLING, TRUE);
hr = attributes->SetUINT32(MF_LOW_LATENCY, TRUE);

另一个键是确保您选择源输出的本机格式.否则,您将非常失望.我在此处进行详细描述.

The other key is to ensure you are selecting the native format for the output of the source. Otherwise, you will remain very disappointed. I describe this in detail here.

我还应该提到,您应该考虑在开始时一次创建转换样本和内存缓冲区,而不是在收到的每个样本上重新创建它们.

I should also mention that you should consider creating the transform sample and memory buffer once at the beginning, instead of recreating them on each sample received.

祝你好运.我希望这会有所帮助.

Good luck. I hope this helps.

这篇关于MFT编码器(h264)高CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆