]> git.sesse.net Git - ffmpeg/blob - libavcodec/nvenc_h264.c
avcodec/nvenc: split H264/HEVC encoder definitions into separate files
[ffmpeg] / libavcodec / nvenc_h264.c
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "libavutil/internal.h"
20
21 #include "avcodec.h"
22 #include "internal.h"
23
24 #include "nvenc.h"
25
26 #define OFFSET(x) offsetof(NvencContext, x)
27 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
28 static const AVOption options[] = {
29     { "preset", "Set the encoding preset (one of slow = hq 2pass, medium = hq, fast = hp, hq, hp, bd, ll, llhq, llhp, lossless, losslesshp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE },
30     { "profile", "Set the encoding profile (high, main, baseline or high444p)", OFFSET(profile), AV_OPT_TYPE_STRING, { .str = "main" }, 0, 0, VE },
31     { "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, { .str = "auto" }, 0, 0, VE },
32     { "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
33     { "2pass", "Use 2pass encoding mode", OFFSET(twopass), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
34     { "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 },
35     { "delay", "Delays frame output by the given amount of frames.", OFFSET(buffer_delay), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE },
36     { NULL }
37 };
38
39 static const AVCodecDefault defaults[] = {
40     { "b", "2M" },
41     { "qmin", "-1" },
42     { "qmax", "-1" },
43     { "qdiff", "-1" },
44     { "qblur", "-1" },
45     { "qcomp", "-1" },
46     { "g", "250" },
47     { "bf", "0" },
48     { NULL },
49 };
50
51 #if CONFIG_NVENC_ENCODER
52 static const AVClass nvenc_class = {
53     .class_name = "nvenc",
54     .item_name = av_default_item_name,
55     .option = options,
56     .version = LIBAVUTIL_VERSION_INT,
57 };
58
59 AVCodec ff_nvenc_encoder = {
60     .name           = "nvenc",
61     .long_name      = NULL_IF_CONFIG_SMALL("NVIDIA NVENC h264 encoder"),
62     .type           = AVMEDIA_TYPE_VIDEO,
63     .id             = AV_CODEC_ID_H264,
64     .init           = ff_nvenc_encode_init,
65     .encode2        = ff_nvenc_encode_frame,
66     .close          = ff_nvenc_encode_close,
67     .priv_data_size = sizeof(NvencContext),
68     .priv_class     = &nvenc_class,
69     .defaults       = defaults,
70     .capabilities   = AV_CODEC_CAP_DELAY,
71     .pix_fmts       = ff_nvenc_pix_fmts,
72 };
73 #endif
74
75 /* Add an alias for nvenc_h264 */
76 #if CONFIG_NVENC_H264_ENCODER
77 static const AVClass nvenc_h264_class = {
78     .class_name = "nvenc_h264",
79     .item_name = av_default_item_name,
80     .option = options,
81     .version = LIBAVUTIL_VERSION_INT,
82 };
83
84 AVCodec ff_nvenc_h264_encoder = {
85     .name           = "nvenc_h264",
86     .long_name      = NULL_IF_CONFIG_SMALL("NVIDIA NVENC h264 encoder"),
87     .type           = AVMEDIA_TYPE_VIDEO,
88     .id             = AV_CODEC_ID_H264,
89     .init           = ff_nvenc_encode_init,
90     .encode2        = ff_nvenc_encode_frame,
91     .close          = ff_nvenc_encode_close,
92     .priv_data_size = sizeof(NvencContext),
93     .priv_class     = &nvenc_h264_class,
94     .defaults       = defaults,
95     .capabilities   = AV_CODEC_CAP_DELAY,
96     .pix_fmts       = ff_nvenc_pix_fmts,
97 };
98 #endif