@@ -100,9 +100,12 @@ void NvEncoder::CreateDefaultEncoderParams(NV_ENC_INITIALIZE_PARAMS* pIntializeP
100
100
pIntializeParams->enableEncodeAsync = GetCapabilityValue (codecGuid, NV_ENC_CAPS_ASYNC_ENCODE_SUPPORT);
101
101
#endif
102
102
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
106
109
m_nvenc.nvEncGetEncodePresetConfigEx (m_hEncoder, codecGuid, presetGuid, tuningInfo, &presetConfig);
107
110
memcpy (pIntializeParams->encodeConfig , &presetConfig.presetCfg , sizeof (NV_ENC_CONFIG));
108
111
@@ -116,8 +119,13 @@ void NvEncoder::CreateDefaultEncoderParams(NV_ENC_INITIALIZE_PARAMS* pIntializeP
116
119
}
117
120
else if (pIntializeParams->encodeGUID == NV_ENC_CODEC_HEVC_GUID)
118
121
{
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
119
126
pIntializeParams->encodeConfig ->encodeCodecConfig .hevcConfig .pixelBitDepthMinus8 =
120
127
(m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV420_10BIT || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT) ? 2 : 0 ;
128
+ #endif
121
129
if (m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444 || m_eBufferFormat == NV_ENC_BUFFER_FORMAT_YUV444_10BIT)
122
130
{
123
131
pIntializeParams->encodeConfig ->encodeCodecConfig .hevcConfig .chromaFormatIDC = 3 ;
@@ -171,7 +179,11 @@ void NvEncoder::CreateEncoder(const NV_ENC_INITIALIZE_PARAMS* pEncoderParams)
171
179
if (pEncoderParams->encodeGUID == NV_ENC_CODEC_HEVC_GUID)
172
180
{
173
181
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
174
185
if (yuv10BitFormat && pEncoderParams->encodeConfig ->encodeCodecConfig .hevcConfig .pixelBitDepthMinus8 != 2 )
186
+ #endif
175
187
{
176
188
NVENC_THROW_ERROR (" Invalid PixelBitdepth" , NV_ENC_ERR_INVALID_PARAM);
177
189
}
@@ -193,12 +205,20 @@ void NvEncoder::CreateEncoder(const NV_ENC_INITIALIZE_PARAMS* pEncoderParams)
193
205
}
194
206
else
195
207
{
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
199
213
m_nvenc.nvEncGetEncodePresetConfigEx (m_hEncoder, pEncoderParams->encodeGUID , pEncoderParams->presetGUID , pEncoderParams->tuningInfo , &presetConfig);
200
214
memcpy (&m_encodeConfig, &presetConfig.presetCfg , sizeof (NV_ENC_CONFIG));
201
215
}
216
+
217
+ if (((uint32_t )m_encodeConfig.frameIntervalP ) > m_encodeConfig.gopLength )
218
+ {
219
+ m_encodeConfig.frameIntervalP = m_encodeConfig.gopLength ;
220
+ }
221
+
202
222
m_initializeParams.encodeConfig = &m_encodeConfig;
203
223
NVENC_API_CALL (m_nvenc.nvEncInitializeEncoder (m_hEncoder, &m_initializeParams));
204
224
m_bEncoderInitialized = true ;
0 commit comments