39 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, dl_fn->cuda_dl, x)
41 #define NVENC_CAP 0x30
42 #define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
43 rc == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ || \
44 rc == NV_ENC_PARAMS_RC_CBR_HQ)
72 #define IS_10BIT(pix_fmt) (pix_fmt == AV_PIX_FMT_P010 || \
73 pix_fmt == AV_PIX_FMT_P016 || \
74 pix_fmt == AV_PIX_FMT_YUV444P16)
76 #define IS_YUV444(pix_fmt) (pix_fmt == AV_PIX_FMT_YUV444P || \
77 pix_fmt == AV_PIX_FMT_YUV444P16)
84 { NV_ENC_SUCCESS, 0,
"success" },
85 { NV_ENC_ERR_NO_ENCODE_DEVICE,
AVERROR(ENOENT),
"no encode device" },
86 { NV_ENC_ERR_UNSUPPORTED_DEVICE,
AVERROR(ENOSYS),
"unsupported device" },
87 { NV_ENC_ERR_INVALID_ENCODERDEVICE,
AVERROR(EINVAL),
"invalid encoder device" },
88 { NV_ENC_ERR_INVALID_DEVICE,
AVERROR(EINVAL),
"invalid device" },
89 { NV_ENC_ERR_DEVICE_NOT_EXIST,
AVERROR(EIO),
"device does not exist" },
90 { NV_ENC_ERR_INVALID_PTR,
AVERROR(EFAULT),
"invalid ptr" },
91 { NV_ENC_ERR_INVALID_EVENT,
AVERROR(EINVAL),
"invalid event" },
92 { NV_ENC_ERR_INVALID_PARAM,
AVERROR(EINVAL),
"invalid param" },
93 { NV_ENC_ERR_INVALID_CALL,
AVERROR(EINVAL),
"invalid call" },
94 { NV_ENC_ERR_OUT_OF_MEMORY,
AVERROR(ENOMEM),
"out of memory" },
95 { NV_ENC_ERR_ENCODER_NOT_INITIALIZED,
AVERROR(EINVAL),
"encoder not initialized" },
96 { NV_ENC_ERR_UNSUPPORTED_PARAM,
AVERROR(ENOSYS),
"unsupported param" },
97 { NV_ENC_ERR_LOCK_BUSY,
AVERROR(EAGAIN),
"lock busy" },
99 { NV_ENC_ERR_INVALID_VERSION,
AVERROR(EINVAL),
"invalid version" },
100 { NV_ENC_ERR_MAP_FAILED,
AVERROR(EIO),
"map failed" },
101 { NV_ENC_ERR_NEED_MORE_INPUT,
AVERROR(EAGAIN),
"need more input" },
102 { NV_ENC_ERR_ENCODER_BUSY,
AVERROR(EAGAIN),
"encoder busy" },
103 { NV_ENC_ERR_EVENT_NOT_REGISTERD,
AVERROR(EBADF),
"event not registered" },
105 { NV_ENC_ERR_INCOMPATIBLE_CLIENT_KEY,
AVERROR(EINVAL),
"incompatible client key" },
106 { NV_ENC_ERR_UNIMPLEMENTED,
AVERROR(ENOSYS),
"unimplemented" },
107 { NV_ENC_ERR_RESOURCE_REGISTER_FAILED,
AVERROR(EIO),
"resource register failed" },
108 { NV_ENC_ERR_RESOURCE_NOT_REGISTERED,
AVERROR(EBADF),
"resource not registered" },
109 { NV_ENC_ERR_RESOURCE_NOT_MAPPED,
AVERROR(EBADF),
"resource not mapped" },
123 *
desc =
"unknown error";
128 const char *error_string)
131 const char *details =
"(no details)";
134 #ifdef NVENC_HAVE_GETLASTERRORSTRING
136 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
138 if (p_nvenc &&
ctx->nvencoder)
139 details = p_nvenc->nvEncGetLastErrorString(
ctx->nvencoder);
152 #define PRESET_ALIAS(alias, name, ...) \
153 [PRESET_ ## alias] = { NV_ENC_PRESET_ ## name ## _GUID, __VA_ARGS__ }
155 #define PRESET(name, ...) PRESET_ALIAS(name, name, __VA_ARGS__)
160 #ifdef NVENC_HAVE_NEW_PRESETS
199 ctx->init_encode_params.presetGUID = t->
guid;
202 #ifdef NVENC_HAVE_NEW_PRESETS
203 if (
ctx->tuning_info == NV_ENC_TUNING_INFO_LOSSLESS)
213 #if NVENCAPI_CHECK_VERSION(11, 1)
214 const char *minver =
"(unknown)";
215 #elif NVENCAPI_CHECK_VERSION(11, 0)
216 # if defined(_WIN32) || defined(__CYGWIN__)
217 const char *minver =
"456.71";
219 const char *minver =
"455.28";
221 #elif NVENCAPI_CHECK_VERSION(10, 0)
222 # if defined(_WIN32) || defined(__CYGWIN__)
223 const char *minver =
"450.51";
225 const char *minver =
"445.87";
227 #elif NVENCAPI_CHECK_VERSION(9, 1)
228 # if defined(_WIN32) || defined(__CYGWIN__)
229 const char *minver =
"436.15";
231 const char *minver =
"435.21";
233 #elif NVENCAPI_CHECK_VERSION(9, 0)
234 # if defined(_WIN32) || defined(__CYGWIN__)
235 const char *minver =
"418.81";
237 const char *minver =
"418.30";
239 #elif NVENCAPI_CHECK_VERSION(8, 2)
240 # if defined(_WIN32) || defined(__CYGWIN__)
241 const char *minver =
"397.93";
243 const char *minver =
"396.24";
245 #elif NVENCAPI_CHECK_VERSION(8, 1)
246 # if defined(_WIN32) || defined(__CYGWIN__)
247 const char *minver =
"390.77";
249 const char *minver =
"390.25";
252 # if defined(_WIN32) || defined(__CYGWIN__)
253 const char *minver =
"378.66";
255 const char *minver =
"378.13";
258 av_log(avctx,
level,
"The minimum required Nvidia driver for nvenc is %s or newer\n", minver);
266 uint32_t nvenc_max_ver;
269 ret = cuda_load_functions(&dl_fn->
cuda_dl, avctx);
273 ret = nvenc_load_functions(&dl_fn->
nvenc_dl, avctx);
279 err = dl_fn->
nvenc_dl->NvEncodeAPIGetMaxSupportedVersion(&nvenc_max_ver);
280 if (err != NV_ENC_SUCCESS)
285 if ((NVENCAPI_MAJOR_VERSION << 4 | NVENCAPI_MINOR_VERSION) > nvenc_max_ver) {
286 av_log(avctx,
AV_LOG_ERROR,
"Driver does not support the required nvenc API version. "
287 "Required: %d.%d Found: %d.%d\n",
288 NVENCAPI_MAJOR_VERSION, NVENCAPI_MINOR_VERSION,
289 nvenc_max_ver >> 4, nvenc_max_ver & 0
xf);
294 dl_fn->
nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
297 if (err != NV_ENC_SUCCESS)
310 if (
ctx->d3d11_device)
322 if (
ctx->d3d11_device)
330 NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS params = { 0 };
332 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
335 params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
336 params.apiVersion = NVENCAPI_VERSION;
337 if (
ctx->d3d11_device) {
338 params.device =
ctx->d3d11_device;
339 params.deviceType = NV_ENC_DEVICE_TYPE_DIRECTX;
341 params.device =
ctx->cu_context;
342 params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
345 ret = p_nvenc->nvEncOpenEncodeSessionEx(¶ms, &
ctx->nvencoder);
346 if (
ret != NV_ENC_SUCCESS) {
357 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
358 int i,
ret, count = 0;
361 ret = p_nvenc->nvEncGetEncodeGUIDCount(
ctx->nvencoder, &count);
363 if (
ret != NV_ENC_SUCCESS || !count)
370 ret = p_nvenc->nvEncGetEncodeGUIDs(
ctx->nvencoder, guids, count, &count);
371 if (
ret != NV_ENC_SUCCESS) {
377 for (
i = 0;
i < count;
i++) {
378 if (!memcmp(&guids[
i], &
ctx->init_encode_params.encodeGUID,
sizeof(*guids))) {
393 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
394 NV_ENC_CAPS_PARAM params = { 0 };
397 params.version = NV_ENC_CAPS_PARAM_VER;
398 params.capsToQuery = cap;
400 ret = p_nvenc->nvEncGetEncodeCaps(
ctx->nvencoder,
ctx->init_encode_params.encodeGUID, ¶ms, &
val);
402 if (
ret == NV_ENC_SUCCESS)
431 if (ret < avctx->
width) {
438 if (ret < avctx->
height) {
445 if (ret < avctx->max_b_frames) {
455 "Interlaced encoding is not supported. Supported level: %d\n",
467 if (
ctx->rc_lookahead > 0 &&
ret <= 0) {
473 if (
ctx->temporal_aq > 0 &&
ret <= 0) {
479 if (
ctx->weighted_pred > 0 &&
ret <= 0) {
485 if (
ctx->coder == NV_ENC_H264_ENTROPY_CODING_MODE_CABAC &&
ret <= 0) {
490 #ifdef NVENC_HAVE_BFRAME_REF_MODE
492 if (
ctx->b_ref_mode == NV_ENC_BFRAME_REF_MODE_EACH &&
ret != 1 &&
ret != 3) {
495 }
else if (
ctx->b_ref_mode != NV_ENC_BFRAME_REF_MODE_DISABLED &&
ret == 0) {
500 if (
ctx->b_ref_mode != 0) {
506 #ifdef NVENC_HAVE_MULTIPLE_REF_FRAMES
508 if(avctx->
refs != NV_ENC_NUM_REF_FRAMES_AUTOSELECT &&
ret <= 0) {
513 if(avctx->
refs != 0) {
519 ctx->support_dyn_bitrate =
nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
528 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
529 char name[128] = { 0};
549 av_log(avctx, loglevel,
"[ GPU #%d - < %s > has Compute SM %d.%d ]\n", idx,
name,
major,
minor);
551 av_log(avctx, loglevel,
"does not support NVENC\n");
562 ctx->cu_context =
ctx->cu_context_internal;
574 av_log(avctx, loglevel,
"supports NVENC\n");
585 p_nvenc->nvEncDestroyEncoder(
ctx->nvencoder);
593 ctx->cu_context_internal =
NULL;
606 ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_H264_GUID;
609 ctx->init_encode_params.encodeGUID = NV_ENC_CODEC_HEVC_GUID;
618 av_log(avctx,
AV_LOG_WARNING,
"The selected preset is deprecated. Use p1 to p7 + -tune or fast/medium/slow.\n");
642 cuda_device_hwctx = hwdev_ctx->
hwctx;
645 d3d11_device_hwctx = hwdev_ctx->
hwctx;
653 if (cuda_device_hwctx) {
655 ctx->cu_stream = cuda_device_hwctx->
stream;
658 else if (d3d11_device_hwctx) {
659 ctx->d3d11_device = d3d11_device_hwctx->
device;
660 ID3D11Device_AddRef(
ctx->d3d11_device);
670 av_log(avctx,
AV_LOG_FATAL,
"Provided device doesn't support required NVENC features\n");
674 int i, nb_devices = 0;
690 for (
i = 0;
i < nb_devices; ++
i) {
703 av_log(avctx,
AV_LOG_FATAL,
"Requested GPU %d, but only %d GPUs are available!\n",
ctx->device, nb_devices);
713 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
715 rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
717 if (
ctx->init_qp_p >= 0) {
718 rc->constQP.qpInterP =
ctx->init_qp_p;
719 if (
ctx->init_qp_i >= 0 &&
ctx->init_qp_b >= 0) {
720 rc->constQP.qpIntra =
ctx->init_qp_i;
721 rc->constQP.qpInterB =
ctx->init_qp_b;
725 rc->constQP.qpInterB =
av_clip(
728 rc->constQP.qpIntra = rc->constQP.qpInterP;
729 rc->constQP.qpInterB = rc->constQP.qpInterP;
731 }
else if (
ctx->cqp >= 0) {
732 rc->constQP.qpInterP = rc->constQP.qpInterB = rc->constQP.qpIntra =
ctx->cqp;
746 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
749 if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
753 rc->minQP.qpInterB = avctx->
qmin;
754 rc->minQP.qpInterP = avctx->
qmin;
755 rc->minQP.qpIntra = avctx->
qmin;
757 rc->maxQP.qpInterB = avctx->
qmax;
758 rc->maxQP.qpInterP = avctx->
qmax;
759 rc->maxQP.qpIntra = avctx->
qmax;
761 qp_inter_p = (avctx->
qmax + 3 * avctx->
qmin) / 4;
762 }
else if (avctx->
qmin >= 0) {
765 rc->minQP.qpInterB = avctx->
qmin;
766 rc->minQP.qpInterP = avctx->
qmin;
767 rc->minQP.qpIntra = avctx->
qmin;
769 qp_inter_p = avctx->
qmin;
774 rc->enableInitialRCQP = 1;
776 if (
ctx->init_qp_p < 0) {
777 rc->initialRCQP.qpInterP = qp_inter_p;
779 rc->initialRCQP.qpInterP =
ctx->init_qp_p;
782 if (
ctx->init_qp_i < 0) {
784 rc->initialRCQP.qpIntra =
av_clip(
787 rc->initialRCQP.qpIntra = rc->initialRCQP.qpInterP;
790 rc->initialRCQP.qpIntra =
ctx->init_qp_i;
793 if (
ctx->init_qp_b < 0) {
795 rc->initialRCQP.qpInterB =
av_clip(
798 rc->initialRCQP.qpInterB = rc->initialRCQP.qpInterP;
801 rc->initialRCQP.qpInterB =
ctx->init_qp_b;
808 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
810 rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
811 rc->constQP.qpInterB = 0;
812 rc->constQP.qpInterP = 0;
813 rc->constQP.qpIntra = 0;
822 NV_ENC_RC_PARAMS *rc = &
ctx->encode_config.rcParams;
825 case NV_ENC_PARAMS_RC_CONSTQP:
828 case NV_ENC_PARAMS_RC_VBR_MINQP:
829 if (avctx->
qmin < 0) {
831 "The variable bitrate rate-control requires "
832 "the 'qmin' option set.\n");
837 case NV_ENC_PARAMS_RC_VBR_HQ:
838 case NV_ENC_PARAMS_RC_VBR:
841 case NV_ENC_PARAMS_RC_CBR:
842 case NV_ENC_PARAMS_RC_CBR_HQ:
843 case NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ:
847 rc->rateControlMode =
ctx->rc;
856 int nb_surfaces =
FFMAX(4,
ctx->encode_config.frameIntervalP * 2 * 2);
859 if (
ctx->rc_lookahead > 0) {
862 nb_surfaces =
FFMAX(1,
FFMAX(nb_surfaces,
ctx->rc_lookahead +
ctx->encode_config.frameIntervalP + 1 + 4));
863 if (nb_surfaces >
ctx->nb_surfaces &&
ctx->nb_surfaces > 0)
866 "Defined rc_lookahead requires more surfaces, "
867 "increasing used surfaces %d -> %d\n",
ctx->nb_surfaces, nb_surfaces);
869 ctx->nb_surfaces =
FFMAX(nb_surfaces,
ctx->nb_surfaces);
871 if (
ctx->encode_config.frameIntervalP > 1 &&
ctx->nb_surfaces < nb_surfaces &&
ctx->nb_surfaces > 0)
874 "Defined b-frame requires more surfaces, "
875 "increasing used surfaces %d -> %d\n",
ctx->nb_surfaces, nb_surfaces);
876 ctx->nb_surfaces =
FFMAX(
ctx->nb_surfaces, nb_surfaces);
878 else if (
ctx->nb_surfaces <= 0)
879 ctx->nb_surfaces = nb_surfaces;
894 av_log(avctx,
AV_LOG_WARNING,
"Using global_quality with nvenc is deprecated. Use qp instead.\n");
900 ctx->encode_config.rcParams.averageBitRate = avctx->
bit_rate;
901 }
else if (
ctx->encode_config.rcParams.averageBitRate > 0) {
902 ctx->encode_config.rcParams.maxBitRate =
ctx->encode_config.rcParams.averageBitRate;
908 #ifdef NVENC_HAVE_MULTIPASS
909 ctx->encode_config.rcParams.multiPass =
ctx->multipass;
912 ctx->encode_config.rcParams.multiPass = NV_ENC_MULTI_PASS_DISABLED;
914 ctx->encode_config.rcParams.multiPass = NV_ENC_TWO_PASS_FULL_RESOLUTION;
918 ctx->rc = NV_ENC_PARAMS_RC_CBR;
919 }
else if (
ctx->cqp >= 0) {
920 ctx->rc = NV_ENC_PARAMS_RC_CONSTQP;
921 }
else if (
ctx->quality >= 0.0f) {
922 ctx->rc = NV_ENC_PARAMS_RC_VBR;
932 if (
ctx->twopass < 0)
937 ctx->rc = NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ;
939 ctx->rc = NV_ENC_PARAMS_RC_CBR;
941 }
else if (
ctx->cqp >= 0) {
942 ctx->rc = NV_ENC_PARAMS_RC_CONSTQP;
943 }
else if (
ctx->twopass) {
944 ctx->rc = NV_ENC_PARAMS_RC_VBR_HQ;
945 }
else if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
946 ctx->rc = NV_ENC_PARAMS_RC_VBR_MINQP;
958 #ifdef NVENC_HAVE_LDKFS
960 ctx->encode_config.rcParams.lowDelayKeyFrameScale =
ctx->ldkfs;
965 }
else if (
ctx->rc >= 0) {
968 ctx->encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
974 }
else if (
ctx->encode_config.rcParams.averageBitRate > 0) {
975 avctx->
rc_buffer_size =
ctx->encode_config.rcParams.vbvBufferSize = 2 *
ctx->encode_config.rcParams.averageBitRate;
979 ctx->encode_config.rcParams.enableAQ = 1;
980 ctx->encode_config.rcParams.aqStrength =
ctx->aq_strength;
984 if (
ctx->temporal_aq) {
985 ctx->encode_config.rcParams.enableTemporalAQ = 1;
989 if (
ctx->rc_lookahead > 0) {
990 int lkd_bound =
FFMIN(
ctx->nb_surfaces,
ctx->async_depth) -
991 ctx->encode_config.frameIntervalP - 4;
995 "Lookahead not enabled. Increase buffer delay (-delay).\n");
997 ctx->encode_config.rcParams.enableLookahead = 1;
998 ctx->encode_config.rcParams.lookaheadDepth =
av_clip(
ctx->rc_lookahead, 0, lkd_bound);
999 ctx->encode_config.rcParams.disableIadapt =
ctx->no_scenecut;
1000 ctx->encode_config.rcParams.disableBadapt = !
ctx->b_adapt;
1002 "Lookahead enabled: depth %d, scenecut %s, B-adapt %s.\n",
1003 ctx->encode_config.rcParams.lookaheadDepth,
1004 ctx->encode_config.rcParams.disableIadapt ?
"disabled" :
"enabled",
1005 ctx->encode_config.rcParams.disableBadapt ?
"disabled" :
"enabled");
1009 if (
ctx->strict_gop) {
1010 ctx->encode_config.rcParams.strictGOPTarget = 1;
1015 ctx->encode_config.rcParams.enableNonRefP = 1;
1017 if (
ctx->zerolatency)
1018 ctx->encode_config.rcParams.zeroReorderDelay = 1;
1022 int tmp_quality = (
int)(
ctx->quality * 256.0f);
1023 ctx->encode_config.rcParams.targetQuality = (
uint8_t)(tmp_quality >> 8);
1024 ctx->encode_config.rcParams.targetQualityLSB = (
uint8_t)(tmp_quality & 0xff);
1029 ctx->encode_config.rcParams.averageBitRate = avctx->
bit_rate = 0;
1037 NV_ENC_CONFIG *cc = &
ctx->encode_config;
1038 NV_ENC_CONFIG_H264 *h264 = &cc->encodeCodecConfig.h264Config;
1039 NV_ENC_CONFIG_H264_VUI_PARAMETERS *vui = &h264->h264VUIParameters;
1043 vui->transferCharacteristics = avctx->
color_trc;
1047 vui->colourDescriptionPresentFlag =
1050 vui->videoSignalTypePresentFlag =
1051 (vui->colourDescriptionPresentFlag
1052 || vui->videoFormat != 5
1053 || vui->videoFullRangeFlag != 0);
1055 h264->sliceMode = 3;
1056 h264->sliceModeData = 1;
1060 h264->outputAUD =
ctx->aud;
1062 if (
ctx->dpb_size >= 0) {
1064 h264->maxNumRefFrames =
ctx->dpb_size;
1067 h264->idrPeriod = cc->gopLength;
1070 if (
IS_CBR(cc->rcParams.rateControlMode)) {
1071 h264->outputBufferingPeriodSEI = 1;
1074 h264->outputPictureTimingSEI = 1;
1076 if (cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ ||
1077 cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_CBR_HQ ||
1078 cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_VBR_HQ) {
1079 h264->adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
1080 h264->fmoMode = NV_ENC_H264_FMO_DISABLE;
1084 h264->qpPrimeYZeroTransformBypassFlag = 1;
1086 switch(
ctx->profile) {
1088 cc->profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
1092 cc->profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
1096 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
1100 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
1108 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
1114 h264->level =
ctx->level;
1116 if (
ctx->coder >= 0)
1117 h264->entropyCodingMode =
ctx->coder;
1119 #ifdef NVENC_HAVE_BFRAME_REF_MODE
1120 h264->useBFramesAsRef =
ctx->b_ref_mode;
1123 #ifdef NVENC_HAVE_MULTIPLE_REF_FRAMES
1124 h264->numRefL0 = avctx->
refs;
1125 h264->numRefL1 = avctx->
refs;
1134 NV_ENC_CONFIG *cc = &
ctx->encode_config;
1135 NV_ENC_CONFIG_HEVC *hevc = &cc->encodeCodecConfig.hevcConfig;
1136 NV_ENC_CONFIG_HEVC_VUI_PARAMETERS *vui = &hevc->hevcVUIParameters;
1140 vui->transferCharacteristics = avctx->
color_trc;
1144 vui->colourDescriptionPresentFlag =
1147 vui->videoSignalTypePresentFlag =
1148 (vui->colourDescriptionPresentFlag
1149 || vui->videoFormat != 5
1150 || vui->videoFullRangeFlag != 0);
1152 hevc->sliceMode = 3;
1153 hevc->sliceModeData = 1;
1157 hevc->outputAUD =
ctx->aud;
1159 if (
ctx->dpb_size >= 0) {
1161 hevc->maxNumRefFramesInDPB =
ctx->dpb_size;
1164 hevc->idrPeriod = cc->gopLength;
1167 if (
IS_CBR(cc->rcParams.rateControlMode)) {
1168 hevc->outputBufferingPeriodSEI = 1;
1171 hevc->outputPictureTimingSEI = 1;
1173 switch (
ctx->profile) {
1175 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
1179 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN10_GUID;
1183 cc->profileGUID = NV_ENC_HEVC_PROFILE_FREXT_GUID;
1190 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN10_GUID;
1196 cc->profileGUID = NV_ENC_HEVC_PROFILE_FREXT_GUID;
1200 hevc->chromaFormatIDC =
IS_YUV444(
ctx->data_pix_fmt) ? 3 : 1;
1202 hevc->pixelBitDepthMinus8 =
IS_10BIT(
ctx->data_pix_fmt) ? 2 : 0;
1204 hevc->level =
ctx->level;
1206 hevc->tier =
ctx->tier;
1208 #ifdef NVENC_HAVE_HEVC_BFRAME_REF_MODE
1209 hevc->useBFramesAsRef =
ctx->b_ref_mode;
1212 #ifdef NVENC_HAVE_MULTIPLE_REF_FRAMES
1213 hevc->numRefL0 = avctx->
refs;
1214 hevc->numRefL1 = avctx->
refs;
1251 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1253 NV_ENC_PRESET_CONFIG preset_config = { 0 };
1254 NVENCSTATUS nv_status = NV_ENC_SUCCESS;
1259 ctx->encode_config.version = NV_ENC_CONFIG_VER;
1260 ctx->init_encode_params.version = NV_ENC_INITIALIZE_PARAMS_VER;
1262 ctx->init_encode_params.encodeHeight = avctx->
height;
1263 ctx->init_encode_params.encodeWidth = avctx->
width;
1265 ctx->init_encode_params.encodeConfig = &
ctx->encode_config;
1267 preset_config.version = NV_ENC_PRESET_CONFIG_VER;
1268 preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
1270 #ifdef NVENC_HAVE_NEW_PRESETS
1271 ctx->init_encode_params.tuningInfo =
ctx->tuning_info;
1274 ctx->init_encode_params.tuningInfo = NV_ENC_TUNING_INFO_LOSSLESS;
1276 ctx->init_encode_params.tuningInfo = NV_ENC_TUNING_INFO_LOW_LATENCY;
1278 nv_status = p_nvenc->nvEncGetEncodePresetConfigEx(
ctx->nvencoder,
1279 ctx->init_encode_params.encodeGUID,
1280 ctx->init_encode_params.presetGUID,
1281 ctx->init_encode_params.tuningInfo,
1284 nv_status = p_nvenc->nvEncGetEncodePresetConfig(
ctx->nvencoder,
1285 ctx->init_encode_params.encodeGUID,
1286 ctx->init_encode_params.presetGUID,
1289 if (nv_status != NV_ENC_SUCCESS)
1290 return nvenc_print_error(avctx, nv_status,
"Cannot get the preset configuration");
1292 memcpy(&
ctx->encode_config, &preset_config.presetCfg,
sizeof(
ctx->encode_config));
1294 ctx->encode_config.version = NV_ENC_CONFIG_VER;
1297 ctx->init_encode_params.darHeight = dh;
1298 ctx->init_encode_params.darWidth = dw;
1308 ctx->init_encode_params.enableEncodeAsync = 0;
1309 ctx->init_encode_params.enablePTD = 1;
1311 #ifdef NVENC_HAVE_NEW_PRESETS
1315 if (
ctx->rc_lookahead == 0 &&
ctx->encode_config.rcParams.enableLookahead)
1316 ctx->rc_lookahead =
ctx->encode_config.rcParams.lookaheadDepth;
1319 if (
ctx->weighted_pred == 1)
1320 ctx->init_encode_params.enableWeightedPrediction = 1;
1322 if (
ctx->bluray_compat) {
1331 ctx->level = NV_ENC_LEVEL_HEVC_51;
1332 ctx->tier = NV_ENC_TIER_HEVC_HIGH;
1345 ctx->encode_config.frameIntervalP = 0;
1346 ctx->encode_config.gopLength = 1;
1354 ctx->encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD;
1356 ctx->encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;
1367 nv_status = p_nvenc->nvEncInitializeEncoder(
ctx->nvencoder, &
ctx->init_encode_params);
1368 if (nv_status != NV_ENC_SUCCESS) {
1373 #ifdef NVENC_HAVE_CUSTREAM_PTR
1374 if (
ctx->cu_context) {
1375 nv_status = p_nvenc->nvEncSetIOCudaStreams(
ctx->nvencoder, &
ctx->cu_stream, &
ctx->cu_stream);
1376 if (nv_status != NV_ENC_SUCCESS) {
1387 if (
ctx->encode_config.frameIntervalP > 1)
1390 if (
ctx->encode_config.rcParams.averageBitRate > 0)
1391 avctx->
bit_rate =
ctx->encode_config.rcParams.averageBitRate;
1398 cpb_props->
buffer_size =
ctx->encode_config.rcParams.vbvBufferSize;
1407 return NV_ENC_BUFFER_FORMAT_YV12_PL;
1409 return NV_ENC_BUFFER_FORMAT_NV12_PL;
1412 return NV_ENC_BUFFER_FORMAT_YUV420_10BIT;
1414 return NV_ENC_BUFFER_FORMAT_YUV444_PL;
1416 return NV_ENC_BUFFER_FORMAT_YUV444_10BIT;
1418 return NV_ENC_BUFFER_FORMAT_ARGB;
1420 return NV_ENC_BUFFER_FORMAT_ABGR;
1422 return NV_ENC_BUFFER_FORMAT_UNDEFINED;
1430 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1433 NVENCSTATUS nv_status;
1434 NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
1435 allocOut.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
1439 if (!
ctx->surfaces[idx].in_ref)
1442 NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
1445 if (
ctx->surfaces[idx].format == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
1451 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
1452 allocSurf.width = avctx->
width;
1453 allocSurf.height = avctx->
height;
1454 allocSurf.bufferFmt =
ctx->surfaces[idx].format;
1456 nv_status = p_nvenc->nvEncCreateInputBuffer(
ctx->nvencoder, &allocSurf);
1457 if (nv_status != NV_ENC_SUCCESS) {
1461 ctx->surfaces[idx].input_surface = allocSurf.inputBuffer;
1462 ctx->surfaces[idx].width = allocSurf.width;
1463 ctx->surfaces[idx].height = allocSurf.height;
1466 nv_status = p_nvenc->nvEncCreateBitstreamBuffer(
ctx->nvencoder, &allocOut);
1467 if (nv_status != NV_ENC_SUCCESS) {
1470 p_nvenc->nvEncDestroyInputBuffer(
ctx->nvencoder,
ctx->surfaces[idx].input_surface);
1475 ctx->surfaces[idx].output_surface = allocOut.bitstreamBuffer;
1485 int i, res = 0, res2;
1492 if (!
ctx->timestamp_list)
1496 if (!
ctx->unused_surface_queue)
1500 if (!
ctx->output_surface_queue)
1503 if (!
ctx->output_surface_ready_queue)
1510 for (
i = 0;
i <
ctx->nb_surfaces;
i++) {
1527 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1529 NVENCSTATUS nv_status;
1530 uint32_t outSize = 0;
1531 char tmpHeader[256];
1532 NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
1533 payload.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
1535 payload.spsppsBuffer = tmpHeader;
1536 payload.inBufferSize =
sizeof(tmpHeader);
1537 payload.outSPSPPSPayloadSize = &outSize;
1539 nv_status = p_nvenc->nvEncGetSequenceParams(
ctx->nvencoder, &payload);
1540 if (nv_status != NV_ENC_SUCCESS) {
1551 memcpy(avctx->
extradata, tmpHeader, outSize);
1560 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1564 if (
ctx->nvencoder) {
1565 NV_ENC_PIC_PARAMS params = { .version = NV_ENC_PIC_PARAMS_VER,
1566 .encodePicFlags = NV_ENC_PIC_FLAG_EOS };
1572 p_nvenc->nvEncEncodePicture(
ctx->nvencoder, ¶ms);
1581 for (
i = 0;
i <
ctx->nb_registered_frames;
i++) {
1582 if (
ctx->registered_frames[
i].mapped)
1583 p_nvenc->nvEncUnmapInputResource(
ctx->nvencoder,
ctx->registered_frames[
i].in_map.mappedResource);
1584 if (
ctx->registered_frames[
i].regptr)
1585 p_nvenc->nvEncUnregisterResource(
ctx->nvencoder,
ctx->registered_frames[
i].regptr);
1587 ctx->nb_registered_frames = 0;
1590 if (
ctx->surfaces) {
1591 for (
i = 0;
i <
ctx->nb_surfaces; ++
i) {
1593 p_nvenc->nvEncDestroyInputBuffer(
ctx->nvencoder,
ctx->surfaces[
i].input_surface);
1595 p_nvenc->nvEncDestroyBitstreamBuffer(
ctx->nvencoder,
ctx->surfaces[
i].output_surface);
1599 ctx->nb_surfaces = 0;
1603 if (
ctx->nvencoder) {
1604 p_nvenc->nvEncDestroyEncoder(
ctx->nvencoder);
1612 if (
ctx->cu_context_internal)
1614 ctx->cu_context =
ctx->cu_context_internal =
NULL;
1617 if (
ctx->d3d11_device) {
1618 ID3D11Device_Release(
ctx->d3d11_device);
1623 nvenc_free_functions(&dl_fn->
nvenc_dl);
1624 cuda_free_functions(&dl_fn->
cuda_dl);
1642 "hw_frames_ctx must be set when using GPU frames as input\n");
1648 "hw_frames_ctx must match the GPU frame type\n");
1693 NV_ENC_LOCK_INPUT_BUFFER *lock_buffer_params,
const AVFrame *
frame)
1695 int dst_linesize[4] = {
1696 lock_buffer_params->pitch,
1697 lock_buffer_params->pitch,
1698 lock_buffer_params->pitch,
1699 lock_buffer_params->pitch
1705 dst_linesize[1] = dst_linesize[2] >>= 1;
1708 lock_buffer_params->bufferDataPtr, dst_linesize);
1726 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1727 NVENCSTATUS nv_status;
1732 for (first_round = 1; first_round >= 0; first_round--) {
1733 for (
i = 0;
i <
ctx->nb_registered_frames;
i++) {
1734 if (!
ctx->registered_frames[
i].mapped) {
1735 if (
ctx->registered_frames[
i].regptr) {
1738 nv_status = p_nvenc->nvEncUnregisterResource(
ctx->nvencoder,
ctx->registered_frames[
i].regptr);
1739 if (nv_status != NV_ENC_SUCCESS)
1740 return nvenc_print_error(avctx, nv_status,
"Failed unregistering unused input resource");
1741 ctx->registered_frames[
i].ptr =
NULL;
1742 ctx->registered_frames[
i].regptr =
NULL;
1749 return ctx->nb_registered_frames++;
1760 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1763 NV_ENC_REGISTER_RESOURCE reg = { 0 };
1766 for (
i = 0;
i <
ctx->nb_registered_frames;
i++) {
1777 reg.version = NV_ENC_REGISTER_RESOURCE_VER;
1778 reg.width = frames_ctx->width;
1779 reg.height = frames_ctx->height;
1780 reg.pitch =
frame->linesize[0];
1781 reg.resourceToRegister =
frame->data[0];
1784 reg.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR;
1787 reg.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_DIRECTX;
1788 reg.subResourceIndex = (intptr_t)
frame->data[1];
1792 if (reg.bufferFormat == NV_ENC_BUFFER_FORMAT_UNDEFINED) {
1798 ret = p_nvenc->nvEncRegisterResource(
ctx->nvencoder, ®);
1799 if (
ret != NV_ENC_SUCCESS) {
1804 ctx->registered_frames[idx].ptr =
frame->data[0];
1805 ctx->registered_frames[idx].ptr_index = reg.subResourceIndex;
1806 ctx->registered_frames[idx].regptr = reg.registeredResource;
1815 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1818 NVENCSTATUS nv_status;
1831 if (!
ctx->registered_frames[reg_idx].mapped) {
1832 ctx->registered_frames[reg_idx].in_map.version = NV_ENC_MAP_INPUT_RESOURCE_VER;
1833 ctx->registered_frames[reg_idx].in_map.registeredResource =
ctx->registered_frames[reg_idx].regptr;
1834 nv_status = p_nvenc->nvEncMapInputResource(
ctx->nvencoder, &
ctx->registered_frames[reg_idx].in_map);
1835 if (nv_status != NV_ENC_SUCCESS) {
1841 ctx->registered_frames[reg_idx].mapped += 1;
1843 nvenc_frame->
reg_idx = reg_idx;
1844 nvenc_frame->
input_surface =
ctx->registered_frames[reg_idx].in_map.mappedResource;
1845 nvenc_frame->
format =
ctx->registered_frames[reg_idx].in_map.mappedBufferFmt;
1850 NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
1852 lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
1855 nv_status = p_nvenc->nvEncLockInputBuffer(
ctx->nvencoder, &lockBufferParams);
1856 if (nv_status != NV_ENC_SUCCESS) {
1857 return nvenc_print_error(avctx, nv_status,
"Failed locking nvenc input buffer");
1860 nvenc_frame->
pitch = lockBufferParams.pitch;
1863 nv_status = p_nvenc->nvEncUnlockInputBuffer(
ctx->nvencoder, nvenc_frame->
input_surface);
1864 if (nv_status != NV_ENC_SUCCESS) {
1873 NV_ENC_PIC_PARAMS *params,
1874 NV_ENC_SEI_PAYLOAD *sei_data,
1881 params->codecPicParams.h264PicParams.sliceMode =
1882 ctx->encode_config.encodeCodecConfig.h264Config.sliceMode;
1883 params->codecPicParams.h264PicParams.sliceModeData =
1884 ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData;
1885 if (sei_count > 0) {
1886 params->codecPicParams.h264PicParams.seiPayloadArray = sei_data;
1887 params->codecPicParams.h264PicParams.seiPayloadArrayCnt = sei_count;
1892 params->codecPicParams.hevcPicParams.sliceMode =
1893 ctx->encode_config.encodeCodecConfig.hevcConfig.sliceMode;
1894 params->codecPicParams.hevcPicParams.sliceModeData =
1895 ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1896 if (sei_count > 0) {
1897 params->codecPicParams.hevcPicParams.seiPayloadArray = sei_data;
1898 params->codecPicParams.hevcPicParams.seiPayloadArrayCnt = sei_count;
1920 NV_ENC_LOCK_BITSTREAM *params,
1925 pkt->
pts = params->outputTimeStamp;
1937 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1939 uint32_t slice_mode_data;
1940 uint32_t *slice_offsets =
NULL;
1941 NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
1942 NVENCSTATUS nv_status;
1949 slice_mode_data =
ctx->encode_config.encodeCodecConfig.h264Config.sliceModeData;
1952 slice_mode_data =
ctx->encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1959 slice_offsets =
av_mallocz(slice_mode_data *
sizeof(*slice_offsets));
1961 if (!slice_offsets) {
1966 lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
1968 lock_params.doNotWait = 0;
1970 lock_params.sliceOffsets = slice_offsets;
1972 nv_status = p_nvenc->nvEncLockBitstream(
ctx->nvencoder, &lock_params);
1973 if (nv_status != NV_ENC_SUCCESS) {
1985 memcpy(
pkt->
data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
1987 nv_status = p_nvenc->nvEncUnlockBitstream(
ctx->nvencoder, tmpoutsurf->
output_surface);
1988 if (nv_status != NV_ENC_SUCCESS) {
1989 res =
nvenc_print_error(avctx, nv_status,
"Failed unlocking bitstream buffer, expect the gates of mordor to open");
1995 ctx->registered_frames[tmpoutsurf->
reg_idx].mapped -= 1;
1996 if (
ctx->registered_frames[tmpoutsurf->
reg_idx].mapped == 0) {
1997 nv_status = p_nvenc->nvEncUnmapInputResource(
ctx->nvencoder,
ctx->registered_frames[tmpoutsurf->
reg_idx].in_map.mappedResource);
1998 if (nv_status != NV_ENC_SUCCESS) {
2002 }
else if (
ctx->registered_frames[tmpoutsurf->
reg_idx].mapped < 0) {
2012 switch (lock_params.pictureType) {
2013 case NV_ENC_PIC_TYPE_IDR:
2015 case NV_ENC_PIC_TYPE_I:
2018 case NV_ENC_PIC_TYPE_P:
2021 case NV_ENC_PIC_TYPE_B:
2024 case NV_ENC_PIC_TYPE_BI:
2028 av_log(avctx,
AV_LOG_ERROR,
"Unknown picture type encountered, expect the output to be broken.\n");
2029 av_log(avctx,
AV_LOG_ERROR,
"Please report this error and include as much information on how to reproduce it as possible.\n");
2034 #if FF_API_CODED_FRAME
2063 int nb_ready, nb_pending;
2068 return nb_ready > 0;
2069 return (nb_ready > 0) && (nb_ready + nb_pending >=
ctx->async_depth);
2075 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &
ctx->nvenc_dload_funcs.nvenc_funcs;
2078 NV_ENC_RECONFIGURE_PARAMS params = { 0 };
2079 int needs_reconfig = 0;
2080 int needs_encode_config = 0;
2081 int reconfig_bitrate = 0, reconfig_dar = 0;
2084 params.version = NV_ENC_RECONFIGURE_PARAMS_VER;
2085 params.reInitEncodeParams =
ctx->init_encode_params;
2088 if (dw !=
ctx->init_encode_params.darWidth || dh !=
ctx->init_encode_params.darHeight) {
2090 "aspect ratio change (DAR): %d:%d -> %d:%d\n",
2091 ctx->init_encode_params.darWidth,
2092 ctx->init_encode_params.darHeight, dw, dh);
2094 params.reInitEncodeParams.darHeight = dh;
2095 params.reInitEncodeParams.darWidth = dw;
2101 if (
ctx->rc != NV_ENC_PARAMS_RC_CONSTQP &&
ctx->support_dyn_bitrate) {
2102 if (avctx->
bit_rate > 0 && params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate != avctx->
bit_rate) {
2104 "avg bitrate change: %d -> %d\n",
2105 params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate,
2108 params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate = avctx->
bit_rate;
2109 reconfig_bitrate = 1;
2114 "max bitrate change: %d -> %d\n",
2115 params.reInitEncodeParams.encodeConfig->rcParams.maxBitRate,
2118 params.reInitEncodeParams.encodeConfig->rcParams.maxBitRate = avctx->
rc_max_rate;
2119 reconfig_bitrate = 1;
2124 "vbv buffer size change: %d -> %d\n",
2125 params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize,
2128 params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize = avctx->
rc_buffer_size;
2129 reconfig_bitrate = 1;
2132 if (reconfig_bitrate) {
2133 params.resetEncoder = 1;
2134 params.forceIDR = 1;
2136 needs_encode_config = 1;
2141 if (!needs_encode_config)
2142 params.reInitEncodeParams.encodeConfig =
NULL;
2144 if (needs_reconfig) {
2145 ret = p_nvenc->nvEncReconfigureEncoder(
ctx->nvencoder, ¶ms);
2146 if (
ret != NV_ENC_SUCCESS) {
2150 ctx->init_encode_params.darHeight = dh;
2151 ctx->init_encode_params.darWidth = dw;
2154 if (reconfig_bitrate) {
2155 ctx->encode_config.rcParams.averageBitRate = params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate;
2156 ctx->encode_config.rcParams.maxBitRate = params.reInitEncodeParams.encodeConfig->rcParams.maxBitRate;
2157 ctx->encode_config.rcParams.vbvBufferSize = params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize;
2166 NVENCSTATUS nv_status;
2169 NV_ENC_SEI_PAYLOAD sei_data[8];
2175 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
2177 NV_ENC_PIC_PARAMS pic_params = { 0 };
2178 pic_params.version = NV_ENC_PIC_PARAMS_VER;
2180 if ((!
ctx->cu_context && !
ctx->d3d11_device) || !
ctx->nvencoder)
2204 pic_params.bufferFmt = in_surf->
format;
2205 pic_params.inputWidth = in_surf->
width;
2206 pic_params.inputHeight = in_surf->
height;
2207 pic_params.inputPitch = in_surf->
pitch;
2211 if (
frame->top_field_first)
2212 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM;
2214 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP;
2216 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
2220 pic_params.encodePicFlags =
2221 ctx->forced_idr ? NV_ENC_PIC_FLAG_FORCEIDR : NV_ENC_PIC_FLAG_FORCEINTRA;
2223 pic_params.encodePicFlags = 0;
2226 pic_params.inputTimeStamp =
frame->pts;
2229 void *a53_data =
NULL;
2230 size_t a53_size = 0;
2237 sei_data[sei_count].payloadSize = (uint32_t)a53_size;
2238 sei_data[sei_count].payloadType = 4;
2239 sei_data[sei_count].payload = (
uint8_t*)a53_data;
2245 void *tc_data =
NULL;
2253 sei_data[sei_count].payloadSize = (uint32_t)tc_size;
2255 sei_data[sei_count].payload = (
uint8_t*)tc_data;
2262 pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
2269 nv_status = p_nvenc->nvEncEncodePicture(
ctx->nvencoder, &pic_params);
2271 for (
i = 0;
i < sei_count;
i++)
2278 if (nv_status != NV_ENC_SUCCESS &&
2279 nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
2288 if (nv_status == NV_ENC_SUCCESS) {
2307 if ((!
ctx->cu_context && !
ctx->d3d11_device) || !
ctx->nvencoder)
2310 if (!
frame->buf[0]) {