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 {
169 {
"auto", NV_ENC_LEVEL_AUTOSELECT },
170 {
"1" , NV_ENC_LEVEL_H264_1 },
171 {
"1.0" , NV_ENC_LEVEL_H264_1 },
172 {
"1b" , NV_ENC_LEVEL_H264_1b },
173 {
"1.0b", NV_ENC_LEVEL_H264_1b },
174 {
"1.1" , NV_ENC_LEVEL_H264_11 },
175 {
"1.2" , NV_ENC_LEVEL_H264_12 },
176 {
"1.3" , NV_ENC_LEVEL_H264_13 },
177 {
"2" , NV_ENC_LEVEL_H264_2 },
178 {
"2.0" , NV_ENC_LEVEL_H264_2 },
179 {
"2.1" , NV_ENC_LEVEL_H264_21 },
180 {
"2.2" , NV_ENC_LEVEL_H264_22 },
181 {
"3" , NV_ENC_LEVEL_H264_3 },
182 {
"3.0" , NV_ENC_LEVEL_H264_3 },
183 {
"3.1" , NV_ENC_LEVEL_H264_31 },
184 {
"3.2" , NV_ENC_LEVEL_H264_32 },
185 {
"4" , NV_ENC_LEVEL_H264_4 },
186 {
"4.0" , NV_ENC_LEVEL_H264_4 },
187 {
"4.1" , NV_ENC_LEVEL_H264_41 },
188 {
"4.2" , NV_ENC_LEVEL_H264_42 },
189 {
"5" , NV_ENC_LEVEL_H264_5 },
190 {
"5.0" , NV_ENC_LEVEL_H264_5 },
191 {
"5.1" , NV_ENC_LEVEL_H264_51 },
196 {
"auto", NV_ENC_LEVEL_AUTOSELECT },
197 {
"1" , NV_ENC_LEVEL_HEVC_1 },
198 {
"1.0" , NV_ENC_LEVEL_HEVC_1 },
199 {
"2" , NV_ENC_LEVEL_HEVC_2 },
200 {
"2.0" , NV_ENC_LEVEL_HEVC_2 },
201 {
"2.1" , NV_ENC_LEVEL_HEVC_21 },
202 {
"3" , NV_ENC_LEVEL_HEVC_3 },
203 {
"3.0" , NV_ENC_LEVEL_HEVC_3 },
204 {
"3.1" , NV_ENC_LEVEL_HEVC_31 },
205 {
"4" , NV_ENC_LEVEL_HEVC_4 },
206 {
"4.0" , NV_ENC_LEVEL_HEVC_4 },
207 {
"4.1" , NV_ENC_LEVEL_HEVC_41 },
208 {
"5" , NV_ENC_LEVEL_HEVC_5 },
209 {
"5.0" , NV_ENC_LEVEL_HEVC_5 },
210 {
"5.1" , NV_ENC_LEVEL_HEVC_51 },
211 {
"5.2" , NV_ENC_LEVEL_HEVC_52 },
212 {
"6" , NV_ENC_LEVEL_HEVC_6 },
213 {
"6.0" , NV_ENC_LEVEL_HEVC_6 },
214 {
"6.1" , NV_ENC_LEVEL_HEVC_61 },
215 {
"6.2" , NV_ENC_LEVEL_HEVC_62 },
221 for (; pair->
str; ++pair) {
222 if (!strcmp(input, pair->
str)) {
244 mask = queue->
size - 1;
245 read_pos = (queue->
pos - queue->
count) & mask;
248 return &queue->
data[read_pos];
287 mask = queue->
size - 1;
290 queue->
pos = (queue->
pos + 1) & mask;
332 #define CHECK_LOAD_FUNC(t, f, s) \
334 (f) = (t)LOAD_FUNC(dl_fn->cuda_lib, s); \
336 av_log(avctx, AV_LOG_FATAL, "Failed loading %s from CUDA library\n", s); \
352 dl_fn->
cuda_lib = dlopen(
"libcuda.so", RTLD_LAZY);
389 #define check_cuda_errors(f) if (!check_cuda_errors(avctx, f, #f)) goto error
393 int device_count = 0;
396 int smminor = 0, smmajor = 0;
397 int i, smver, target_smver;
433 for (i = 0; i < device_count; ++i) {
438 smver = (smmajor << 4) | smminor;
440 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");
442 if (smver >= target_smver)
463 NVENCSTATUS nvstatus;
475 if (
sizeof(
void*) == 8) {
481 dl_fn->
nvenc_lib = dlopen(
"libnvidia-encode.so.1", RTLD_LAZY);
491 if (!nvEncodeAPICreateInstance) {
496 dl_fn->
nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
498 nvstatus = nvEncodeAPICreateInstance(&dl_fn->
nvenc_funcs);
500 if (nvstatus != NV_ENC_SUCCESS) {
545 NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS encode_session_params = { 0 };
546 NV_ENC_PRESET_CONFIG preset_config = { 0 };
549 GUID encoder_preset = NV_ENC_PRESET_HQ_GUID;
551 NVENCSTATUS nv_status = NV_ENC_SUCCESS;
552 int surfaceCount = 0;
560 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
575 preset_config.version = NV_ENC_PRESET_CONFIG_VER;
576 preset_config.presetCfg.version = NV_ENC_CONFIG_VER;
577 encode_session_params.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER;
578 encode_session_params.apiVersion = NVENCAPI_VERSION;
590 av_log(avctx,
AV_LOG_FATAL,
"Failed creating CUDA context for NVENC: 0x%x\n", (
int)cu_res);
603 encode_session_params.device = ctx->
cu_context;
604 encode_session_params.deviceType = NV_ENC_DEVICE_TYPE_CUDA;
606 nv_status = p_nvenc->nvEncOpenEncodeSessionEx(&encode_session_params, &ctx->
nvencoder);
607 if (nv_status != NV_ENC_SUCCESS) {
609 av_log(avctx,
AV_LOG_FATAL,
"OpenEncodeSessionEx failed: 0x%x - invalid license key?\n", (
int)nv_status);
615 if (!strcmp(ctx->
preset,
"hp")) {
616 encoder_preset = NV_ENC_PRESET_HP_GUID;
617 }
else if (!strcmp(ctx->
preset,
"hq")) {
618 encoder_preset = NV_ENC_PRESET_HQ_GUID;
619 }
else if (!strcmp(ctx->
preset,
"bd")) {
620 encoder_preset = NV_ENC_PRESET_BD_GUID;
621 }
else if (!strcmp(ctx->
preset,
"ll")) {
622 encoder_preset = NV_ENC_PRESET_LOW_LATENCY_DEFAULT_GUID;
624 }
else if (!strcmp(ctx->
preset,
"llhp")) {
625 encoder_preset = NV_ENC_PRESET_LOW_LATENCY_HP_GUID;
627 }
else if (!strcmp(ctx->
preset,
"llhq")) {
628 encoder_preset = NV_ENC_PRESET_LOW_LATENCY_HQ_GUID;
630 }
else if (!strcmp(ctx->
preset,
"default")) {
631 encoder_preset = NV_ENC_PRESET_DEFAULT_GUID;
633 av_log(avctx,
AV_LOG_FATAL,
"Preset \"%s\" is unknown! Supported presets: hp, hq, bd, ll, llhp, llhq, default\n", ctx->
preset);
641 codec = NV_ENC_CODEC_H264_GUID;
644 codec = NV_ENC_CODEC_HEVC_GUID;
652 nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->
nvencoder, codec, encoder_preset, &preset_config);
653 if (nv_status != NV_ENC_SUCCESS) {
678 if (avctx->
width == 720 &&
691 num_mbs = ((avctx->
width + 15) >> 4) * ((avctx->
height + 15) >> 4);
703 if (avctx->
refs >= 0) {
710 ctx->
encode_config.encodeCodecConfig.hevcConfig.maxNumRefFramesInDPB = avctx->
refs;
737 ctx->
encode_config.encodeCodecConfig.h264Config.idrPeriod = 1;
740 ctx->
encode_config.encodeCodecConfig.hevcConfig.idrPeriod = 1;
758 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
759 }
else if (ctx->
twopass == 1 || isLL) {
760 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_2_PASS_QUALITY;
763 ctx->
encode_config.encodeCodecConfig.h264Config.adaptiveTransformMode = NV_ENC_H264_ADAPTIVE_TRANSFORM_ENABLE;
764 ctx->
encode_config.encodeCodecConfig.h264Config.fmoMode = NV_ENC_H264_FMO_DISABLE;
768 av_log(avctx,
AV_LOG_WARNING,
"Twopass mode is only known to work with low latency (ll, llhq, llhp) presets.\n");
770 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CBR;
773 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_CONSTQP;
780 }
else if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
781 ctx->
encode_config.rcParams.rateControlMode = NV_ENC_PARAMS_RC_VBR;
799 ctx->
encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FIELD;
801 ctx->
encode_config.frameFieldMode = NV_ENC_PARAMS_FRAME_FIELD_MODE_FRAME;
806 ctx->
encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1;
807 ctx->
encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1;
811 ctx->
encode_config.encodeCodecConfig.h264Config.h264VUIParameters.transferCharacteristics = avctx->
color_trc;
821 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
824 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
828 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
832 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
836 if (!strcmp(ctx->
profile,
"high")) {
837 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
839 }
else if (!strcmp(ctx->
profile,
"main")) {
840 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_MAIN_GUID;
842 }
else if (!strcmp(ctx->
profile,
"baseline")) {
843 ctx->
encode_config.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID;
856 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);
860 ctx->
encode_config.encodeCodecConfig.h264Config.level = NV_ENC_LEVEL_AUTOSELECT;
869 ctx->
encode_config.profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID;
876 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);
880 ctx->
encode_config.encodeCodecConfig.hevcConfig.level = NV_ENC_LEVEL_AUTOSELECT;
884 if (!strcmp(ctx->
tier,
"main")) {
885 ctx->
encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_MAIN;
886 }
else if (!strcmp(ctx->
tier,
"high")) {
887 ctx->
encode_config.encodeCodecConfig.hevcConfig.tier = NV_ENC_TIER_HEVC_HIGH;
900 if (nv_status != NV_ENC_SUCCESS) {
921 NV_ENC_CREATE_INPUT_BUFFER allocSurf = { 0 };
922 NV_ENC_CREATE_BITSTREAM_BUFFER allocOut = { 0 };
923 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
924 allocOut.version = NV_ENC_CREATE_BITSTREAM_BUFFER_VER;
926 allocSurf.width = (avctx->
width + 31) & ~31;
927 allocSurf.height = (avctx->
height + 31) & ~31;
929 allocSurf.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
933 allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_YV12_PL;
937 allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_NV12_PL;
941 allocSurf.bufferFmt = NV_ENC_BUFFER_FORMAT_YUV444_PL;
950 nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->
nvencoder, &allocSurf);
951 if (nv_status != NV_ENC_SUCCESS) {
964 allocOut.size = 1024 * 1024;
966 allocOut.memoryHeap = NV_ENC_MEMORY_HEAP_SYSMEM_CACHED;
968 nv_status = p_nvenc->nvEncCreateBitstreamBuffer(ctx->
nvencoder, &allocOut);
969 if (nv_status != NV_ENC_SUCCESS) {
982 uint32_t outSize = 0;
984 NV_ENC_SEQUENCE_PARAM_PAYLOAD payload = { 0 };
985 payload.version = NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER;
987 payload.spsppsBuffer = tmpHeader;
988 payload.inBufferSize =
sizeof(tmpHeader);
989 payload.outSPSPPSPayloadSize = &outSize;
991 nv_status = p_nvenc->nvEncGetSequenceParams(ctx->
nvencoder, &payload);
992 if (nv_status != NV_ENC_SUCCESS) {
1005 memcpy(avctx->
extradata, tmpHeader, outSize);
1018 for (i = 0; i < surfaceCount; ++i) {
1025 p_nvenc->nvEncDestroyEncoder(ctx->
nvencoder);
1044 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1057 p_nvenc->nvEncDestroyEncoder(ctx->
nvencoder);
1074 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1076 uint32_t slice_mode_data;
1077 uint32_t *slice_offsets;
1078 NV_ENC_LOCK_BITSTREAM lock_params = { 0 };
1079 NVENCSTATUS nv_status;
1084 slice_mode_data = ctx->
encode_config.encodeCodecConfig.h264Config.sliceModeData;
1087 slice_mode_data = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1094 slice_offsets =
av_mallocz(slice_mode_data *
sizeof(*slice_offsets));
1099 lock_params.version = NV_ENC_LOCK_BITSTREAM_VER;
1101 lock_params.doNotWait = 0;
1103 lock_params.sliceOffsets = slice_offsets;
1105 nv_status = p_nvenc->nvEncLockBitstream(ctx->
nvencoder, &lock_params);
1106 if (nv_status != NV_ENC_SUCCESS) {
1112 if (res =
ff_alloc_packet2(avctx, pkt, lock_params.bitstreamSizeInBytes)) {
1117 memcpy(pkt->
data, lock_params.bitstreamBufferPtr, lock_params.bitstreamSizeInBytes);
1120 if (nv_status != NV_ENC_SUCCESS)
1121 av_log(avctx,
AV_LOG_ERROR,
"Failed unlocking bitstream buffer, expect the gates of mordor to open\n");
1123 switch (lock_params.pictureType) {
1124 case NV_ENC_PIC_TYPE_IDR:
1126 case NV_ENC_PIC_TYPE_I:
1129 case NV_ENC_PIC_TYPE_P:
1132 case NV_ENC_PIC_TYPE_B:
1135 case NV_ENC_PIC_TYPE_BI:
1139 av_log(avctx,
AV_LOG_ERROR,
"Unknown picture type encountered, expect the output to be broken.\n");
1140 av_log(avctx,
AV_LOG_ERROR,
"Please report this error and include as much information on how to reproduce it as possible.\n");
1145 pkt->
pts = lock_params.outputTimeStamp;
1175 NVENCSTATUS nv_status;
1181 NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->
nvenc_funcs;
1183 NV_ENC_PIC_PARAMS pic_params = { 0 };
1184 pic_params.version = NV_ENC_PIC_PARAMS_VER;
1187 NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 };
1201 lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER;
1204 nv_status = p_nvenc->nvEncLockInputBuffer(ctx->
nvencoder, &lockBufferParams);
1205 if (nv_status != NV_ENC_SUCCESS) {
1211 uint8_t *
buf = lockBufferParams.bufferDataPtr;
1217 buf += inSurf->
height * lockBufferParams.pitch;
1223 buf += (inSurf->
height * lockBufferParams.pitch) >> 2;
1229 uint8_t *
buf = lockBufferParams.bufferDataPtr;
1235 buf += inSurf->
height * lockBufferParams.pitch;
1241 uint8_t *
buf = lockBufferParams.bufferDataPtr;
1247 buf += inSurf->
height * lockBufferParams.pitch;
1253 buf += inSurf->
height * lockBufferParams.pitch;
1264 if (nv_status != NV_ENC_SUCCESS) {
1282 pic_params.bufferFmt = inSurf->
format;
1283 pic_params.inputWidth = avctx->
width;
1284 pic_params.inputHeight = avctx->
height;
1286 pic_params.completionEvent = 0;
1290 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_TOP_BOTTOM;
1292 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FIELD_BOTTOM_TOP;
1295 pic_params.pictureStruct = NV_ENC_PIC_STRUCT_FRAME;
1298 pic_params.encodePicFlags = 0;
1299 pic_params.inputTimeStamp = frame->
pts;
1300 pic_params.inputDuration = 0;
1303 pic_params.codecPicParams.h264PicParams.sliceMode = ctx->
encode_config.encodeCodecConfig.h264Config.sliceMode;
1304 pic_params.codecPicParams.h264PicParams.sliceModeData = ctx->
encode_config.encodeCodecConfig.h264Config.sliceModeData;
1307 pic_params.codecPicParams.hevcPicParams.sliceMode = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceMode;
1308 pic_params.codecPicParams.hevcPicParams.sliceModeData = ctx->
encode_config.encodeCodecConfig.hevcConfig.sliceModeData;
1320 pic_params.encodePicFlags = NV_ENC_PIC_FLAG_EOS;
1323 nv_status = p_nvenc->nvEncEncodePicture(ctx->
nvencoder, &pic_params);
1325 if (frame && nv_status == NV_ENC_ERR_NEED_MORE_INPUT) {
1334 if (nv_status != NV_ENC_SUCCESS && nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
1339 if (nv_status != NV_ENC_ERR_NEED_MORE_INPUT) {
1366 tmpoutsurf->
busy = 0;
1383 #define OFFSET(x) offsetof(NvencContext, x)
1384 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1386 {
"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 },
1388 {
"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 },
1391 {
"2pass",
"Use 2pass cbr encoding mode (low latency mode only)",
OFFSET(twopass),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
VE },
1392 {
"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 },
1406 #if CONFIG_NVENC_ENCODER
1407 static const AVClass nvenc_class = {
1424 .priv_class = &nvenc_class,
1431 #if CONFIG_NVENC_H264_ENCODER
1432 static const AVClass nvenc_h264_class = {
1439 AVCodec ff_nvenc_h264_encoder = {
1440 .
name =
"nvenc_h264",
1449 .priv_class = &nvenc_h264_class,
1455 #if CONFIG_NVENC_HEVC_ENCODER
1456 static const AVClass nvenc_hevc_class = {
1463 AVCodec ff_nvenc_hevc_encoder = {
1464 .
name =
"nvenc_hevc",
1473 .priv_class = &nvenc_hevc_class,
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
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
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
AVFrame * coded_frame
the picture in the bitstream
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_assert0(cond)
assert() equivalent, that is always enabled.
CUresult(CUDAAPI * PCUDEVICEGET)(CUdevice *device, int ordinal)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define CHECK_LOAD_FUNC(t, f, s)
PCUDEVICEGETCOUNT cu_device_get_count
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
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]
static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, AVFrame *coded_frame, NvencOutputSurface *tmpoutsurf)
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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
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
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
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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[]
#define CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
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)
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)
static int64_t timestamp_queue_dequeue(NvencDataList *queue)
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.
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)
common internal api header.
CUresult(CUDAAPI * PCUCTXDESTROY)(CUcontext ctx)
PCUCTXPOPCURRENT cu_ctx_pop_current
CUdevice nvenc_devices[16]
static enum AVPixelFormat pix_fmts_nvenc[]
#define FF_PROFILE_HEVC_MAIN
CUresult(CUDAAPI * PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev)
CUresult(CUDAAPI * PCUINIT)(unsigned int Flags)
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)