23 #include "config_components.h"
27 #if CONFIG_AV1_NVENC_ENCODER
48 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, dl_fn->cuda_dl, x)
50 #define NVENC_CAP 0x30
52 #ifndef NVENC_NO_DEPRECATED_RC
53 #define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
54 rc == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ || \
55 rc == NV_ENC_PARAMS_RC_CBR_HQ)
57 #define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR)
66 #ifdef NVENC_HAVE_422_SUPPORT
97 #define IS_10BIT(pix_fmt) (pix_fmt == AV_PIX_FMT_P010 || \
98 pix_fmt == AV_PIX_FMT_P016 || \
99 pix_fmt == AV_PIX_FMT_P210 || \
100 pix_fmt == AV_PIX_FMT_P216 || \
101 pix_fmt == AV_PIX_FMT_YUV444P16 || \
102 pix_fmt == AV_PIX_FMT_X2RGB10 || \
103 pix_fmt == AV_PIX_FMT_X2BGR10 || \
104 pix_fmt == AV_PIX_FMT_GBRP16)
106 #define IS_RGB(pix_fmt) (pix_fmt == AV_PIX_FMT_0RGB32 || \
107 pix_fmt == AV_PIX_FMT_RGB32 || \
108 pix_fmt == AV_PIX_FMT_0BGR32 || \
109 pix_fmt == AV_PIX_FMT_BGR32 || \
110 pix_fmt == AV_PIX_FMT_X2RGB10 || \
111 pix_fmt == AV_PIX_FMT_X2BGR10)
113 #define IS_YUV444(pix_fmt) (pix_fmt == AV_PIX_FMT_YUV444P || \
114 pix_fmt == AV_PIX_FMT_YUV444P16 || \
115 pix_fmt == AV_PIX_FMT_GBRP || \
116 pix_fmt == AV_PIX_FMT_GBRP16 || \
117 (ctx->rgb_mode == NVENC_RGB_MODE_444 && IS_RGB(pix_fmt)))
119 #define IS_YUV422(pix_fmt) (pix_fmt == AV_PIX_FMT_NV16 || \
120 pix_fmt == AV_PIX_FMT_P210 || \
121 pix_fmt == AV_PIX_FMT_P216)
123 #define IS_GBRP(pix_fmt) (pix_fmt == AV_PIX_FMT_GBRP || \
124 pix_fmt == AV_PIX_FMT_GBRP16)
126 static const struct {
131 { NV_ENC_SUCCESS, 0,
"success" },
132 { NV_ENC_ERR_NO_ENCODE_DEVICE,
AVERROR(ENOENT),
"no encode device" },
133 { NV_ENC_ERR_UNSUPPORTED_DEVICE,
AVERROR(ENOSYS),
"unsupported device" },
134 { NV_ENC_ERR_INVALID_ENCODERDEVICE,
AVERROR(EINVAL),
"invalid encoder device" },
135 { NV_ENC_ERR_INVALID_DEVICE,
AVERROR(EINVAL),
"invalid device" },
136 { NV_ENC_ERR_DEVICE_NOT_EXIST,
AVERROR(EIO),
"device does not exist" },
137 { NV_ENC_ERR_INVALID_PTR,
AVERROR(EFAULT),
"invalid ptr" },
138 { NV_ENC_ERR_INVALID_EVENT,
AVERROR(EINVAL),
"invalid event" },
139 { NV_ENC_ERR_INVALID_PARAM,
AVERROR(EINVAL),
"invalid param" },
140 { NV_ENC_ERR_INVALID_CALL,
AVERROR(EINVAL),
"invalid call" },
141 { NV_ENC_ERR_OUT_OF_MEMORY,
AVERROR(ENOMEM),
"out of memory" },
142 { NV_ENC_ERR_ENCODER_NOT_INITIALIZED,
AVERROR(EINVAL),
"encoder not initialized" },
143 { NV_ENC_ERR_UNSUPPORTED_PARAM,
AVERROR(ENOSYS),
"unsupported param" },
144 { NV_ENC_ERR_LOCK_BUSY,
AVERROR(EAGAIN),
"lock busy" },
146 { NV_ENC_ERR_INVALID_VERSION,
AVERROR(EINVAL),
"invalid version" },
147 { NV_ENC_ERR_MAP_FAILED,
AVERROR(EIO),
"map failed" },
148 { NV_ENC_ERR_NEED_MORE_INPUT,
AVERROR(EAGAIN),
"need more input" },
149 { NV_ENC_ERR_ENCODER_BUSY,
AVERROR(EAGAIN),
"encoder busy" },
150 { NV_ENC_ERR_EVENT_NOT_REGISTERD,
AVERROR(EBADF),
"event not registered" },
152 { NV_ENC_ERR_INCOMPATIBLE_CLIENT_KEY,
AVERROR(EINVAL),
"incompatible client key" },
153 { NV_ENC_ERR_UNIMPLEMENTED,
AVERROR(ENOSYS),
"unimplemented" },
154 { NV_ENC_ERR_RESOURCE_REGISTER_FAILED,
AVERROR(EIO),
"resource register failed" },
155 { NV_ENC_ERR_RESOURCE_NOT_REGISTERED,
AVERROR(EBADF),
"resource not registered" },
156 { NV_ENC_ERR_RESOURCE_NOT_MAPPED,
AVERROR(EBADF),
"resource not mapped" },
170 *
desc =
"unknown error";
175 const char *error_string)
178 const char *details =
"(no details)";
181 #ifdef NVENC_HAVE_GETLASTERRORSTRING
183 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
185 if (p_nvenc &&
ctx->nvencoder)
186 details = p_nvenc->nvEncGetLastErrorString(
ctx->nvencoder);
199 #define PRESET_ALIAS(alias, name, ...) \
200 [PRESET_ ## alias] = { NV_ENC_PRESET_ ## name ## _GUID, __VA_ARGS__ }
202 #define PRESET(name, ...) PRESET_ALIAS(name, name, __VA_ARGS__)
207 #ifdef NVENC_HAVE_NEW_PRESETS
246 ctx->init_encode_params.presetGUID = t->
guid;
249 #ifdef NVENC_HAVE_NEW_PRESETS
250 if (
ctx->tuning_info == NV_ENC_TUNING_INFO_LOSSLESS)
260 #if NVENCAPI_CHECK_VERSION(13, 1)
261 const char *minver =
"(unknown)";
262 #elif NVENCAPI_CHECK_VERSION(13, 0)
263 const char *minver =
"570.0";
264 #elif NVENCAPI_CHECK_VERSION(12, 2)
265 # if defined(_WIN32) || defined(__CYGWIN__)
266 const char *minver =
"551.76";
268 const char *minver =
"550.54.14";
270 #elif NVENCAPI_CHECK_VERSION(12, 1)
271 # if defined(_WIN32) || defined(__CYGWIN__)
272 const char *minver =
"531.61";
274 const char *minver =
"530.41.03";
276 #elif NVENCAPI_CHECK_VERSION(12, 0)
277 # if defined(_WIN32) || defined(__CYGWIN__)
278 const char *minver =
"522.25";
280 const char *minver =
"520.56.06";
282 #elif NVENCAPI_CHECK_VERSION(11, 1)
283 # if defined(_WIN32) || defined(__CYGWIN__)
284 const char *minver =
"471.41";
286 const char *minver =
"470.57.02";
288 #elif NVENCAPI_CHECK_VERSION(11, 0)
289 # if defined(_WIN32) || defined(__CYGWIN__)
290 const char *minver =
"456.71";
292 const char *minver =
"455.28";
294 #elif NVENCAPI_CHECK_VERSION(10, 0)
295 # if defined(_WIN32) || defined(__CYGWIN__)
296 const char *minver =
"450.51";
298 const char *minver =
"445.87";
300 #elif NVENCAPI_CHECK_VERSION(9, 1)
301 # if defined(_WIN32) || defined(__CYGWIN__)
302 const char *minver =
"436.15";
304 const char *minver =
"435.21";
306 #elif NVENCAPI_CHECK_VERSION(9, 0)
307 # if defined(_WIN32) || defined(__CYGWIN__)
308 const char *minver =
"418.81";
310 const char *minver =
"418.30";
312 #elif NVENCAPI_CHECK_VERSION(8, 2)
313 # if defined(_WIN32) || defined(__CYGWIN__)
314 const char *minver =
"397.93";
316 const char *minver =
"396.24";
318 #elif NVENCAPI_CHECK_VERSION(8, 1)
319 # if defined(_WIN32) || defined(__CYGWIN__)
320 const char *minver =
"390.77";
322 const char *minver =
"390.25";
325 # if defined(_WIN32) || defined(__CYGWIN__)
326 const char *minver =
"378.66";
328 const char *minver =
"378.13";
331 av_log(avctx,
level,
"The minimum required Nvidia driver for nvenc is %s or newer\n", minver);
339 uint32_t nvenc_max_ver;
342 ret = cuda_load_functions(&dl_fn->
cuda_dl, avctx);
346 ret = nvenc_load_functions(&dl_fn->
nvenc_dl, avctx);
352 err = dl_fn->
nvenc_dl->NvEncodeAPIGetMaxSupportedVersion(&nvenc_max_ver);
353 if (err != NV_ENC_SUCCESS)
358 if ((NVENCAPI_MAJOR_VERSION << 4 | NVENCAPI_MINOR_VERSION) > nvenc_max_ver) {
359 av_log(avctx,
AV_LOG_ERROR,
"Driver does not support the required nvenc API version. "
360 "Required: %d.%d Found: %d.%d\n",
361 NVENCAPI_MAJOR_VERSION, NVENCAPI_MINOR_VERSION,
362 nvenc_max_ver >> 4, nvenc_max_ver & 0
xf);
367 dl_fn->
nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
370 if (err != NV_ENC_SUCCESS)
383 if (
ctx->d3d11_device)
395 if (
ctx->d3d11_device)
403 NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS params = { 0 };
405 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
408 params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
409 params.apiVersion = NVENCAPI_VERSION;
410 if (
ctx->d3d11_device) {
411 params.device =
ctx->d3d11_device;
412 params.deviceType = NV_ENC_DEVICE_TYPE_DIRECTX;
414 params.device =
ctx->cu_context;
415 params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
418 ret = p_nvenc->nvEncOpenEncodeSessionEx(¶ms, &
ctx->nvencoder);
419 if (
ret != NV_ENC_SUCCESS) {
430 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
431 int i,
ret, count = 0;
434 ret = p_nvenc->nvEncGetEncodeGUIDCount(
ctx->nvencoder, &count);
436 if (
ret != NV_ENC_SUCCESS || !count)
443 ret = p_nvenc->nvEncGetEncodeGUIDs(
ctx->nvencoder, guids, count, &count);
444 if (
ret != NV_ENC_SUCCESS) {
450 for (
i = 0;
i < count;
i++) {
451 if (!memcmp(&guids[
i], &
ctx->init_encode_params.encodeGUID,
sizeof(*guids))) {
466 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
467 NV_ENC_CAPS_PARAM params = { 0 };
470 params.version = NV_ENC_CAPS_PARAM_VER;
471 params.capsToQuery = cap;
473 ret = p_nvenc->nvEncGetEncodeCaps(
ctx->nvencoder,
ctx->init_encode_params.encodeGUID, ¶ms, &
val);
475 if (
ret == NV_ENC_SUCCESS)
497 #ifdef NVENC_HAVE_422_SUPPORT
514 if (ret < avctx->
width) {
521 if (ret < avctx->
height) {
528 if (ret < avctx->max_b_frames) {
538 "Interlaced encoding is not supported. Supported level: %d\n",
550 if (
ctx->rc_lookahead > 0 &&
ret <= 0) {
556 if (
ctx->temporal_aq > 0 &&
ret <= 0) {
562 if (
ctx->weighted_pred > 0 &&
ret <= 0) {
568 if (
ctx->coder == NV_ENC_H264_ENTROPY_CODING_MODE_CABAC &&
ret <= 0) {
573 #ifdef NVENC_HAVE_BFRAME_REF_MODE
574 tmp = (
ctx->b_ref_mode >= 0) ?
ctx->b_ref_mode : NV_ENC_BFRAME_REF_MODE_DISABLED;
576 if (
tmp == NV_ENC_BFRAME_REF_MODE_EACH &&
ret != 1 &&
ret != 3) {
579 }
else if (
tmp != NV_ENC_BFRAME_REF_MODE_DISABLED &&
ret == 0) {
584 tmp = (
ctx->b_ref_mode >= 0) ?
ctx->b_ref_mode : 0;
591 #ifdef NVENC_HAVE_MULTIPLE_REF_FRAMES
593 if(avctx->
refs != NV_ENC_NUM_REF_FRAMES_AUTOSELECT &&
ret <= 0) {
598 if(avctx->
refs != 0) {
604 #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
606 if(
ctx->single_slice_intra_refresh &&
ret <= 0) {
611 if(
ctx->single_slice_intra_refresh) {
618 if((
ctx->intra_refresh ||
ctx->single_slice_intra_refresh) &&
ret <= 0) {
623 #ifndef NVENC_HAVE_HEVC_CONSTRAINED_ENCODING
631 if(
ctx->constrained_encoding &&
ret <= 0) {
636 #if defined(NVENC_HAVE_TEMPORAL_FILTER) || defined(NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER)
638 if(
ctx->tf_level > 0 &&
ret <= 0) {
644 #ifdef NVENC_HAVE_LOOKAHEAD_LEVEL
646 if(
ctx->rc_lookahead > 0 &&
ctx->lookahead_level > 0 &&
647 ctx->lookahead_level != NV_ENC_LOOKAHEAD_LEVEL_AUTOSELECT &&
648 ctx->lookahead_level >
ret)
655 #ifdef NVENC_HAVE_UNIDIR_B
657 if(
ctx->unidir_b &&
ret <= 0) {
663 ctx->support_dyn_bitrate =
nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
665 #ifdef NVENC_HAVE_MVHEVC
666 ctx->multiview_supported =
nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_MVHEVC_ENCODE) > 0;
667 if(
ctx->profile == NV_ENC_HEVC_PROFILE_MULTIVIEW_MAIN && !
ctx->multiview_supported) {
680 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
681 char name[128] = { 0};
682 int major, minor,
ret;
701 av_log(avctx, loglevel,
"[ GPU #%d - < %s > has Compute SM %d.%d ]\n", idx,
name, major, minor);
702 if (((major << 4) | minor) <
NVENC_CAP) {
703 av_log(avctx, loglevel,
"does not support NVENC\n");
714 ctx->cu_context =
ctx->cu_context_internal;
726 av_log(avctx, loglevel,
"supports NVENC\n");
737 p_nvenc->nvEncDestroyEncoder(
ctx->nvencoder);
745 ctx->cu_context_internal =
NULL;
758 ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_H264_GUID;
761 ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_HEVC_GUID;
763 #if CONFIG_AV1_NVENC_ENCODER
765 ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_AV1_GUID;
775 av_log(avctx,
AV_LOG_WARNING,
"The selected preset is deprecated. Use p1 to p7 + -tune or fast/medium/slow.\n");
799 cuda_device_hwctx = hwdev_ctx->
hwctx;
802 d3d11_device_hwctx = hwdev_ctx->
hwctx;
810 if (cuda_device_hwctx) {
812 ctx->cu_stream = cuda_device_hwctx->
stream;
815 else if (d3d11_device_hwctx) {
816 ctx->d3d11_device = d3d11_device_hwctx->
device;
817 ID3D11Device_AddRef(
ctx->d3d11_device);
827 av_log(avctx,
AV_LOG_FATAL,
"Provided device doesn't support required NVENC features\n");
831 int i, nb_devices = 0;
847 for (
i = 0;
i < nb_devices; ++
i) {
860 av_log(avctx,
AV_LOG_FATAL,
"Requested GPU %d, but only %d GPUs are available!\n",
ctx->device, nb_devices);
870 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
871 #if CONFIG_AV1_NVENC_ENCODER
877 rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
879 if (
ctx->init_qp_p >= 0) {
880 rc->constQP.qpInterP =
ctx->init_qp_p;
881 if (
ctx->init_qp_i >= 0 &&
ctx->init_qp_b >= 0) {
882 rc->constQP.qpIntra =
ctx->init_qp_i;
883 rc->constQP.qpInterB =
ctx->init_qp_b;
887 rc->constQP.qpInterB =
av_clip(
890 rc->constQP.qpIntra = rc->constQP.qpInterP;
891 rc->constQP.qpInterB = rc->constQP.qpInterP;
893 }
else if (
ctx->cqp >= 0) {
894 rc->constQP.qpInterP = rc->constQP.qpInterB = rc->constQP.qpIntra =
ctx->cqp;
908 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
910 #if CONFIG_AV1_NVENC_ENCODER
916 if (avctx->
qmin >= 0 || avctx->
qmax >= 0)
917 av_log(avctx,
AV_LOG_WARNING,
"Passing qmin/qmax via global AVCodecContext options. Use encoder options instead.\n");
919 if (avctx->
qmin >= 0 &&
ctx->qmin < 0)
921 if (avctx->
qmax >= 0 &&
ctx->qmax < 0)
926 if (
ctx->qmin >= 0 &&
ctx->qmax >= 0) {
930 rc->minQP.qpInterB =
ctx->qmin;
931 rc->minQP.qpInterP =
ctx->qmin;
932 rc->minQP.qpIntra =
ctx->qmin;
934 rc->maxQP.qpInterB =
ctx->qmax;
935 rc->maxQP.qpInterP =
ctx->qmax;
936 rc->maxQP.qpIntra =
ctx->qmax;
938 qp_inter_p = (
ctx->qmax + 3 *
ctx->qmin) / 4;
939 }
else if (
ctx->qmin >= 0) {
942 rc->minQP.qpInterB =
ctx->qmin;
943 rc->minQP.qpInterP =
ctx->qmin;
944 rc->minQP.qpIntra =
ctx->qmin;
946 qp_inter_p =
ctx->qmin;
951 rc->enableInitialRCQP = 1;
953 if (
ctx->init_qp_p < 0) {
954 rc->initialRCQP.qpInterP = qp_inter_p;
956 rc->initialRCQP.qpInterP =
ctx->init_qp_p;
959 if (
ctx->init_qp_i < 0) {
961 rc->initialRCQP.qpIntra =
av_clip(
964 rc->initialRCQP.qpIntra = rc->initialRCQP.qpInterP;
967 rc->initialRCQP.qpIntra =
ctx->init_qp_i;
970 if (
ctx->init_qp_b < 0) {
972 rc->initialRCQP.qpInterB =
av_clip(
975 rc->initialRCQP.qpInterB = rc->initialRCQP.qpInterP;
978 rc->initialRCQP.qpInterB =
ctx->init_qp_b;
985 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
987 rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
988 rc->constQP.qpInterB = 0;
989 rc->constQP.qpInterP = 0;
990 rc->constQP.qpIntra = 0;
999 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
1002 case NV_ENC_PARAMS_RC_CONSTQP:
1005 #ifndef NVENC_NO_DEPRECATED_RC
1006 case NV_ENC_PARAMS_RC_VBR_MINQP:
1007 if (avctx->
qmin < 0 &&
ctx->qmin < 0) {
1009 "The variable bitrate rate-control requires "
1010 "the 'qmin' option set.\n");
1015 case NV_ENC_PARAMS_RC_VBR_HQ:
1017 case NV_ENC_PARAMS_RC_VBR:
1020 case NV_ENC_PARAMS_RC_CBR:
1021 #ifndef NVENC_NO_DEPRECATED_RC
1022 case NV_ENC_PARAMS_RC_CBR_HQ:
1023 case NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ:
1028 rc->rateControlMode =
ctx->rc;
1037 int nb_surfaces =
FFMAX(4,
ctx->encode_config.frameIntervalP * 2 * 2);
1040 if (
ctx->rc_lookahead > 0) {
1043 nb_surfaces =
FFMAX(1,
FFMAX(nb_surfaces,
ctx->rc_lookahead +
ctx->encode_config.frameIntervalP + 1 + 4));
1044 if (nb_surfaces >
ctx->nb_surfaces &&
ctx->nb_surfaces > 0)
1047 "Defined rc_lookahead requires more surfaces, "
1048 "increasing used surfaces %d -> %d\n",
ctx->nb_surfaces, nb_surfaces);
1050 ctx->nb_surfaces =
FFMAX(nb_surfaces,
ctx->nb_surfaces);
1052 if (
ctx->encode_config.frameIntervalP > 1 &&
ctx->nb_surfaces < nb_surfaces &&
ctx->nb_surfaces > 0)
1055 "Defined b-frame requires more surfaces, "
1056 "increasing used surfaces %d -> %d\n",
ctx->nb_surfaces, nb_surfaces);
1057 ctx->nb_surfaces =
FFMAX(
ctx->nb_surfaces, nb_surfaces);
1059 else if (
ctx->nb_surfaces <= 0)
1060 ctx->nb_surfaces = nb_surfaces;
1065 ctx->async_depth =
FFMIN(
ctx->async_depth,
ctx->nb_surfaces - 1);
1069 ctx->frame_data_array_nb =
FFMAX(
ctx->nb_surfaces,
ctx->nb_surfaces +
ctx->encode_config.frameIntervalP - 1);
1079 av_log(avctx,
AV_LOG_WARNING,
"Using global_quality with nvenc is deprecated. Use qp instead.\n");
1085 ctx->encode_config.rcParams.averageBitRate = avctx->
bit_rate;
1086 }
else if (
ctx->encode_config.rcParams.averageBitRate > 0) {
1087 ctx->encode_config.rcParams.maxBitRate =
ctx->encode_config.rcParams.averageBitRate;
1093 #ifdef NVENC_HAVE_MULTIPASS
1094 ctx->encode_config.rcParams.multiPass =
ctx->multipass;
1097 ctx->encode_config.rcParams.multiPass = NV_ENC_MULTI_PASS_DISABLED;
1099 ctx->encode_config.rcParams.multiPass = NV_ENC_TWO_PASS_FULL_RESOLUTION;
1103 ctx->rc = NV_ENC_PARAMS_RC_CBR;
1104 }
else if (
ctx->cqp >= 0) {
1105 ctx->rc = NV_ENC_PARAMS_RC_CONSTQP;
1106 }
else if (
ctx->quality >= 0.0f) {
1107 ctx->rc = NV_ENC_PARAMS_RC_VBR;
1117 if (
ctx->twopass < 0)
1122 ctx->rc = NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ;
1124 ctx->rc = NV_ENC_PARAMS_RC_CBR;
1126 }
else if (
ctx->cqp >= 0) {
1127 ctx->rc = NV_ENC_PARAMS_RC_CONSTQP;
1128 }
else if (
ctx->twopass) {
1129 ctx->rc = NV_ENC_PARAMS_RC_VBR_HQ;
1130 }
else if ((avctx->
qmin >= 0 && avctx->
qmax >= 0) ||
1131 (
ctx->qmin >= 0 &&
ctx->qmax >= 0)) {
1132 ctx->rc = NV_ENC_PARAMS_RC_VBR_MINQP;
1144 #ifdef NVENC_HAVE_QP_CHROMA_OFFSETS
1145 ctx->encode_config.rcParams.cbQPIndexOffset =
ctx->qp_cb_offset;
1146 ctx->encode_config.rcParams.crQPIndexOffset =
ctx->qp_cr_offset;
1148 if (
ctx->qp_cb_offset ||
ctx->qp_cr_offset)
1149 av_log(avctx,
AV_LOG_WARNING,
"Failed setting QP CB/CR offsets, SDK 11.1 or greater required at compile time.\n");
1152 #ifdef NVENC_HAVE_LDKFS
1154 ctx->encode_config.rcParams.lowDelayKeyFrameScale =
ctx->ldkfs;
1159 }
else if (
ctx->rc >= 0) {
1162 ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
1168 }
else if (
ctx->encode_config.rcParams.averageBitRate > 0) {
1169 avctx->
rc_buffer_size =
ctx->encode_config.rcParams.vbvBufferSize = 2 *
ctx->encode_config.rcParams.averageBitRate;
1173 ctx->encode_config.rcParams.enableAQ = 1;
1174 ctx->encode_config.rcParams.aqStrength =
ctx->aq_strength;
1178 if (
ctx->temporal_aq) {
1179 ctx->encode_config.rcParams.enableTemporalAQ = 1;
1183 if (
ctx->rc_lookahead > 0) {
1184 int lkd_bound =
FFMIN(
ctx->nb_surfaces,
ctx->async_depth) -
1185 ctx->encode_config.frameIntervalP - 4;
1187 if (lkd_bound < 0) {
1188 ctx->encode_config.rcParams.enableLookahead = 0;
1190 "Lookahead not enabled. Increase buffer delay (-delay).\n");
1192 ctx->encode_config.rcParams.enableLookahead = 1;
1193 ctx->encode_config.rcParams.lookaheadDepth =
av_clip(
ctx->rc_lookahead, 0, lkd_bound);
1194 ctx->encode_config.rcParams.disableIadapt =
ctx->no_scenecut;
1195 ctx->encode_config.rcParams.disableBadapt = !
ctx->b_adapt;
1197 "Lookahead enabled: depth %d, scenecut %s, B-adapt %s.\n",
1198 ctx->encode_config.rcParams.lookaheadDepth,
1199 ctx->encode_config.rcParams.disableIadapt ?
"disabled" :
"enabled",
1200 ctx->encode_config.rcParams.disableBadapt ?
"disabled" :
"enabled");
1201 if (
ctx->encode_config.rcParams.lookaheadDepth <
ctx->rc_lookahead)
1202 av_log(avctx,
AV_LOG_WARNING,
"Clipping lookahead depth to %d (from %d) due to lack of surfaces/delay",
1203 ctx->encode_config.rcParams.lookaheadDepth,
ctx->rc_lookahead);
1205 #ifdef NVENC_HAVE_LOOKAHEAD_LEVEL
1206 if (
ctx->lookahead_level >= 0) {
1207 switch (
ctx->lookahead_level) {
1208 case NV_ENC_LOOKAHEAD_LEVEL_0:
1209 case NV_ENC_LOOKAHEAD_LEVEL_1:
1210 case NV_ENC_LOOKAHEAD_LEVEL_2:
1211 case NV_ENC_LOOKAHEAD_LEVEL_3:
1212 case NV_ENC_LOOKAHEAD_LEVEL_AUTOSELECT:
1219 ctx->encode_config.rcParams.lookaheadLevel =
ctx->lookahead_level;
1225 if (
ctx->strict_gop) {
1226 ctx->encode_config.rcParams.strictGOPTarget = 1;
1231 ctx->encode_config.rcParams.enableNonRefP = 1;
1233 if (
ctx->zerolatency)
1234 ctx->encode_config.rcParams.zeroReorderDelay = 1;
1238 int tmp_quality = (int)(
ctx->quality * 256.0f);
1239 ctx->encode_config.rcParams.targetQuality = (uint8_t)(tmp_quality >> 8);
1240 ctx->encode_config.rcParams.targetQualityLSB = (uint8_t)(tmp_quality & 0xff);
1245 ctx->encode_config.rcParams.averageBitRate = avctx->
bit_rate = 0;
1256 NV_ENC_CONFIG *cc = &
ctx->encode_config;
1257 NV_ENC_CONFIG_H264 *h264 = &cc->encodeCodecConfig.h264Config;
1258 NV_ENC_CONFIG_H264_VUI_PARAMETERS *vui = &h264->h264VUIParameters;
1265 vui->transferCharacteristics = avctx->
color_trc;
1266 vui->videoFullRangeFlag = 0;
1270 vui->transferCharacteristics = avctx->
color_trc;
1275 vui->colourDescriptionPresentFlag =
1276 (vui->colourMatrix != 2 || vui->colourPrimaries != 2 || vui->transferCharacteristics != 2);
1278 vui->videoSignalTypePresentFlag =
1279 (vui->colourDescriptionPresentFlag
1280 || vui->videoFormat != 5
1281 || vui->videoFullRangeFlag != 0);
1283 if (
ctx->max_slice_size > 0) {
1284 h264->sliceMode = 1;
1285 h264->sliceModeData =
ctx->max_slice_size;
1287 h264->sliceMode = 3;
1288 h264->sliceModeData = avctx->
slices > 0 ? avctx->
slices : 1;
1291 if (
ctx->intra_refresh) {
1292 h264->enableIntraRefresh = 1;
1293 h264->intraRefreshPeriod = cc->gopLength;
1294 h264->intraRefreshCnt = cc->gopLength - 1;
1295 cc->gopLength = NVENC_INFINITE_GOPLENGTH;
1296 h264->outputRecoveryPointSEI = 1;
1297 #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
1298 h264->singleSliceIntraRefresh =
ctx->single_slice_intra_refresh;
1302 if (
ctx->constrained_encoding)
1303 h264->enableConstrainedEncoding = 1;
1307 h264->outputAUD =
ctx->aud;
1309 if (
ctx->dpb_size >= 0) {
1311 h264->maxNumRefFrames =
ctx->dpb_size;
1314 h264->idrPeriod = cc->gopLength;
1316 if (
IS_CBR(cc->rcParams.rateControlMode)) {
1318 h264->outputBufferingPeriodSEI =
ctx->cbr_padding;
1320 #ifdef NVENC_HAVE_FILLER_DATA
1321 h264->enableFillerDataInsertion =
ctx->cbr_padding;
1325 h264->outputPictureTimingSEI = 1;
1327 #ifndef NVENC_NO_DEPRECATED_RC
1328 if (cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ ||
1329 cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_CBR_HQ ||
1330 cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_VBR_HQ) {
1331 h264->adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
1332 h264->fmoMode = NV_ENC_H264_FMO_DISABLE;
1337 h264->qpPrimeYZeroTransformBypassFlag = 1;
1339 switch(
ctx->profile) {
1341 cc->profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
1345 cc->profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
1349 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
1352 #ifdef NVENC_HAVE_H264_10BIT_SUPPORT
1353 case NV_ENC_H264_PROFILE_HIGH_10:
1354 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_10_GUID;
1358 #ifdef NVENC_HAVE_422_SUPPORT
1359 case NV_ENC_H264_PROFILE_HIGH_422:
1360 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_422_GUID;
1365 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
1371 #ifdef NVENC_HAVE_H264_10BIT_SUPPORT
1374 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_10_GUID;
1381 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
1385 #ifdef NVENC_HAVE_422_SUPPORT
1388 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_422_GUID;
1397 h264->level =
ctx->level;
1399 #ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
1400 h264->inputBitDepth =
IS_10BIT(
ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
1401 h264->outputBitDepth = (
IS_10BIT(
ctx->data_pix_fmt) ||
ctx->highbitdepth) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
1404 if (
ctx->coder >= 0)
1405 h264->entropyCodingMode =
ctx->coder;
1407 #ifdef NVENC_HAVE_BFRAME_REF_MODE
1408 if (
ctx->b_ref_mode >= 0)
1409 h264->useBFramesAsRef =
ctx->b_ref_mode;
1412 #ifdef NVENC_HAVE_MULTIPLE_REF_FRAMES
1413 h264->numRefL0 = avctx->
refs;
1414 h264->numRefL1 = avctx->
refs;
1417 #ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
1418 if (
ctx->tf_level >= 0) {
1419 h264->tfLevel =
ctx->tf_level;
1421 switch (
ctx->tf_level)
1423 case NV_ENC_TEMPORAL_FILTER_LEVEL_0:
1424 case NV_ENC_TEMPORAL_FILTER_LEVEL_4:
1431 if (
ctx->encode_config.frameIntervalP < 5)
1436 #ifdef NVENC_HAVE_TIME_CODE
1438 h264->enableTimeCode = 1;
1447 NV_ENC_CONFIG *cc = &
ctx->encode_config;
1448 NV_ENC_CONFIG_HEVC *hevc = &cc->encodeCodecConfig.hevcConfig;
1449 NV_ENC_CONFIG_HEVC_VUI_PARAMETERS *vui = &hevc->hevcVUIParameters;
1456 vui->transferCharacteristics = avctx->
color_trc;
1457 vui->videoFullRangeFlag = 0;
1461 vui->transferCharacteristics = avctx->
color_trc;
1466 vui->colourDescriptionPresentFlag =
1467 (vui->colourMatrix != 2 || vui->colourPrimaries != 2 || vui->transferCharacteristics != 2);
1469 vui->videoSignalTypePresentFlag =
1470 (vui->colourDescriptionPresentFlag
1471 || vui->videoFormat != 5
1472 || vui->videoFullRangeFlag != 0);
1474 if (
ctx->max_slice_size > 0) {
1475 hevc->sliceMode = 1;
1476 hevc->sliceModeData =
ctx->max_slice_size;
1478 hevc->sliceMode = 3;
1479 hevc->sliceModeData = avctx->
slices > 0 ? avctx->
slices : 1;
1482 if (
ctx->intra_refresh) {
1483 hevc->enableIntraRefresh = 1;
1484 hevc->intraRefreshPeriod = cc->gopLength;
1485 hevc->intraRefreshCnt = cc->gopLength - 1;
1486 cc->gopLength = NVENC_INFINITE_GOPLENGTH;
1487 #ifdef NVENC_HAVE_HEVC_OUTPUT_RECOVERY_POINT_SEI
1488 hevc->outputRecoveryPointSEI = 1;
1490 #ifdef NVENC_HAVE_SINGLE_SLICE_INTRA_REFRESH
1491 hevc->singleSliceIntraRefresh =
ctx->single_slice_intra_refresh;
1495 #ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA
1504 #ifdef NVENC_HAVE_HEVC_CONSTRAINED_ENCODING
1505 if (
ctx->constrained_encoding)
1506 hevc->enableConstrainedEncoding = 1;
1511 hevc->outputAUD =
ctx->aud;
1513 if (
ctx->dpb_size >= 0) {
1515 hevc->maxNumRefFramesInDPB =
ctx->dpb_size;
1518 hevc->idrPeriod = cc->gopLength;
1520 if (
IS_CBR(cc->rcParams.rateControlMode)) {
1522 hevc->outputBufferingPeriodSEI =
ctx->cbr_padding;
1524 #ifdef NVENC_HAVE_FILLER_DATA
1525 hevc->enableFillerDataInsertion =
ctx->cbr_padding;
1529 hevc->outputPictureTimingSEI = 1;
1531 #ifdef NVENC_HAVE_MVHEVC
1538 ctx->profile = NV_ENC_HEVC_PROFILE_MULTIVIEW_MAIN;
1540 if (
ctx->profile == NV_ENC_HEVC_PROFILE_MULTIVIEW_MAIN && stereo3d &&
1551 switch (
ctx->profile) {
1553 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
1557 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN10_GUID;
1561 cc->profileGUID = NV_ENC_HEVC_PROFILE_FREXT_GUID;
1564 #ifdef NVENC_HAVE_MVHEVC
1565 case NV_ENC_HEVC_PROFILE_MULTIVIEW_MAIN:
1566 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
1570 hevc->enableMVHEVC = 1;
1571 hevc->outputHevc3DReferenceDisplayInfo = 1;
1580 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN10_GUID;
1586 cc->profileGUID = NV_ENC_HEVC_PROFILE_FREXT_GUID;
1590 #ifdef NVENC_HAVE_MVHEVC
1592 av_log(avctx,
AV_LOG_ERROR,
"Multiview encoding only works for Main profile content.\n");
1599 #ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
1600 hevc->inputBitDepth =
IS_10BIT(
ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
1601 hevc->outputBitDepth = (
IS_10BIT(
ctx->data_pix_fmt) ||
ctx->highbitdepth) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
1603 hevc->pixelBitDepthMinus8 =
IS_10BIT(
ctx->data_pix_fmt) ? 2 : 0;
1606 hevc->level =
ctx->level;
1608 hevc->tier =
ctx->tier;
1610 #ifdef NVENC_HAVE_HEVC_BFRAME_REF_MODE
1611 if (
ctx->b_ref_mode >= 0)
1612 hevc->useBFramesAsRef =
ctx->b_ref_mode;
1615 #ifdef NVENC_HAVE_MULTIPLE_REF_FRAMES
1616 hevc->numRefL0 = avctx->
refs;
1617 hevc->numRefL1 = avctx->
refs;
1620 #ifdef NVENC_HAVE_TEMPORAL_FILTER
1621 if (
ctx->tf_level >= 0) {
1622 hevc->tfLevel =
ctx->tf_level;
1624 switch (
ctx->tf_level)
1626 case NV_ENC_TEMPORAL_FILTER_LEVEL_0:
1627 case NV_ENC_TEMPORAL_FILTER_LEVEL_4:
1634 if (
ctx->encode_config.frameIntervalP < 5)
1642 #if CONFIG_AV1_NVENC_ENCODER
1646 NV_ENC_CONFIG *cc = &
ctx->encode_config;
1647 NV_ENC_CONFIG_AV1 *av1 = &cc->encodeCodecConfig.av1Config;
1654 av1->transferCharacteristics = avctx->
color_trc;
1655 av1->colorRange = 0;
1659 av1->transferCharacteristics = avctx->
color_trc;
1665 av_log(avctx,
AV_LOG_ERROR,
"AV1 High Profile not supported, required for 4:4:4 encoding\n");
1668 cc->profileGUID = NV_ENC_AV1_PROFILE_MAIN_GUID;
1672 if (
ctx->dpb_size >= 0) {
1674 av1->maxNumRefFramesInDPB =
ctx->dpb_size;
1677 if (
ctx->intra_refresh) {
1678 av1->enableIntraRefresh = 1;
1679 av1->intraRefreshPeriod = cc->gopLength;
1680 av1->intraRefreshCnt = cc->gopLength - 1;
1681 cc->gopLength = NVENC_INFINITE_GOPLENGTH;
1684 av1->idrPeriod = cc->gopLength;
1686 if (
IS_CBR(cc->rcParams.rateControlMode)) {
1687 av1->enableBitstreamPadding =
ctx->cbr_padding;
1690 if (
ctx->tile_cols >= 0)
1691 av1->numTileColumns =
ctx->tile_cols;
1692 if (
ctx->tile_rows >= 0)
1693 av1->numTileRows =
ctx->tile_rows;
1695 av1->outputAnnexBFormat = 0;
1697 av1->level =
ctx->level;
1698 av1->tier =
ctx->tier;
1700 av1->enableTimingInfo =
ctx->timing_info;
1703 av1->disableSeqHdr = 0;
1704 av1->repeatSeqHdr = 1;
1706 av1->chromaFormatIDC =
IS_YUV444(
ctx->data_pix_fmt) ? 3 : 1;
1708 #ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
1709 av1->inputBitDepth =
IS_10BIT(
ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
1710 av1->outputBitDepth = (
IS_10BIT(
ctx->data_pix_fmt) ||
ctx->highbitdepth) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
1712 av1->inputPixelBitDepthMinus8 =
IS_10BIT(
ctx->data_pix_fmt) ? 2 : 0;
1713 av1->pixelBitDepthMinus8 = (
IS_10BIT(
ctx->data_pix_fmt) ||
ctx->highbitdepth) ? 2 : 0;
1716 #ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA
1725 if (
ctx->b_ref_mode >= 0)
1726 av1->useBFramesAsRef =
ctx->b_ref_mode;
1728 av1->numFwdRefs = avctx->
refs;
1729 av1->numBwdRefs = avctx->
refs;
1731 #ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
1732 if (
ctx->tf_level >= 0) {
1733 av1->tfLevel =
ctx->tf_level;
1735 switch (
ctx->tf_level)
1737 case NV_ENC_TEMPORAL_FILTER_LEVEL_0:
1738 case NV_ENC_TEMPORAL_FILTER_LEVEL_4:
1745 if (
ctx->encode_config.frameIntervalP < 5)
1761 #if CONFIG_AV1_NVENC_ENCODER
1763 return nvenc_setup_av1_config(avctx);
1777 #if CONFIG_AV1_NVENC_ENCODER
1808 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1810 NV_ENC_PRESET_CONFIG preset_config = { 0 };
1811 NVENCSTATUS nv_status = NV_ENC_SUCCESS;
1816 ctx->encode_config.version = NV_ENC_CONFIG_VER;
1817 ctx->init_encode_params.version = NV_ENC_INITIALIZE_PARAMS_VER;
1819 ctx->init_encode_params.encodeHeight = avctx->
height;
1820 ctx->init_encode_params.encodeWidth = avctx->
width;
1822 ctx->init_encode_params.encodeConfig = &
ctx->encode_config;
1824 preset_config.version = NV_ENC_PRESET_CONFIG_VER;
1825 preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
1827 #ifdef NVENC_HAVE_NEW_PRESETS
1828 ctx->init_encode_params.tuningInfo =
ctx->tuning_info;
1831 ctx->init_encode_params.tuningInfo = NV_ENC_TUNING_INFO_LOSSLESS;
1833 ctx->init_encode_params.tuningInfo = NV_ENC_TUNING_INFO_LOW_LATENCY;
1835 nv_status = p_nvenc->nvEncGetEncodePresetConfigEx(
ctx->nvencoder,
1836 ctx->init_encode_params.encodeGUID,
1837 ctx->init_encode_params.presetGUID,
1838 ctx->init_encode_params.tuningInfo,
1841 nv_status = p_nvenc->nvEncGetEncodePresetConfig(
ctx->nvencoder,
1842 ctx->init_encode_params.encodeGUID,
1843 ctx->init_encode_params.presetGUID,
1846 if (nv_status != NV_ENC_SUCCESS)
1847 return nvenc_print_error(avctx, nv_status,
"Cannot get the preset configuration");
1849 memcpy(&
ctx->encode_config, &preset_config.presetCfg,
sizeof(
ctx->encode_config));
1851 ctx->encode_config.version = NV_ENC_CONFIG_VER;
1854 ctx->init_encode_params.darHeight = dh;
1855 ctx->init_encode_params.darWidth = dw;
1865 #ifdef NVENC_HAVE_UNIDIR_B
1866 ctx->init_encode_params.enableUniDirectionalB =
ctx->unidir_b;
1869 ctx->init_encode_params.enableEncodeAsync = 0;
1870 ctx->init_encode_params.enablePTD = 1;
1872 #ifdef NVENC_HAVE_NEW_PRESETS
1876 if (
ctx->rc_lookahead == 0 &&
ctx->encode_config.rcParams.enableLookahead)
1877 ctx->rc_lookahead =
ctx->encode_config.rcParams.lookaheadDepth;
1880 if (
ctx->weighted_pred == 1)
1881 ctx->init_encode_params.enableWeightedPrediction = 1;
1883 #ifdef NVENC_HAVE_SPLIT_FRAME_ENCODING
1884 ctx->init_encode_params.splitEncodeMode =
ctx->split_encode_mode;
1886 if (
ctx->split_encode_mode != NV_ENC_SPLIT_DISABLE_MODE) {
1888 av_log(avctx,
AV_LOG_WARNING,
"Split encoding not supported with weighted prediction enabled.\n");
1892 if (
ctx->bluray_compat) {
1901 ctx->level = NV_ENC_LEVEL_HEVC_51;
1902 ctx->tier = NV_ENC_TIER_HEVC_HIGH;
1911 ctx->encode_config.frameIntervalP = 0;
1912 ctx->encode_config.gopLength = 1;
1921 if(
ctx->single_slice_intra_refresh)
1922 ctx->intra_refresh = 1;
1931 ctx->encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD;
1933 ctx->encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;
1944 nv_status = p_nvenc->nvEncInitializeEncoder(
ctx->nvencoder, &
ctx->init_encode_params);
1945 if (nv_status != NV_ENC_SUCCESS) {
1950 #ifdef NVENC_HAVE_CUSTREAM_PTR
1951 if (
ctx->cu_context) {
1952 nv_status = p_nvenc->nvEncSetIOCudaStreams(
ctx->nvencoder, &
ctx->cu_stream, &
ctx->cu_stream);
1953 if (nv_status != NV_ENC_SUCCESS) {
1964 if (
ctx->encode_config.frameIntervalP > 1)
1967 if (
ctx->encode_config.rcParams.averageBitRate > 0)
1968 avctx->
bit_rate =
ctx->encode_config.rcParams.averageBitRate;
1975 cpb_props->
buffer_size =
ctx->encode_config.rcParams.vbvBufferSize;
1984 return NV_ENC_BUFFER_FORMAT_YV12;
1986 return NV_ENC_BUFFER_FORMAT_NV12;
1989 return NV_ENC_BUFFER_FORMAT_YUV420_10BIT;
1992 return NV_ENC_BUFFER_FORMAT_YUV444;
1995 return NV_ENC_BUFFER_FORMAT_YUV444_10BIT;
1998 return NV_ENC_BUFFER_FORMAT_ARGB;
2001 return NV_ENC_BUFFER_FORMAT_ABGR;
2003 return NV_ENC_BUFFER_FORMAT_ARGB10;
2005 return NV_ENC_BUFFER_FORMAT_ABGR10;
2006 #ifdef NVENC_HAVE_422_SUPPORT
2008 return NV_ENC_BUFFER_FORMAT_NV16;
2011 return NV_ENC_BUFFER_FORMAT_P210;
2014 return NV_ENC_BUFFER_FORMAT_UNDEFINED;
2022 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2025 NVENCSTATUS nv_status;
2026 NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
2027 allocOut.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
2031 if (!
ctx->surfaces[idx].in_ref)
2034 NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
2037 if (
ctx->surfaces[idx].format == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
2043 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
2044 allocSurf.width = avctx->
width;
2045 allocSurf.height = avctx->
height;
2046 allocSurf.bufferFmt =
ctx->surfaces[idx].format;
2048 nv_status = p_nvenc->nvEncCreateInputBuffer(
ctx->nvencoder, &allocSurf);
2049 if (nv_status != NV_ENC_SUCCESS) {
2053 ctx->surfaces[idx].input_surface = allocSurf.inputBuffer;
2054 ctx->surfaces[idx].width = allocSurf.width;
2055 ctx->surfaces[idx].height = allocSurf.height;
2058 nv_status = p_nvenc->nvEncCreateBitstreamBuffer(
ctx->nvencoder, &allocOut);
2059 if (nv_status != NV_ENC_SUCCESS) {
2062 p_nvenc->nvEncDestroyInputBuffer(
ctx->nvencoder,
ctx->surfaces[idx].input_surface);
2067 ctx->surfaces[idx].output_surface = allocOut.bitstreamBuffer;
2077 int i, res = 0, res2;
2083 ctx->frame_data_array =
av_calloc(
ctx->frame_data_array_nb,
sizeof(*
ctx->frame_data_array));
2084 if (!
ctx->frame_data_array)
2089 if (!
ctx->timestamp_list)
2093 if (!
ctx->unused_surface_queue)
2097 if (!
ctx->output_surface_queue)
2100 if (!
ctx->output_surface_ready_queue)
2107 for (
i = 0;
i <
ctx->nb_surfaces;
i++) {
2124 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2126 NVENCSTATUS nv_status;
2127 uint32_t outSize = 0;
2128 char tmpHeader[NV_MAX_SEQ_HDR_LEN];
2130 NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
2131 payload.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
2133 payload.spsppsBuffer = tmpHeader;
2134 payload.inBufferSize =
sizeof(tmpHeader);
2135 payload.outSPSPPSPayloadSize = &outSize;
2137 nv_status = p_nvenc->nvEncGetSequenceParams(
ctx->nvencoder, &payload);
2138 if (nv_status != NV_ENC_SUCCESS) {
2149 memcpy(avctx->
extradata, tmpHeader, outSize);
2158 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2162 if (
ctx->nvencoder) {
2163 NV_ENC_PIC_PARAMS params = { .version = NV_ENC_PIC_PARAMS_VER,
2164 .encodePicFlags = NV_ENC_PIC_FLAG_EOS };
2170 p_nvenc->nvEncEncodePicture(
ctx->nvencoder, ¶ms);
2178 if (
ctx->frame_data_array) {
2179 for (
i = 0;
i <
ctx->frame_data_array_nb;
i++)
2185 for (
i = 0;
i <
ctx->nb_registered_frames;
i++) {
2186 if (
ctx->registered_frames[
i].mapped)
2187 p_nvenc->nvEncUnmapInputResource(
ctx->nvencoder,
ctx->registered_frames[
i].in_map.mappedResource);
2188 if (
ctx->registered_frames[
i].regptr)
2189 p_nvenc->nvEncUnregisterResource(
ctx->nvencoder,
ctx->registered_frames[
i].regptr);
2191 ctx->nb_registered_frames = 0;
2194 if (
ctx->surfaces) {
2195 for (
i = 0;
i <
ctx->nb_surfaces; ++
i) {
2197 p_nvenc->nvEncDestroyInputBuffer(
ctx->nvencoder,
ctx->surfaces[
i].input_surface);
2199 p_nvenc->nvEncDestroyBitstreamBuffer(
ctx->nvencoder,
ctx->surfaces[
i].output_surface);
2203 ctx->nb_surfaces = 0;
2209 if (
ctx->nvencoder) {
2210 p_nvenc->nvEncDestroyEncoder(
ctx->nvencoder);
2218 if (
ctx->cu_context_internal)
2220 ctx->cu_context =
ctx->cu_context_internal =
NULL;
2223 if (
ctx->d3d11_device) {
2224 ID3D11Device_Release(
ctx->d3d11_device);
2229 nvenc_free_functions(&dl_fn->
nvenc_dl);
2230 cuda_free_functions(&dl_fn->
cuda_dl);
2248 "hw_frames_ctx must be set when using GPU frames as input\n");
2254 "hw_frames_ctx must match the GPU frame type\n");
2303 NV_ENC_LOCK_INPUT_BUFFER *lock_buffer_params,
const AVFrame *
frame)
2305 int dst_linesize[4] = {
2306 lock_buffer_params->pitch,
2307 lock_buffer_params->pitch,
2308 lock_buffer_params->pitch,
2309 lock_buffer_params->pitch
2311 uint8_t *dst_data[4];
2315 dst_linesize[1] = dst_linesize[2] >>= 1;
2318 lock_buffer_params->bufferDataPtr, dst_linesize);
2323 FFSWAP(uint8_t*, dst_data[1], dst_data[2]);
2336 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2337 NVENCSTATUS nv_status;
2342 for (first_round = 1; first_round >= 0; first_round--) {
2343 for (
i = 0;
i <
ctx->nb_registered_frames;
i++) {
2344 if (!
ctx->registered_frames[
i].mapped) {
2345 if (
ctx->registered_frames[
i].regptr) {
2348 nv_status = p_nvenc->nvEncUnregisterResource(
ctx->nvencoder,
ctx->registered_frames[
i].regptr);
2349 if (nv_status != NV_ENC_SUCCESS)
2350 return nvenc_print_error(avctx, nv_status,
"Failed unregistering unused input resource");
2351 ctx->registered_frames[
i].ptr =
NULL;
2352 ctx->registered_frames[
i].regptr =
NULL;
2359 return ctx->nb_registered_frames++;
2370 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2373 NV_ENC_REGISTER_RESOURCE reg = { 0 };
2376 for (
i = 0;
i <
ctx->nb_registered_frames;
i++) {
2387 reg.version = NV_ENC_REGISTER_RESOURCE_VER;
2388 reg.width = frames_ctx->width;
2389 reg.height = frames_ctx->height;
2390 reg.pitch =
frame->linesize[0];
2391 reg.resourceToRegister =
frame->data[0];
2394 reg.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR;
2397 reg.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX;
2398 reg.subResourceIndex = (intptr_t)
frame->data[1];
2402 if (reg.bufferFormat == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
2408 ret = p_nvenc->nvEncRegisterResource(
ctx->nvencoder, ®);
2409 if (
ret != NV_ENC_SUCCESS) {
2414 ctx->registered_frames[idx].ptr =
frame->data[0];
2415 ctx->registered_frames[idx].ptr_index = reg.subResourceIndex;
2416 ctx->registered_frames[idx].regptr = reg.registeredResource;
2425 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2428 NVENCSTATUS nv_status;
2441 if (!
ctx->registered_frames[reg_idx].mapped) {
2442 ctx->registered_frames[reg_idx].in_map.version = NV_ENC_MAP_INPUT_RESOURCE_VER;
2443 ctx->registered_frames[reg_idx].in_map.registeredResource =
ctx->registered_frames[reg_idx].regptr;
2444 nv_status = p_nvenc->nvEncMapInputResource(
ctx->nvencoder, &
ctx->registered_frames[reg_idx].in_map);
2445 if (nv_status != NV_ENC_SUCCESS) {
2451 ctx->registered_frames[reg_idx].mapped += 1;
2453 nvenc_frame->
reg_idx = reg_idx;
2454 nvenc_frame->
input_surface =
ctx->registered_frames[reg_idx].in_map.mappedResource;
2455 nvenc_frame->
format =
ctx->registered_frames[reg_idx].in_map.mappedBufferFmt;
2460 NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
2462 lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
2465 nv_status = p_nvenc->nvEncLockInputBuffer(
ctx->nvencoder, &lockBufferParams);
2466 if (nv_status != NV_ENC_SUCCESS) {
2467 return nvenc_print_error(avctx, nv_status,
"Failed locking nvenc input buffer");
2470 nvenc_frame->
pitch = lockBufferParams.pitch;
2473 nv_status = p_nvenc->nvEncUnlockInputBuffer(
ctx->nvencoder, nvenc_frame->
input_surface);
2474 if (nv_status != NV_ENC_SUCCESS) {
2482 #ifdef NVENC_HAVE_TIME_CODE
2488 uint32_t *tc = (uint32_t*)sd->
data;
2493 time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME;
2494 time_code->skipClockTimestampInsertion = 1;
2497 time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME_DOUBLING;
2500 time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME_TRIPLING;
2503 time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME;
2507 for (
int i = 0;
i < cnt;
i++) {
2508 unsigned hh, mm,
ss, ff, drop;
2511 time_code->clockTimestamp[
i].countingType = 0;
2512 time_code->clockTimestamp[
i].discontinuityFlag = 0;
2513 time_code->clockTimestamp[
i].cntDroppedFrames = drop;
2514 time_code->clockTimestamp[
i].nFrames = ff;
2515 time_code->clockTimestamp[
i].secondsValue =
ss;
2516 time_code->clockTimestamp[
i].minutesValue = mm;
2517 time_code->clockTimestamp[
i].hoursValue = hh;
2518 time_code->clockTimestamp[
i].timeOffset = 0;
2521 time_code->displayPicStruct = NV_ENC_PIC_STRUCT_DISPLAY_FRAME;
2522 time_code->skipClockTimestampInsertion = 1;
2528 NV_ENC_PIC_PARAMS *params,
2529 NV_ENC_SEI_PAYLOAD *sei_data,
2536 params->codecPicParams.h264PicParams.sliceMode =
2537 ctx->encode_config.encodeCodecConfig.h264Config.sliceMode;
2538 params->codecPicParams.h264PicParams.sliceModeData =
2539 ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData;
2540 if (sei_count > 0) {
2541 params->codecPicParams.h264PicParams.seiPayloadArray = sei_data;
2542 params->codecPicParams.h264PicParams.seiPayloadArrayCnt = sei_count;
2545 #ifdef NVENC_HAVE_TIME_CODE
2547 nvenc_fill_time_code(avctx,
frame, ¶ms->codecPicParams.h264PicParams.timeCode);
2552 params->codecPicParams.hevcPicParams.sliceMode =
2553 ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode;
2554 params->codecPicParams.hevcPicParams.sliceModeData =
2555 ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
2556 if (sei_count > 0) {
2557 params->codecPicParams.hevcPicParams.seiPayloadArray = sei_data;
2558 params->codecPicParams.hevcPicParams.seiPayloadArrayCnt = sei_count;
2562 #if CONFIG_AV1_NVENC_ENCODER
2564 params->codecPicParams.av1PicParams.numTileColumns =
2565 ctx->encode_config.encodeCodecConfig.av1Config.numTileColumns;
2566 params->codecPicParams.av1PicParams.numTileRows =
2567 ctx->encode_config.encodeCodecConfig.av1Config.numTileRows;
2568 if (sei_count > 0) {
2569 params->codecPicParams.av1PicParams.obuPayloadArray = sei_data;
2570 params->codecPicParams.av1PicParams.obuPayloadArrayCnt = sei_count;
2601 NV_ENC_LOCK_BITSTREAM *params,
2608 pkt->
pts = params->outputTimeStamp;
2616 delay =
FFMAX(
ctx->encode_config.frameIntervalP - 1, 0);
2617 #ifdef NVENC_HAVE_MVHEVC
2618 delay *=
ctx->multiview ? 2 : 1;
2620 if (
ctx->output_frame_num >= delay) {
2622 ctx->output_frame_num++;
2626 delay_time =
ctx->initial_delay_time;
2634 delay_time = t1 - t2;
2639 delay_time = delay * (t3 - t2);
2643 ctx->initial_delay_time = delay_time;
2652 ctx->output_frame_num++;
2662 int idx =
ctx->frame_data_array_pos;
2677 ctx->frame_data_array_pos = (
ctx->frame_data_array_pos + 1) %
ctx->frame_data_array_nb;
2678 pic_params->inputDuration = idx;
2688 int idx = lock_params->outputDuration;
2708 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2710 NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
2711 NVENCSTATUS nv_status;
2716 lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
2718 lock_params.doNotWait = 0;
2721 nv_status = p_nvenc->nvEncLockBitstream(
ctx->nvencoder, &lock_params);
2722 if (nv_status != NV_ENC_SUCCESS) {
2734 memcpy(
pkt->
data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
2736 nv_status = p_nvenc->nvEncUnlockBitstream(
ctx->nvencoder, tmpoutsurf->
output_surface);
2737 if (nv_status != NV_ENC_SUCCESS) {
2738 res =
nvenc_print_error(avctx, nv_status,
"Failed unlocking bitstream buffer, expect the gates of mordor to open");
2744 ctx->registered_frames[tmpoutsurf->
reg_idx].mapped -= 1;
2745 if (
ctx->registered_frames[tmpoutsurf->
reg_idx].mapped == 0) {
2746 nv_status = p_nvenc->nvEncUnmapInputResource(
ctx->nvencoder,
ctx->registered_frames[tmpoutsurf->
reg_idx].in_map.mappedResource);
2747 if (nv_status != NV_ENC_SUCCESS) {
2751 }
else if (
ctx->registered_frames[tmpoutsurf->
reg_idx].mapped < 0) {
2761 switch (lock_params.pictureType) {
2762 case NV_ENC_PIC_TYPE_IDR:
2764 case NV_ENC_PIC_TYPE_I:
2767 case NV_ENC_PIC_TYPE_P:
2770 case NV_ENC_PIC_TYPE_B:
2773 case NV_ENC_PIC_TYPE_BI:
2777 av_log(avctx,
AV_LOG_ERROR,
"Unknown picture type encountered, expect the output to be broken.\n");
2778 av_log(avctx,
AV_LOG_ERROR,
"Please report this error and include as much information on how to reproduce it as possible.\n");
2806 int nb_ready, nb_pending;
2811 return nb_ready > 0;
2812 return (nb_ready > 0) && (nb_ready + nb_pending >=
ctx->async_depth);
2822 void *a53_data =
NULL;
2823 size_t a53_size = 0;
2831 &
ctx->sei_data_size,
2832 (sei_count + 1) *
sizeof(*
ctx->sei_data));
2839 ctx->sei_data[sei_count].payloadSize = (uint32_t)a53_size;
2840 ctx->sei_data[sei_count].payload = (uint8_t*)a53_data;
2842 #if CONFIG_AV1_NVENC_ENCODER
2855 void *tc_data =
NULL;
2864 &
ctx->sei_data_size,
2865 (sei_count + 1) *
sizeof(*
ctx->sei_data));
2872 ctx->sei_data[sei_count].payloadSize = (uint32_t)tc_size;
2873 ctx->sei_data[sei_count].payload = (uint8_t*)tc_data;
2875 #if CONFIG_AV1_NVENC_ENCODER
2890 for (
i = 0;
i <
frame->nb_side_data;
i++) {
2898 &
ctx->sei_data_size,
2899 (sei_count + 1) *
sizeof(*
ctx->sei_data));
2905 ctx->sei_data[sei_count].payloadSize = side_data->
size;
2909 if (!
ctx->sei_data[sei_count].payload) {
2921 for (
i = 0;
i < sei_count;
i++)
2930 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
2933 NV_ENC_RECONFIGURE_PARAMS params = { 0 };
2934 int needs_reconfig = 0;
2935 int needs_encode_config = 0;
2936 int reconfig_bitrate = 0, reconfig_dar = 0;
2939 params.version = NV_ENC_RECONFIGURE_PARAMS_VER;
2940 params.reInitEncodeParams =
ctx->init_encode_params;
2943 if (dw !=
ctx->init_encode_params.darWidth || dh !=
ctx->init_encode_params.darHeight) {
2945 "aspect ratio change (DAR): %d:%d -> %d:%d\n",
2946 ctx->init_encode_params.darWidth,
2947 ctx->init_encode_params.darHeight, dw, dh);
2949 params.reInitEncodeParams.darHeight = dh;
2950 params.reInitEncodeParams.darWidth = dw;
2956 if (
ctx->rc != NV_ENC_PARAMS_RC_CONSTQP &&
ctx->support_dyn_bitrate) {
2957 if (avctx->
bit_rate > 0 && params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate != avctx->
bit_rate) {
2959 "avg bitrate change: %d -> %d\n",
2960 params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate,
2963 params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate = avctx->
bit_rate;
2964 reconfig_bitrate = 1;
2969 "max bitrate change: %d -> %d\n",
2970 params.reInitEncodeParams.encodeConfig->rcParams.maxBitRate,
2973 params.reInitEncodeParams.encodeConfig->rcParams.maxBitRate = avctx->
rc_max_rate;
2974 reconfig_bitrate = 1;
2979 "vbv buffer size change: %d -> %d\n",
2980 params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize,
2983 params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize = avctx->
rc_buffer_size;
2984 reconfig_bitrate = 1;
2987 if (reconfig_bitrate) {
2988 params.resetEncoder = 1;
2989 params.forceIDR = 1;
2991 needs_encode_config = 1;
2996 if (!needs_encode_config)
2997 params.reInitEncodeParams.encodeConfig =
NULL;
2999 if (needs_reconfig) {
3000 ret = p_nvenc->nvEncReconfigureEncoder(
ctx->nvencoder, ¶ms);
3001 if (
ret != NV_ENC_SUCCESS) {
3005 ctx->init_encode_params.darHeight = dh;
3006 ctx->init_encode_params.darWidth = dw;
3009 if (reconfig_bitrate) {
3010 ctx->encode_config.rcParams.averageBitRate = params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate;
3011 ctx->encode_config.rcParams.maxBitRate = params.reInitEncodeParams.encodeConfig->rcParams.maxBitRate;
3012 ctx->encode_config.rcParams.vbvBufferSize = params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize;
3019 #ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA
3021 MASTERING_DISPLAY_INFO *mastering_disp_info, CONTENT_LIGHT_LEVEL *content_light_level)
3025 if (
ctx->mdm ||
ctx->cll) {
3066 pic_params->codecPicParams.hevcPicParams.pMasteringDisplay = mastering_disp_info;
3068 pic_params->codecPicParams.av1PicParams.pMasteringDisplay = mastering_disp_info;
3075 content_light_level->maxContentLightLevel = cll->
MaxCLL;
3076 content_light_level->maxPicAverageLightLevel = cll->
MaxFALL;
3079 pic_params->codecPicParams.hevcPicParams.pMaxCll = content_light_level;
3081 pic_params->codecPicParams.av1PicParams.pMaxCll = content_light_level;
3093 NVENCSTATUS nv_status;
3098 #ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA
3099 MASTERING_DISPLAY_INFO mastering_disp_info = { 0 };
3100 CONTENT_LIGHT_LEVEL content_light_level = { 0 };
3102 #ifdef NVENC_HAVE_MVHEVC
3103 HEVC_3D_REFERENCE_DISPLAY_INFO ref_disp_info = { 0 };
3108 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
3110 NV_ENC_PIC_PARAMS pic_params = { 0 };
3111 pic_params.version = NV_ENC_PIC_PARAMS_VER;
3113 if ((!
ctx->cu_context && !
ctx->d3d11_device) || !
ctx->nvencoder)
3137 pic_params.bufferFmt = in_surf->
format;
3138 pic_params.inputWidth = in_surf->
width;
3139 pic_params.inputHeight = in_surf->
height;
3140 pic_params.inputPitch = in_surf->
pitch;
3145 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM;
3147 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP;
3149 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
3153 pic_params.encodePicFlags =
3154 ctx->forced_idr ? NV_ENC_PIC_FLAG_FORCEIDR : NV_ENC_PIC_FLAG_FORCEINTRA;
3156 pic_params.encodePicFlags = 0;
3159 pic_params.frameIdx =
ctx->frame_idx_counter++;
3160 pic_params.inputTimeStamp =
frame->pts;
3162 if (
ctx->extra_sei) {
3169 #ifdef NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA
3170 res = nvenc_set_mastering_display_data(avctx,
frame, &pic_params, &mastering_disp_info, &content_light_level);
3175 #ifdef NVENC_HAVE_MVHEVC
3176 if (
ctx->multiview) {
3181 ctx->next_view_id = *(
int*)sd_view_id->
data;
3183 pic_params.codecPicParams.hevcPicParams.viewId =
ctx->next_view_id;
3207 pic_params.codecPicParams.hevcPicParams.p3DReferenceDisplayInfo = &ref_disp_info;
3208 ctx->display_sei_sent = 1;
3209 }
else if (!
ctx->display_sei_sent) {
3210 ref_disp_info.precRefDisplayWidth = 31;
3211 ref_disp_info.leftViewId[0] = 0;
3212 ref_disp_info.rightViewId[0] = 1;
3214 pic_params.codecPicParams.hevcPicParams.p3DReferenceDisplayInfo = &ref_disp_info;
3215 ctx->display_sei_sent = 1;
3218 ctx->next_view_id = !
ctx->next_view_id;
3228 pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
3235 nv_status = p_nvenc->nvEncEncodePicture(
ctx->nvencoder, &pic_params);
3237 for (
i = 0;
i < sei_count;
i++)
3244 if (nv_status != NV_ENC_SUCCESS &&
3245 nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
3256 if (nv_status == NV_ENC_SUCCESS) {
3257 while (
av_fifo_read(
ctx->output_surface_queue, &tmp_out_surf, 1) >= 0)
3273 if ((!
ctx->cu_context && !
ctx->d3d11_device) || !
ctx->nvencoder)
3276 if (!
frame->buf[0]) {
3321 ctx->output_frame_num = 0;
3322 ctx->initial_delay_time = 0;