+
+static const enum AVPixelFormat pix_fmts_nvenc[] = {
+ AV_PIX_FMT_YUV420P,
+ AV_PIX_FMT_NV12,
+ AV_PIX_FMT_YUV444P,
+ AV_PIX_FMT_NONE
+};
+
+#define OFFSET(x) offsetof(NvencContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "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 },
+ { "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
+ { "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 },
+ { "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
+ { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
+ { "2pass", "Use 2pass cbr encoding mode", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
+ { "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 },
+ { "delay", "Delays frame output by the given amount of frames.", OFFSET(buffer_delay), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE },
+ { NULL }
+};
+
+static const AVCodecDefault nvenc_defaults[] = {
+ { "b", "0" },
+ { "qmin", "-1" },
+ { "qmax", "-1" },
+ { "qdiff", "-1" },
+ { "qblur", "-1" },
+ { "qcomp", "-1" },
+ { NULL },
+};
+
+#if CONFIG_NVENC_ENCODER
+static const AVClass nvenc_class = {
+ .class_name = "nvenc",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_nvenc_encoder = {
+ .name = "nvenc",
+ .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC h264 encoder"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_H264,
+ .priv_data_size = sizeof(NvencContext),
+ .init = nvenc_encode_init,
+ .encode2 = nvenc_encode_frame,
+ .close = nvenc_encode_close,
+ .capabilities = CODEC_CAP_DELAY,
+ .priv_class = &nvenc_class,
+ .defaults = nvenc_defaults,
+ .pix_fmts = pix_fmts_nvenc,
+};
+#endif
+
+/* Add an alias for nvenc_h264 */
+#if CONFIG_NVENC_H264_ENCODER
+static const AVClass nvenc_h264_class = {
+ .class_name = "nvenc_h264",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_nvenc_h264_encoder = {
+ .name = "nvenc_h264",
+ .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC h264 encoder"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_H264,
+ .priv_data_size = sizeof(NvencContext),
+ .init = nvenc_encode_init,
+ .encode2 = nvenc_encode_frame,
+ .close = nvenc_encode_close,
+ .capabilities = CODEC_CAP_DELAY,
+ .priv_class = &nvenc_h264_class,
+ .defaults = nvenc_defaults,
+ .pix_fmts = pix_fmts_nvenc,
+};
+#endif
+
+#if CONFIG_NVENC_HEVC_ENCODER
+static const AVClass nvenc_hevc_class = {
+ .class_name = "nvenc_hevc",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_nvenc_hevc_encoder = {
+ .name = "nvenc_hevc",
+ .long_name = NULL_IF_CONFIG_SMALL("Nvidia NVENC hevc encoder"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_H265,
+ .priv_data_size = sizeof(NvencContext),
+ .init = nvenc_encode_init,
+ .encode2 = nvenc_encode_frame,
+ .close = nvenc_encode_close,
+ .capabilities = CODEC_CAP_DELAY,
+ .priv_class = &nvenc_hevc_class,
+ .defaults = nvenc_defaults,
+ .pix_fmts = pix_fmts_nvenc,
+};
+#endif