28 #include <nvEncodeAPI.h>
40 #define CUDAAPI __stdcall
46 #define LOAD_FUNC(l, s) GetProcAddress(l, s)
47 #define DL_CLOSE_FUNC(l) FreeLibrary(l)
49 #define LOAD_FUNC(l, s) dlsym(l, s)
50 #define DL_CLOSE_FUNC(l) dlclose(l)
53 typedef enum cudaError_enum {
170 {
"auto", NV_ENC_LEVEL_AUTOSELECT },
171 {
"1" , NV_ENC_LEVEL_H264_1 },
172 {
"1.0" , NV_ENC_LEVEL_H264_1 },
173 {
"1b" , NV_ENC_LEVEL_H264_1b },
174 {
"1.0b", NV_ENC_LEVEL_H264_1b },
175 {
"1.1" , NV_ENC_LEVEL_H264_11 },
176 {
"1.2" , NV_ENC_LEVEL_H264_12 },
177 {
"1.3" , NV_ENC_LEVEL_H264_13 },
178 {
"2" , NV_ENC_LEVEL_H264_2 },
179 {
"2.0" , NV_ENC_LEVEL_H264_2 },
180 {
"2.1" , NV_ENC_LEVEL_H264_21 },
181 {
"2.2" , NV_ENC_LEVEL_H264_22 },
182 {
"3" , NV_ENC_LEVEL_H264_3 },
183 {
"3.0" , NV_ENC_LEVEL_H264_3 },
184 {
"3.1" , NV_ENC_LEVEL_H264_31 },
185 {
"3.2" , NV_ENC_LEVEL_H264_32 },
186 {
"4" , NV_ENC_LEVEL_H264_4 },
187 {
"4.0" , NV_ENC_LEVEL_H264_4 },
188 {
"4.1" , NV_ENC_LEVEL_H264_41 },
189 {
"4.2" , NV_ENC_LEVEL_H264_42 },
190 {
"5" , NV_ENC_LEVEL_H264_5 },
191 {
"5.0" , NV_ENC_LEVEL_H264_5 },
192 {
"5.1" , NV_ENC_LEVEL_H264_51 },
197 {
"auto", NV_ENC_LEVEL_AUTOSELECT },
198 {
"1" , NV_ENC_LEVEL_HEVC_1 },
199 {
"1.0" , NV_ENC_LEVEL_HEVC_1 },
200 {
"2" , NV_ENC_LEVEL_HEVC_2 },
201 {
"2.0" , NV_ENC_LEVEL_HEVC_2 },
202 {
"2.1" , NV_ENC_LEVEL_HEVC_21 },
203 {
"3" , NV_ENC_LEVEL_HEVC_3 },
204 {
"3.0" , NV_ENC_LEVEL_HEVC_3 },
205 {
"3.1" , NV_ENC_LEVEL_HEVC_31 },
206 {
"4" , NV_ENC_LEVEL_HEVC_4 },
207 {
"4.0" , NV_ENC_LEVEL_HEVC_4 },
208 {
"4.1" , NV_ENC_LEVEL_HEVC_41 },
209 {
"5" , NV_ENC_LEVEL_HEVC_5 },
210 {
"5.0" , NV_ENC_LEVEL_HEVC_5 },
211 {
"5.1" , NV_ENC_LEVEL_HEVC_51 },
212 {
"5.2" , NV_ENC_LEVEL_HEVC_52 },
213 {
"6" , NV_ENC_LEVEL_HEVC_6 },
214 {
"6.0" , NV_ENC_LEVEL_HEVC_6 },
215 {
"6.1" , NV_ENC_LEVEL_HEVC_61 },
216 {
"6.2" , NV_ENC_LEVEL_HEVC_62 },
222 for (; pair->
str; ++pair) {
223 if (!strcmp(input, pair->
str)) {
245 mask = queue->
size - 1;
246 read_pos = (queue->
pos - queue->
count) & mask;
249 return &queue->
data[read_pos];
288 mask = queue->
size - 1;
291 queue->
pos = (queue->
pos + 1) & mask;
333 #define CHECK_LOAD_FUNC(t, f, s) \
335 (f) = (t)LOAD_FUNC(dl_fn->cuda_lib, s); \
337 av_log(avctx, AV_LOG_FATAL, "Failed loading %s from CUDA library\n", s); \
353 dl_fn->
cuda_lib = dlopen(
"libcuda.so", RTLD_LAZY);
390 #define check_cuda_errors(f) if (!check_cuda_errors(avctx, f, #f)) goto error
394 int device_count = 0;
397 int smminor = 0, smmajor = 0;
398 int i, smver, target_smver;
434 for (i = 0; i < device_count; ++i) {
439 smver = (smmajor << 4) | smminor;
441 av_log(avctx,
AV_LOG_VERBOSE,
"[ GPU #%d - < %s > has Compute SM %d.%d, NVENC %s ]\n", i, gpu_name, smmajor, smminor, (smver >= target_smver) ?
"Available" :
"Not Available");
443 if (smver >= target_smver)
464 NVENCSTATUS nvstatus;
476 if (
sizeof(
void*) == 8) {
482 dl_fn->
nvenc_lib = dlopen(
"libnvidia-encode.so.1", RTLD_LAZY);
492 if (!nvEncodeAPICreateInstance) {
497 dl_fn->
nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
499 nvstatus = nvEncodeAPICreateInstance(&dl_fn->
nvenc_funcs);
501 if (nvstatus != NV_ENC_SUCCESS) {
546 NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS encode_session_params = { 0 };
547 NV_ENC_PRESET_CONFIG preset_config = { 0 };
550 GUID encoder_preset = NV_ENC_PRESET_HQ_GUID;
552 NVENCSTATUS nv_status = NV_ENC_SUCCESS;
553 int surfaceCount = 0;
562 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
571 preset_config.version = NV_ENC_PRESET_CONFIG_VER;
572 preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
573 encode_session_params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
574 encode_session_params.apiVersion = NVENCAPI_VERSION;
586 av_log(avctx,
AV_LOG_FATAL,
"Failed creating CUDA context for NVENC: 0x%x\n", (
int)cu_res);
599 encode_session_params.device = ctx->
cu_context;
600 encode_session_params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
602 nv_status = p_nvenc->nvEncOpenEncodeSessionEx(&encode_session_params, &ctx->
nvencoder);
603 if (nv_status != NV_ENC_SUCCESS) {
605 av_log(avctx,
AV_LOG_FATAL,
"OpenEncodeSessionEx failed: 0x%x - invalid license key?\n", (
int)nv_status);
611 if (!strcmp(ctx->
preset,
"hp")) {
612 encoder_preset = NV_ENC_PRESET_HP_GUID;
613 }
else if (!strcmp(ctx->
preset,
"hq")) {
614 encoder_preset = NV_ENC_PRESET_HQ_GUID;
615 }
else if (!strcmp(ctx->
preset,
"bd")) {
616 encoder_preset = NV_ENC_PRESET_BD_GUID;
617 }
else if (!strcmp(ctx->
preset,
"ll")) {
618 encoder_preset = NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID;
620 }
else if (!strcmp(ctx->
preset,
"llhp")) {
621 encoder_preset = NV_ENC_PRESET_LOW_LATENCY_HP_GUID;
623 }
else if (!strcmp(ctx->
preset,
"llhq")) {
624 encoder_preset = NV_ENC_PRESET_LOW_LATENCY_HQ_GUID;
626 }
else if (!strcmp(ctx->
preset,
"lossless")) {
627 encoder_preset = NV_ENC_PRESET_LOSSLESS_DEFAULT_GUID;
629 }
else if (!strcmp(ctx->
preset,
"losslesshp")) {
630 encoder_preset = NV_ENC_PRESET_LOSSLESS_HP_GUID;
632 }
else if (!strcmp(ctx->
preset,
"default")) {
633 encoder_preset = NV_ENC_PRESET_DEFAULT_GUID;
635 av_log(avctx,
AV_LOG_FATAL,
"Preset \"%s\" is unknown! Supported presets: hp, hq, bd, ll, llhp, llhq, lossless, losslesshp, default\n", ctx->
preset);
643 codec = NV_ENC_CODEC_H264_GUID;
646 codec = NV_ENC_CODEC_HEVC_GUID;
654 nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->
nvencoder, codec, encoder_preset, &preset_config);
655 if (nv_status != NV_ENC_SUCCESS) {
680 if (avctx->
width == 720 &&
693 num_mbs = ((avctx->
width + 15) >> 4) * ((avctx->
height + 15) >> 4);
708 if (avctx->
refs >= 0) {
715 ctx->
encode_config.encodeCodecConfig.hevcConfig.maxNumRefFramesInDPB = avctx->
refs;
742 ctx->
encode_config.encodeCodecConfig.h264Config.idrPeriod = 1;
745 ctx->
encode_config.encodeCodecConfig.hevcConfig.idrPeriod = 1;
763 ctx->
encode_config.encodeCodecConfig.h264Config.qpPrimeYZeroTransformBypassFlag = 1;
765 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
772 }
else if (ctx->
cbr) {
774 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
775 }
else if (ctx->
twopass == 1 || isLL) {
776 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_QUALITY;
779 ctx->
encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
780 ctx->
encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE;
783 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
786 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
793 }
else if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
795 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_VBR;
798 ctx->
encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
799 ctx->
encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE;
802 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
821 ctx->
encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD;
823 ctx->
encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;
828 ctx->
encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1;
829 ctx->
encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1;
833 ctx->
encode_config.encodeCodecConfig.h264Config.h264VUIParameters.transferCharacteristics = avctx->
color_trc;
843 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
846 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
849 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
853 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
857 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
861 if (!strcmp(ctx->
profile,
"high")) {
862 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
864 }
else if (!strcmp(ctx->
profile,
"main")) {
865 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
867 }
else if (!strcmp(ctx->
profile,
"baseline")) {
868 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
870 }
else if (!strcmp(ctx->
profile,
"high444p")) {
871 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
886 av_log(avctx,
AV_LOG_FATAL,
"Level \"%s\" is unknown! Supported levels: auto, 1, 1b, 1.1, 1.2, 1.3, 2, 2.1, 2.2, 3, 3.1, 3.2, 4, 4.1, 4.2, 5, 5.1\n", ctx->
level);
890 ctx->
encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_AUTOSELECT;
899 ctx->
encode_config.profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
906 av_log(avctx,
AV_LOG_FATAL,
"Level \"%s\" is unknown! Supported levels: auto, 1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 5.2, 6, 6.1, 6.2\n", ctx->
level);
910 ctx->
encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_AUTOSELECT;
914 if (!strcmp(ctx->
tier,
"main")) {
915 ctx->
encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_MAIN;
916 }
else if (!strcmp(ctx->
tier,
"high")) {
917 ctx->
encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_HIGH;
930 if (nv_status != NV_ENC_SUCCESS) {
951 NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
952 NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
953 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
954 allocOut.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
956 allocSurf.width = (avctx->
width + 31) & ~31;
957 allocSurf.height = (avctx->
height + 31) & ~31;
959 allocSurf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
963 allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_YV12_PL;
967 allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_NV12_PL;
971 allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_YUV444_PL;
980 nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->
nvencoder, &allocSurf);
981 if (nv_status != NV_ENC_SUCCESS) {
994 allocOut.size = 1024 * 1024;
996 allocOut.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
998 nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->
nvencoder, &allocOut);
999 if (nv_status != NV_ENC_SUCCESS) {
1012 uint32_t outSize = 0;
1013 char tmpHeader[256];
1014 NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
1015 payload.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
1017 payload.spsppsBuffer = tmpHeader;
1018 payload.inBufferSize =
sizeof(tmpHeader);
1019 payload.outSPSPPSPayloadSize = &outSize;
1021 nv_status = p_nvenc->nvEncGetSequenceParams(ctx->
nvencoder, &payload);
1022 if (nv_status != NV_ENC_SUCCESS) {
1035 memcpy(avctx->
extradata, tmpHeader, outSize);
1048 for (i = 0; i < surfaceCount; ++i) {
1055 p_nvenc->nvEncDestroyEncoder(ctx->
nvencoder);
1072 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1085 p_nvenc->nvEncDestroyEncoder(ctx->
nvencoder);
1100 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1102 uint32_t slice_mode_data;
1103 uint32_t *slice_offsets;
1104 NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
1105 NVENCSTATUS nv_status;
1110 slice_mode_data = ctx->
encode_config.encodeCodecConfig.h264Config.sliceModeData;
1113 slice_mode_data = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1120 slice_offsets =
av_mallocz(slice_mode_data *
sizeof(*slice_offsets));
1125 lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
1127 lock_params.doNotWait = 0;
1129 lock_params.sliceOffsets = slice_offsets;
1131 nv_status = p_nvenc->nvEncLockBitstream(ctx->
nvencoder, &lock_params);
1132 if (nv_status != NV_ENC_SUCCESS) {
1138 if (res =
ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes, 0)) {
1143 memcpy(pkt->
data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
1146 if (nv_status != NV_ENC_SUCCESS)
1147 av_log(avctx,
AV_LOG_ERROR,
"Failed unlocking bitstream buffer, expect the gates of mordor to open\n");
1149 switch (lock_params.pictureType) {
1150 case NV_ENC_PIC_TYPE_IDR:
1152 #if FF_API_CODED_FRAME
1154 case NV_ENC_PIC_TYPE_I:
1157 case NV_ENC_PIC_TYPE_P:
1160 case NV_ENC_PIC_TYPE_B:
1163 case NV_ENC_PIC_TYPE_BI:
1167 av_log(avctx,
AV_LOG_ERROR,
"Unknown picture type encountered, expect the output to be broken.\n");
1168 av_log(avctx,
AV_LOG_ERROR,
"Please report this error and include as much information on how to reproduce it as possible.\n");
1175 pkt->
pts = lock_params.outputTimeStamp;
1205 NVENCSTATUS nv_status;
1211 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1213 NV_ENC_PIC_PARAMS pic_params = { 0 };
1214 pic_params.version = NV_ENC_PIC_PARAMS_VER;
1217 NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
1231 lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
1234 nv_status = p_nvenc->nvEncLockInputBuffer(ctx->
nvencoder, &lockBufferParams);
1235 if (nv_status != NV_ENC_SUCCESS) {
1241 uint8_t *
buf = lockBufferParams.bufferDataPtr;
1247 buf += inSurf->
height * lockBufferParams.pitch;
1253 buf += (inSurf->
height * lockBufferParams.pitch) >> 2;
1259 uint8_t *
buf = lockBufferParams.bufferDataPtr;
1265 buf += inSurf->
height * lockBufferParams.pitch;
1271 uint8_t *
buf = lockBufferParams.bufferDataPtr;
1277 buf += inSurf->
height * lockBufferParams.pitch;
1283 buf += inSurf->
height * lockBufferParams.pitch;
1294 if (nv_status != NV_ENC_SUCCESS) {
1312 pic_params.bufferFmt = inSurf->
format;
1313 pic_params.inputWidth = avctx->
width;
1314 pic_params.inputHeight = avctx->
height;
1316 pic_params.completionEvent = 0;
1320 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM;
1322 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP;
1325 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
1328 pic_params.encodePicFlags = 0;
1329 pic_params.inputTimeStamp = frame->
pts;
1330 pic_params.inputDuration = 0;
1333 pic_params.codecPicParams.h264PicParams.sliceMode = ctx->
encode_config.encodeCodecConfig.h264Config.sliceMode;
1334 pic_params.codecPicParams.h264PicParams.sliceModeData = ctx->
encode_config.encodeCodecConfig.h264Config.sliceModeData;
1337 pic_params.codecPicParams.hevcPicParams.sliceMode = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceMode;
1338 pic_params.codecPicParams.hevcPicParams.sliceModeData = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1350 pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
1353 nv_status = p_nvenc->nvEncEncodePicture(ctx->
nvencoder, &pic_params);
1355 if (frame && nv_status == NV_ENC_ERR_NEED_MORE_INPUT) {
1364 if (nv_status != NV_ENC_SUCCESS && nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
1369 if (nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
1396 tmpoutsurf->
busy = 0;
1415 #define OFFSET(x) offsetof(NvencContext, x)
1416 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1418 {
"preset",
"Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)",
OFFSET(
preset),
AV_OPT_TYPE_STRING, { .str =
"hq" }, 0, 0,
VE },
1420 {
"level",
"Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)",
OFFSET(
level),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
VE },
1424 {
"gpu",
"Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.",
OFFSET(gpu),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
VE },
1425 {
"delay",
"Delays frame output by the given amount of frames.",
OFFSET(buffer_delay),
AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX,
VE },
1439 #if CONFIG_NVENC_ENCODER
1440 static const AVClass nvenc_class = {
1457 .priv_class = &nvenc_class,
1464 #if CONFIG_NVENC_H264_ENCODER
1465 static const AVClass nvenc_h264_class = {
1472 AVCodec ff_nvenc_h264_encoder = {
1473 .
name =
"nvenc_h264",
1482 .priv_class = &nvenc_h264_class,
1488 #if CONFIG_NVENC_HEVC_ENCODER
1489 static const AVClass nvenc_hevc_class = {
1496 AVCodec ff_nvenc_hevc_encoder = {
1497 .
name =
"nvenc_hevc",
1506 .priv_class = &nvenc_hevc_class,
const struct AVCodec * codec
static av_cold int nvenc_check_cuda(AVCodecContext *avctx)
NvencOutputSurface * surface
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
NvencDataList output_surface_queue
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
NvencInputSurface * input_surfaces
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
memory handling functions
static av_cold int init(AVCodecContext *avctx)
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...
NVENCSTATUS(NVENCAPI * PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
PCUCTXDESTROY cu_ctx_destroy
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...
PCUDEVICEGETNAME cu_device_get_name
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
CUresult(CUDAAPI * PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev)
static const AVOption options[]
NvencDataList timestamp_list
#define FF_PROFILE_H264_MAIN
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
CUresult(CUDAAPI * PCUDEVICEGET)(CUdevice *device, int ordinal)
#define CHECK_LOAD_FUNC(t, f, s)
PCUDEVICEGETCOUNT cu_device_get_count
Multithreading support functions.
PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability
#define FF_PROFILE_UNKNOWN
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.
NV_ENC_INITIALIZE_PARAMS init_encode_params
#define AV_LOG_VERBOSE
Detailed information.
#define check_cuda_errors(f)
NvencOutputSurface * output_surfaces
static av_cold int nvenc_encode_close(AVCodecContext *avctx)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
NvencDataList output_surface_ready_queue
static int input_string_to_uint32(AVCodecContext *avctx, const NvencValuePair *pair, const char *input, uint32_t *output)
#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 const uint16_t mask[17]
int qmax
maximum quantizer
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
PCUDEVICEGET cu_device_get
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...
int rc_max_rate
maximum bitrate
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Libavcodec external API header.
int flags
A combination of AV_PKT_FLAG values.
int rc_buffer_size
decoder bitstream buffer size
static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencOutputSurface *tmpoutsurf)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
common internal API header
int refs
number of reference frames
int bit_rate
the average bitrate
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static const NvencValuePair nvenc_h264_level_pairs[]
CUresult(CUDAAPI * PCUDEVICEGETCOUNT)(int *count)
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static int out_surf_queue_enqueue(NvencDataList *queue, NvencOutputSurface *surface)
CUresult(CUDAAPI * PCUDEVICEGETNAME)(char *name, int len, CUdevice dev)
the normal 2^n-1 "JPEG" YUV ranges
static av_cold int nvenc_encode_init(AVCodecContext *avctx)
static NvencOutputSurface * out_surf_queue_dequeue(NvencDataList *queue)
PCUCTXCREATE cu_ctx_create
NV_ENC_CONFIG encode_config
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static av_cold void nvenc_unload_nvenc(AVCodecContext *avctx)
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
main external API structure.
int qmin
minimum quantizer
static int timestamp_queue_enqueue(NvencDataList *queue, int64_t timestamp)
static av_cold int nvenc_dyload_cuda(AVCodecContext *avctx)
Describe the class of an AVClass context structure.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static const NvencValuePair nvenc_hevc_level_pairs[]
int(* func)(AVBPrint *dst, const char *in, const char *arg)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static int64_t timestamp_queue_dequeue(NvencDataList *queue)
static enum AVPixelFormat pix_fmts[]
int global_quality
Global quality for codecs which cannot change it per frame.
static av_cold int nvenc_dyload_nvenc(AVCodecContext *avctx)
static const AVCodecDefault nvenc_defaults[]
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
#define FF_PROFILE_H264_HIGH
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
CUresult(CUDAAPI * PCUCTXDESTROY)(CUcontext ctx)
PCUCTXPOPCURRENT cu_ctx_pop_current
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
CUdevice nvenc_devices[16]
static enum AVPixelFormat pix_fmts_nvenc[]
#define FF_PROFILE_HEVC_MAIN
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
CUresult(CUDAAPI * PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev)
CUresult(CUDAAPI * PCUINIT)(unsigned int Flags)
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first.
#define FF_PROFILE_H264_BASELINE
NvencInputSurface * input_surface
static int nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
NV_ENC_OUTPUT_PTR output_surface
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
static NvencData * data_queue_dequeue(NvencDataList *queue)
static const AVCodecDefault defaults[]
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.
#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 ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
CUresult(CUDAAPI * PCUCTXPOPCURRENT)(CUcontext *pctx)
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int data_queue_enqueue(NvencDataList *queue, NvencData *data)