Skip to content

Commit 4c810a9

Browse files
authored
Merge pull request #3717 from cudawarped:update_for_nvidia_video_codec_sdk_12_2
cudacodec: fix #3711 (update for Nvidia Video Codec SDK 12.2)
2 parents b042744 + 57852f2 commit 4c810a9

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

modules/cudacodec/src/NvEncoder.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ void NvEncoder::CreateDefaultEncoderParams(NV_ENC_INITIALIZE_PARAMS* pIntializeP
100100
pIntializeParams->enableEncodeAsync = GetCapabilityValue(codecGuid, NV_ENC_CAPS_ASYNC_ENCODE_SUPPORT);
101101
#endif
102102
pIntializeParams->tuningInfo = tuningInfo;
103-
NV_ENC_PRESET_CONFIG presetConfig = {};
104-
presetConfig.version = NV_ENC_PRESET_CONFIG_VER;
105-
presetConfig.presetCfg.version = NV_ENC_CONFIG_VER;
103+
pIntializeParams->encodeConfig->rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
104+
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
105+
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, 0, { NV_ENC_CONFIG_VER } };
106+
#else
107+
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, { NV_ENC_CONFIG_VER } };
108+
#endif
106109
m_nvenc.nvEncGetEncodePresetConfigEx(m_hEncoder, codecGuid, presetGuid, tuningInfo, &presetConfig);
107110
memcpy(pIntializeParams->encodeConfig, &presetConfig.presetCfg, sizeof(NV_ENC_CONFIG));
108111

@@ -116,8 +119,13 @@ void NvEncoder::CreateDefaultEncoderParams(NV_ENC_INITIALIZE_PARAMS* pIntializeP
116119
}
117120
else if (pIntializeParams->encodeGUID == NV_ENC_CODEC_HEVC_GUID)
118121
{
122+
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
123+
pIntializeParams->encodeConfig->encodeCodecConfig.hevcConfig.inputBitDepth = pIntializeParams->encodeConfig->encodeCodecConfig.hevcConfig.outputBitDepth =
124+
(m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
125+
#else
119126
pIntializeParams->encodeConfig->encodeCodecConfig.hevcConfig.pixelBitDepthMinus8 =
120127
(m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT) ? 2 : 0;
128+
#endif
121129
if (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444 || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT)
122130
{
123131
pIntializeParams->encodeConfig->encodeCodecConfig.hevcConfig.chromaFormatIDC = 3;
@@ -171,7 +179,11 @@ void NvEncoder::CreateEncoder(const NV_ENC_INITIALIZE_PARAMS* pEncoderParams)
171179
if (pEncoderParams->encodeGUID == NV_ENC_CODEC_HEVC_GUID)
172180
{
173181
bool yuv10BitFormat = (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT) ? true : false;
182+
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
183+
if (yuv10BitFormat && pEncoderParams->encodeConfig->encodeCodecConfig.hevcConfig.inputBitDepth != NV_ENC_BIT_DEPTH_10)
184+
#else
174185
if (yuv10BitFormat && pEncoderParams->encodeConfig->encodeCodecConfig.hevcConfig.pixelBitDepthMinus8 != 2)
186+
#endif
175187
{
176188
NVENC_THROW_ERROR("Invalid PixelBitdepth", NV_ENC_ERR_INVALID_PARAM);
177189
}
@@ -193,12 +205,20 @@ void NvEncoder::CreateEncoder(const NV_ENC_INITIALIZE_PARAMS* pEncoderParams)
193205
}
194206
else
195207
{
196-
NV_ENC_PRESET_CONFIG presetConfig = {};
197-
presetConfig.version = NV_ENC_PRESET_CONFIG_VER;
198-
presetConfig.presetCfg.version = NV_ENC_CONFIG_VER;
208+
#if (NVENCAPI_MAJOR_VERSION >= 12 && NVENCAPI_MINOR_VERSION >= 2)
209+
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, 0, { NV_ENC_CONFIG_VER } };
210+
#else
211+
NV_ENC_PRESET_CONFIG presetConfig = { NV_ENC_PRESET_CONFIG_VER, { NV_ENC_CONFIG_VER } };
212+
#endif
199213
m_nvenc.nvEncGetEncodePresetConfigEx(m_hEncoder, pEncoderParams->encodeGUID, pEncoderParams->presetGUID, pEncoderParams->tuningInfo, &presetConfig);
200214
memcpy(&m_encodeConfig, &presetConfig.presetCfg, sizeof(NV_ENC_CONFIG));
201215
}
216+
217+
if (((uint32_t)m_encodeConfig.frameIntervalP) > m_encodeConfig.gopLength)
218+
{
219+
m_encodeConfig.frameIntervalP = m_encodeConfig.gopLength;
220+
}
221+
202222
m_initializeParams.encodeConfig = &m_encodeConfig;
203223
NVENC_API_CALL(m_nvenc.nvEncInitializeEncoder(m_hEncoder, &m_initializeParams));
204224
m_bEncoderInitialized = true;

0 commit comments

Comments
 (0)