Nvidia NvEnc与HVEC导致Div为零

时间:2016-07-16 13:38:21

标签: c++ encoding h.264 hevc nvenc

我正在尝试使用Nvidias NvEnc API构建硬件编码器。此API提供了两个编解码器用于编码任何给定数据的用法:H264和HEVC。 因此,首先必须选择两个代码中的一个,然后配置编码会话或使用一个varios预设。我正如Nvidias NvEnc Programming Guide中描述的那样做。

使用HVEC编解码器时,我有以下代码导致问题:

//Create Init Params
InitParams* ip = new InitParams();

ip->encodeGUID = m_encoderGuid; //encoder GUID is either H264 or HEVC
ip->encodeWidth = width;
ip->encodeHeight = height;
ip->version = NV_ENC_INITIALIZE_PARAMS_VER;
ip->presetGUID = m_presetGuid; //One of the presets
ip->encodeConfig = NULL; //If using preset, further config should be set to NULL

//Async Encode
ip->enableEncodeAsync = 1;

//Send the InputBuffer in Display Order
ip->enablePTD = 1;

//Causing Div by Zero error if used with HEVC GUID:
CheckApiError(m_apiFunctions.nvEncInitializeEncoder(m_Encoder, ip));

所以事情又来了:我正在使用H264 GUID,一切都在运行。如果我使用HEVC,我得到一个Div by Zero ...我没有从api调用得到一些错误代码,只是一个普通的div by零错误。 所以我的问题是:HEVC是否需要使用预设提供的更多信息?如果是这样,会有什么样的信息?

非常感谢!

编辑:解决了它。编程指南没有声明,必须设置这些字段,但 NV_ENC_INITIALIZE_PARAMS frameRateNum frameRateDen 组成,这会导致div为零。 .. Dunno为什么在使用H264时不会发生这种情况。有人可能会关闭这个......

1 个答案:

答案 0 :(得分:0)

根据NVidias编程指南,这就是我所做的配置。如上所述,不提供frameRateNum和frameRateDen的值会导致Div by Zero错误,尤其是在初始memset之后。

//Create Init Params
InitParams* ip = new InitParams();
m_initParams = ip;
memset(ip, 0, sizeof(InitParams));

//Set Struct Version
ip->version = NV_ENC_INITIALIZE_PARAMS_VER;

//Used Codec
ip->encodeGUID = m_encoderGuid;

//Size of the frames
ip->encodeWidth = width;
ip->encodeHeight = height;

//Set to 0, no dynamic resolution changes!
ip->maxEncodeWidth = 0;
ip->maxEncodeHeight = 0;

//Aspect Ratio
ip->darWidth = width;
ip->darHeight = height;

// Frame rate
ip->frameRateNum = 60;
ip->frameRateDen = 1;

//Misc
ip->reportSliceOffsets = 0;
ip->enableSubFrameWrite = 0;

//Preset GUID
ip->presetGUID = m_presetGuid;

//Apply Preset
NV_ENC_PRESET_CONFIG presetCfg;
memset(&presetCfg, 0, sizeof(NV_ENC_PRESET_CONFIG));
presetCfg.version = NV_ENC_PRESET_CONFIG_VER;
presetCfg.presetCfg.version = NV_ENC_CONFIG_VER;
CheckApiError(m_apiFunctions.nvEncGetEncodePresetConfig(m_Encoder,
    m_encoderGuid, m_presetGuid, &presetCfg));
// Copy the Preset Config to member var
memcpy(&m_encodingConfig, &presetCfg.presetCfg, sizeof(NV_ENC_CONFIG));
/************************************************************************/
/* Room for Config Adjustments                                          */
/************************************************************************/

//Set Init configs encoding config
ip->encodeConfig = &m_encodingConfig;

//Async Encode!
ip->enableEncodeAsync = 1;

//Send the InputBuffer in Display Order
ip->enablePTD = 1;


CheckApiError(m_apiFunctions.nvEncInitializeEncoder(m_Encoder, ip));