27 #define CUDA_LIBNAME TEXT("nvcuda.dll")
29 #define NVENC_LIBNAME TEXT("nvEncodeAPI64.dll")
31 #define NVENC_LIBNAME TEXT("nvEncodeAPI.dll")
34 #define dlopen(filename, flags) LoadLibrary((filename))
35 #define dlsym(handle, symbol) GetProcAddress(handle, symbol)
36 #define dlclose(handle) FreeLibrary(handle)
40 #define CUDA_LIBNAME "libcuda.so"
41 #define NVENC_LIBNAME "libnvidia-encode.so"
51 #define NVENC_CAP 0x30
52 #define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
53 rc == NV_ENC_PARAMS_RC_2_PASS_QUALITY || \
54 rc == NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP)
56 #define LOAD_LIBRARY(l, path) \
58 if (!((l) = dlopen(path, RTLD_LAZY))) { \
59 av_log(avctx, AV_LOG_ERROR, \
62 return AVERROR_UNKNOWN; \
66 #define LOAD_SYMBOL(fun, lib, symbol) \
68 if (!((fun) = dlsym(lib, symbol))) { \
69 av_log(avctx, AV_LOG_ERROR, \
72 return AVERROR_UNKNOWN; \
91 { NV_ENC_SUCCESS, 0,
"success" },
92 { NV_ENC_ERR_NO_ENCODE_DEVICE,
AVERROR(ENOENT),
"no encode device" },
93 { NV_ENC_ERR_UNSUPPORTED_DEVICE,
AVERROR(ENOSYS),
"unsupported device" },
94 { NV_ENC_ERR_INVALID_ENCODERDEVICE,
AVERROR(EINVAL),
"invalid encoder device" },
95 { NV_ENC_ERR_INVALID_DEVICE,
AVERROR(EINVAL),
"invalid device" },
96 { NV_ENC_ERR_DEVICE_NOT_EXIST,
AVERROR(EIO),
"device does not exist" },
97 { NV_ENC_ERR_INVALID_PTR,
AVERROR(EFAULT),
"invalid ptr" },
98 { NV_ENC_ERR_INVALID_EVENT,
AVERROR(EINVAL),
"invalid event" },
99 { NV_ENC_ERR_INVALID_PARAM,
AVERROR(EINVAL),
"invalid param" },
100 { NV_ENC_ERR_INVALID_CALL,
AVERROR(EINVAL),
"invalid call" },
101 { NV_ENC_ERR_OUT_OF_MEMORY,
AVERROR(ENOMEM),
"out of memory" },
102 { NV_ENC_ERR_ENCODER_NOT_INITIALIZED,
AVERROR(EINVAL),
"encoder not initialized" },
103 { NV_ENC_ERR_UNSUPPORTED_PARAM,
AVERROR(ENOSYS),
"unsupported param" },
104 { NV_ENC_ERR_LOCK_BUSY,
AVERROR(EAGAIN),
"lock busy" },
105 { NV_ENC_ERR_NOT_ENOUGH_BUFFER,
AVERROR(ENOBUFS),
"not enough buffer" },
106 { NV_ENC_ERR_INVALID_VERSION,
AVERROR(EINVAL),
"invalid version" },
107 { NV_ENC_ERR_MAP_FAILED,
AVERROR(EIO),
"map failed" },
108 { NV_ENC_ERR_NEED_MORE_INPUT,
AVERROR(EAGAIN),
"need more input" },
109 { NV_ENC_ERR_ENCODER_BUSY,
AVERROR(EAGAIN),
"encoder busy" },
110 { NV_ENC_ERR_EVENT_NOT_REGISTERD,
AVERROR(EBADF),
"event not registered" },
112 { NV_ENC_ERR_INCOMPATIBLE_CLIENT_KEY,
AVERROR(EINVAL),
"incompatible client key" },
113 { NV_ENC_ERR_UNIMPLEMENTED,
AVERROR(ENOSYS),
"unimplemented" },
114 { NV_ENC_ERR_RESOURCE_REGISTER_FAILED,
AVERROR(EIO),
"resource register failed" },
115 { NV_ENC_ERR_RESOURCE_NOT_REGISTERED,
AVERROR(EBADF),
"resource not registered" },
116 { NV_ENC_ERR_RESOURCE_NOT_MAPPED,
AVERROR(EBADF),
"resource not mapped" },
130 *desc =
"unknown error";
135 const char *error_string)
168 "cuDeviceComputeCapability");
177 "NvEncodeAPICreateInstance");
179 dl_fn->
nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
182 if (err != NV_ENC_SUCCESS)
192 NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS
params = { 0 };
197 params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
198 params.apiVersion = NVENCAPI_VERSION;
200 params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
202 ret = p_nvenc->nvEncOpenEncodeSessionEx(¶ms, &ctx->
nvencoder);
203 if (ret != NV_ENC_SUCCESS) {
215 int i, ret,
count = 0;
218 ret = p_nvenc->nvEncGetEncodeGUIDCount(ctx->
nvencoder, &count);
220 if (ret != NV_ENC_SUCCESS || !count)
227 ret = p_nvenc->nvEncGetEncodeGUIDs(ctx->
nvencoder, guids, count, &count);
228 if (ret != NV_ENC_SUCCESS) {
234 for (i = 0; i <
count; i++) {
251 NV_ENC_CAPS_PARAM
params = { 0 };
254 params.version = NV_ENC_CAPS_PARAM_VER;
255 params.capsToQuery = cap;
259 if (ret == NV_ENC_SUCCESS)
288 if (ret < avctx->
width) {
295 if (ret < avctx->
height) {
302 if (ret < avctx->max_b_frames) {
312 "Interlaced encoding is not supported. Supported level: %d\n",
324 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
325 char name[128] = { 0};
326 int major, minor, ret;
338 "Cannot access the CUDA device %d\n",
351 av_log(avctx, loglevel,
"[ GPU #%d - < %s > has Compute SM %d.%d ]\n", idx, name, major, minor);
352 if (((major << 4) | minor) <
NVENC_CAP) {
353 av_log(avctx, loglevel,
"does not support NVENC\n");
359 av_log(avctx,
AV_LOG_FATAL,
"Failed creating CUDA context for NVENC: 0x%x\n", (
int)cu_res);
377 av_log(avctx, loglevel,
"supports NVENC\n");
385 p_nvenc->nvEncDestroyEncoder(ctx->
nvencoder);
432 av_log(avctx,
AV_LOG_FATAL,
"Provided device doesn't support required NVENC features\n");
439 int i, nb_devices = 0;
443 "Cannot init CUDA\n");
449 "Cannot enumerate the CUDA devices\n");
461 for (i = 0; i < nb_devices; ++i) {
489 { NV_ENC_PRESET_DEFAULT_GUID },
493 { NV_ENC_PRESET_HP_GUID },
494 { NV_ENC_PRESET_HQ_GUID },
495 { NV_ENC_PRESET_BD_GUID },
514 rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
529 if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
533 rc->minQP.qpInterB = avctx->
qmin;
534 rc->minQP.qpInterP = avctx->
qmin;
535 rc->minQP.qpIntra = avctx->
qmin;
537 rc->maxQP.qpInterB = avctx->
qmax;
538 rc->maxQP.qpInterP = avctx->
qmax;
539 rc->maxQP.qpIntra = avctx->
qmax;
541 qp_inter_p = (avctx->
qmax + 3 * avctx->
qmin) / 4;
542 }
else if (avctx->
qmin >= 0) {
545 rc->minQP.qpInterB = avctx->
qmin;
546 rc->minQP.qpInterP = avctx->
qmin;
547 rc->minQP.qpIntra = avctx->
qmin;
549 qp_inter_p = avctx->
qmin;
554 rc->enableInitialRCQP = 1;
555 rc->initialRCQP.qpInterP = qp_inter_p;
558 rc->initialRCQP.qpIntra = av_clip(
560 rc->initialRCQP.qpInterB = av_clip(
563 rc->initialRCQP.qpIntra = qp_inter_p;
564 rc->initialRCQP.qpInterB = qp_inter_p;
573 rc->rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
574 rc->constQP.qpInterB = 0;
575 rc->constQP.qpInterP = 0;
576 rc->constQP.qpIntra = 0;
588 case NV_ENC_PARAMS_RC_CONSTQP:
591 "The constant quality rate-control requires "
592 "the 'global_quality' option set.\n");
597 case NV_ENC_PARAMS_RC_2_PASS_VBR:
598 case NV_ENC_PARAMS_RC_VBR:
599 if (avctx->
qmin < 0 && avctx->
qmax < 0) {
601 "The variable bitrate rate-control requires "
602 "the 'qmin' and/or 'qmax' option set.\n");
606 case NV_ENC_PARAMS_RC_VBR_MINQP:
607 if (avctx->
qmin < 0) {
609 "The variable bitrate rate-control requires "
610 "the 'qmin' option set.\n");
616 case NV_ENC_PARAMS_RC_CBR:
617 case NV_ENC_PARAMS_RC_2_PASS_QUALITY:
618 case NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP:
622 rc->rateControlMode = ctx->
rc;
649 ctx->
rc = NV_ENC_PARAMS_RC_2_PASS_QUALITY;
651 ctx->
rc = NV_ENC_PARAMS_RC_CBR;
654 ctx->
rc = NV_ENC_PARAMS_RC_CONSTQP;
656 ctx->
rc = NV_ENC_PARAMS_RC_2_PASS_VBR;
657 }
else if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
658 ctx->
rc = NV_ENC_PARAMS_RC_VBR_MINQP;
664 }
else if (ctx->
rc >= 0) {
667 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
682 NV_ENC_CONFIG_H264 *h264 = &cc->encodeCodecConfig.h264Config;
683 NV_ENC_CONFIG_H264_VUI_PARAMETERS *vui = &h264->h264VUIParameters;
687 vui->transferCharacteristics = avctx->
color_trc;
691 vui->colourDescriptionPresentFlag =
694 vui->videoSignalTypePresentFlag =
695 (vui->colourDescriptionPresentFlag
696 || vui->videoFormat != 5
697 || vui->videoFullRangeFlag != 0);
700 h264->sliceModeData = 1;
706 if (avctx->
refs >= 0) {
708 h264->maxNumRefFrames = avctx->
refs;
711 h264->idrPeriod = cc->gopLength;
714 if (
IS_CBR(cc->rcParams.rateControlMode)) {
715 h264->outputBufferingPeriodSEI = 1;
716 h264->outputPictureTimingSEI = 1;
719 if (cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_2_PASS_QUALITY ||
720 cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP ||
721 cc->rcParams.rateControlMode == NV_ENC_PARAMS_RC_2_PASS_VBR) {
722 h264->adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
723 h264->fmoMode = NV_ENC_H264_FMO_DISABLE;
727 h264->qpPrimeYZeroTransformBypassFlag = 1;
731 cc->profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
735 cc->profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
739 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
743 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
751 cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
757 h264->level = ctx->
level;
766 NV_ENC_CONFIG_HEVC *hevc = &cc->encodeCodecConfig.hevcConfig;
767 NV_ENC_CONFIG_HEVC_VUI_PARAMETERS *vui = &hevc->hevcVUIParameters;
771 vui->transferCharacteristics = avctx->
color_trc;
775 vui->colourDescriptionPresentFlag =
778 vui->videoSignalTypePresentFlag =
779 (vui->colourDescriptionPresentFlag
780 || vui->videoFormat != 5
781 || vui->videoFullRangeFlag != 0);
784 hevc->sliceModeData = 1;
790 if (avctx->
refs >= 0) {
792 hevc->maxNumRefFramesInDPB = avctx->
refs;
795 hevc->idrPeriod = cc->gopLength;
798 if (
IS_CBR(cc->rcParams.rateControlMode)) {
799 hevc->outputBufferingPeriodSEI = 1;
800 hevc->outputPictureTimingSEI = 1;
804 cc->profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
807 hevc->level = ctx->
level;
809 hevc->tier = ctx->
tier;
831 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
833 NV_ENC_PRESET_CONFIG preset_config = { 0 };
834 NVENCSTATUS nv_status = NV_ENC_SUCCESS;
849 preset_config.version = NV_ENC_PRESET_CONFIG_VER;
850 preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
852 nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->
nvencoder,
856 if (nv_status != NV_ENC_SUCCESS)
857 return nvenc_print_error(avctx, nv_status,
"Cannot get the preset configuration");
878 if (avctx->
width == 720 &&
912 ctx->
encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD;
914 ctx->
encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;
922 if (nv_status != NV_ENC_SUCCESS) {
946 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
948 NVENCSTATUS nv_status;
949 NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
950 allocOut.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
975 NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
976 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
977 allocSurf.width = (avctx->
width + 31) & ~31;
978 allocSurf.height = (avctx->
height + 31) & ~31;
979 allocSurf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
982 nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->
nvencoder, &allocSurf);
983 if (nv_status != NV_ENC_SUCCESS) {
996 allocOut.size = 1024 * 1024;
998 allocOut.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
1000 nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->
nvencoder, &allocOut);
1001 if (nv_status != NV_ENC_SUCCESS) {
1019 int num_mbs = ((avctx->
width + 15) >> 4) * ((avctx->
height + 15) >> 4);
1051 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1053 NVENCSTATUS nv_status;
1054 uint32_t outSize = 0;
1055 char tmpHeader[256];
1056 NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
1057 payload.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
1059 payload.spsppsBuffer = tmpHeader;
1060 payload.inBufferSize =
sizeof(tmpHeader);
1061 payload.outSPSPPSPayloadSize = &outSize;
1063 nv_status = p_nvenc->nvEncGetSequenceParams(ctx->
nvencoder, &payload);
1064 if (nv_status != NV_ENC_SUCCESS) {
1075 memcpy(avctx->
extradata, tmpHeader, outSize);
1084 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1089 NV_ENC_PIC_PARAMS
params = { .version = NV_ENC_PIC_PARAMS_VER,
1090 .encodePicFlags = NV_ENC_PIC_FLAG_EOS };
1092 p_nvenc->nvEncEncodePicture(ctx->
nvencoder, ¶ms);
1124 p_nvenc->nvEncDestroyEncoder(ctx->
nvencoder);
1132 dlclose(dl_fn->
nvenc);
1139 dlclose(dl_fn->
cuda);
1166 "hw_frames_ctx must be set when using GPU frames as input\n");
1210 NV_ENC_LOCK_INPUT_BUFFER *lockBufferParams,
const AVFrame *
frame)
1212 uint8_t *
buf = lockBufferParams->bufferDataPtr;
1213 int off = inSurf->
height * lockBufferParams->pitch;
1269 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1277 p_nvenc->nvEncUnregisterResource(ctx->
nvencoder,
1296 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1299 NV_ENC_REGISTER_RESOURCE reg;
1311 reg.version = NV_ENC_REGISTER_RESOURCE_VER;
1312 reg.resourceType = NV_ENC_INPUT_RESOURCE_TYPE_CUDADEVICEPTR;
1313 reg.width = frames_ctx->
width;
1314 reg.height = frames_ctx->
height;
1317 reg.resourceToRegister = frame->
data[0];
1319 ret = p_nvenc->nvEncRegisterResource(ctx->
nvencoder, ®);
1320 if (ret != NV_ENC_SUCCESS) {
1335 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1338 NVENCSTATUS nv_status;
1351 nvenc_frame->
in_map.version = NV_ENC_MAP_INPUT_RESOURCE_VER;
1353 nv_status = p_nvenc->nvEncMapInputResource(ctx->
nvencoder, &nvenc_frame->
in_map);
1354 if (nv_status != NV_ENC_SUCCESS) {
1360 nvenc_frame->
reg_idx = reg_idx;
1364 NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
1366 lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
1369 nv_status = p_nvenc->nvEncLockInputBuffer(ctx->
nvencoder, &lockBufferParams);
1370 if (nv_status != NV_ENC_SUCCESS) {
1371 return nvenc_print_error(avctx, nv_status,
"Failed locking nvenc input buffer");
1377 if (nv_status != NV_ENC_SUCCESS) {
1386 NV_ENC_PIC_PARAMS *
params)
1392 params->codecPicParams.h264PicParams.sliceMode =
1394 params->codecPicParams.h264PicParams.sliceModeData =
1395 ctx->
encode_config.encodeCodecConfig.h264Config.sliceModeData;
1398 params->codecPicParams.hevcPicParams.sliceMode =
1400 params->codecPicParams.hevcPicParams.sliceModeData =
1401 ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1421 NV_ENC_LOCK_BITSTREAM *
params,
1426 pkt->
pts = params->outputTimeStamp;
1435 if ((ts0 < 0 && ts1 > INT64_MAX + ts0) ||
1436 (ts0 > 0 && ts1 < INT64_MIN + ts0))
1440 if ((delta < 0 && ts0 > INT64_MAX + delta) ||
1441 (delta > 0 && ts0 < INT64_MIN + delta))
1458 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1460 uint32_t slice_mode_data;
1461 uint32_t *slice_offsets;
1462 NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
1463 NVENCSTATUS nv_status;
1470 slice_mode_data = ctx->
encode_config.encodeCodecConfig.h264Config.sliceModeData;
1473 slice_mode_data = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1480 slice_offsets =
av_mallocz(slice_mode_data *
sizeof(*slice_offsets));
1485 lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
1487 lock_params.doNotWait = 0;
1489 lock_params.sliceOffsets = slice_offsets;
1491 nv_status = p_nvenc->nvEncLockBitstream(ctx->
nvencoder, &lock_params);
1492 if (nv_status != NV_ENC_SUCCESS) {
1497 if (res =
ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes,0)) {
1502 memcpy(pkt->
data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
1505 if (nv_status != NV_ENC_SUCCESS)
1506 nvenc_print_error(avctx, nv_status,
"Failed unlocking bitstream buffer, expect the gates of mordor to open");
1510 p_nvenc->nvEncUnmapInputResource(ctx->
nvencoder, tmpoutsurf->
in_map.mappedResource);
1517 switch (lock_params.pictureType) {
1518 case NV_ENC_PIC_TYPE_IDR:
1520 case NV_ENC_PIC_TYPE_I:
1523 case NV_ENC_PIC_TYPE_P:
1526 case NV_ENC_PIC_TYPE_B:
1529 case NV_ENC_PIC_TYPE_BI:
1533 av_log(avctx,
AV_LOG_ERROR,
"Unknown picture type encountered, expect the output to be broken.\n");
1534 av_log(avctx,
AV_LOG_ERROR,
"Please report this error and include as much information on how to reproduce it as possible.\n");
1539 #if FF_API_CODED_FRAME
1568 int nb_ready, nb_pending;
1579 return nb_ready > 0;
1580 return (nb_ready > 0) && (nb_ready + nb_pending >= ctx->
async_depth);
1586 NVENCSTATUS nv_status;
1592 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1594 NV_ENC_PIC_PARAMS pic_params = { 0 };
1595 pic_params.version = NV_ENC_PIC_PARAMS_VER;
1611 pic_params.bufferFmt = inSurf->
format;
1612 pic_params.inputWidth = avctx->
width;
1613 pic_params.inputHeight = avctx->
height;
1618 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM;
1620 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP;
1622 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
1625 pic_params.encodePicFlags = 0;
1626 pic_params.inputTimeStamp = frame->
pts;
1630 pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
1633 nv_status = p_nvenc->nvEncEncodePicture(ctx->
nvencoder, &pic_params);
1634 if (nv_status != NV_ENC_SUCCESS &&
1635 nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
1649 if (nv_status == NV_ENC_SUCCESS) {
#define FF_PROFILE_H264_MAIN
const struct AVCodec * codec
const char const char void * val
av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
NV_ENC_BUFFER_FORMAT format
This structure describes decoded (raw) audio or video data.
static av_cold int nvenc_setup_codec_config(AVCodecContext *avctx)
AVFifoBuffer * timestamp_list
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
static void flush(AVCodecContext *avctx)
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static av_cold void set_vbr(AVCodecContext *avctx)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
memory handling functions
static av_cold int nvenc_setup_device(AVCodecContext *avctx)
int max_bitrate
Maximum bitrate of the stream, in bits per second.
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
NV_ENC_MAP_INPUT_RESOURCE in_map
enum AVColorRange color_range
MPEG vs JPEG YUV range.
PCUCTXDESTROY cu_ctx_destroy
static av_cold int nvenc_setup_surfaces(AVCodecContext *avctx)
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
NvencDynLoadFunctions nvenc_dload_funcs
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
int width
The allocated dimensions of the frames in this pool.
PCUDEVICEGETNAME cu_device_get_name
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
float i_quant_offset
qscale offset between P and I-frames
static void nvenc_override_rate_control(AVCodecContext *avctx)
static NvencSurface * get_free_frame(NvencContext *ctx)
static av_cold void nvenc_setup_rate_control(AVCodecContext *avctx)
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
NV_ENC_INPUT_PTR input_surface
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define FF_PROFILE_H264_BASELINE
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
PCUDEVICEGETCOUNT cu_device_get_count
enum AVPixelFormat ff_nvenc_pix_fmts[]
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
#define FF_PROFILE_HEVC_MAIN
PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define LOAD_LIBRARY(l, path)
NV_ENC_INITIALIZE_PARAMS init_encode_params
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
static av_cold int nvenc_alloc_surface(AVCodecContext *avctx, int idx)
static av_cold int nvenc_setup_extradata(AVCodecContext *avctx)
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_LOG_VERBOSE
Detailed information.
static int nvenc_check_capabilities(AVCodecContext *avctx)
static int nvenc_register_frame(AVCodecContext *avctx, const AVFrame *frame)
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
AVFifoBuffer * output_surface_ready_queue
CUcontext cu_context_internal
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static av_cold int nvenc_open_session(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
static void timestamp_queue_enqueue(AVFifoBuffer *queue, int64_t timestamp)
NVENCSTATUS(NVENCAPI * PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList)
#define LOAD_SYMBOL(fun, lib, symbol)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int qmax
maximum quantizer
PCUDEVICEGET cu_device_get
static int nvenc_map_error(NVENCSTATUS err, const char **desc)
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
#define FF_PROFILE_H264_HIGH
int flags
AV_CODEC_FLAG_*.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
simple assert() macros that are a bit more flexible than ISO C assert().
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
static av_cold void set_constqp(AVCodecContext *avctx)
int flags
A combination of AV_PKT_FLAG values.
int rc_buffer_size
decoder bitstream buffer size
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static int nvenc_check_codec_support(AVCodecContext *avctx)
int refs
number of reference frames
enum AVPictureType pict_type
Picture type of the frame.
static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame, NvencSurface *nvenc_frame)
NV_ENC_REGISTERED_PTR regptr
static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
av_cold int ff_nvenc_encode_init(AVCodecContext *avctx)
static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencSurface *tmpoutsurf)
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
int width
picture width / height.
AVBufferRef * hw_frames_ctx
Encoding only.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
AVFifoBuffer * output_surface_queue
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
HW acceleration through CUDA.
static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
#define FF_ARRAY_ELEMS(a)
the normal 2^n-1 "JPEG" YUV ranges
static int nvenc_print_error(void *log_ctx, NVENCSTATUS err, const char *error_string)
enum AVPixelFormat data_pix_fmt
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
This structure describes the bitrate properties of an encoded bitstream.
PCUCTXCREATE cu_ctx_create
#define AV_LOG_INFO
Standard information.
NV_ENC_CONFIG encode_config
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
uint8_t * data
The data buffer.
int qmin
minimum quantizer
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
This struct is allocated as AVHWDeviceContext.hwctx.
static int nvenc_check_cap(AVCodecContext *avctx, NV_ENC_CAPS cap)
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
struct NvencContext::@85 registered_frames[MAX_REGISTERED_FRAMES]
This struct describes a set or pool of "hardware" frames (i.e.
static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, NV_ENC_PIC_PARAMS *params)
float b_quant_offset
qscale offset between IP and B-frames
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static int nvenc_find_free_reg_resource(AVCodecContext *avctx)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static int64_t timestamp_queue_dequeue(AVFifoBuffer *queue)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
PCUCTXPOPCURRENT cu_ctx_pop_current
static int output_ready(AVCodecContext *avctx, int flush)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int nvenc_set_timestamp(AVCodecContext *avctx, NV_ENC_LOCK_BITSTREAM *params, AVPacket *pkt)
#define FF_ENABLE_DEPRECATION_WARNINGS
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int top_field_first
If the content is interlaced, is top field displayed first.
static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
static av_cold int nvenc_check_device(AVCodecContext *avctx, int idx)
int avg_bitrate
Average bitrate of the stream, in bits per second.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static void * av_mallocz_array(size_t nmemb, size_t size)
static av_cold void set_lossless(AVCodecContext *avctx)
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
static const struct @80 nvenc_errors[]
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *inSurf, NV_ENC_LOCK_INPUT_BUFFER *lockBufferParams, const AVFrame *frame)
NV_ENC_OUTPUT_PTR output_surface
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void nvenc_map_preset(NvencContext *ctx)
int64_t rc_max_rate
maximum bitrate