summaryrefslogtreecommitdiff
path: root/libavcodec/nvenc.h (plain)
blob: 7dec5cc68517c4f92d1725d93be0283c37927e82
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#ifndef AVCODEC_NVENC_H
20#define AVCODEC_NVENC_H
21
22#include "compat/nvenc/nvEncodeAPI.h"
23
24#include "config.h"
25
26#include "compat/cuda/dynlink_loader.h"
27#include "libavutil/fifo.h"
28#include "libavutil/opt.h"
29
30#include "avcodec.h"
31
32#define MAX_REGISTERED_FRAMES 64
33
34typedef struct NvencSurface
35{
36 NV_ENC_INPUT_PTR input_surface;
37 AVFrame *in_ref;
38 NV_ENC_MAP_INPUT_RESOURCE in_map;
39 int reg_idx;
40 int width;
41 int height;
42 int pitch;
43
44 NV_ENC_OUTPUT_PTR output_surface;
45 NV_ENC_BUFFER_FORMAT format;
46 int size;
47 int lockCount;
48} NvencSurface;
49
50typedef struct NvencDynLoadFunctions
51{
52 CudaFunctions *cuda_dl;
53 NvencFunctions *nvenc_dl;
54
55 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
56 int nvenc_device_count;
57} NvencDynLoadFunctions;
58
59enum {
60 PRESET_DEFAULT = 0,
61 PRESET_SLOW,
62 PRESET_MEDIUM,
63 PRESET_FAST,
64 PRESET_HP,
65 PRESET_HQ,
66 PRESET_BD ,
67 PRESET_LOW_LATENCY_DEFAULT ,
68 PRESET_LOW_LATENCY_HQ ,
69 PRESET_LOW_LATENCY_HP,
70 PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
71 PRESET_LOSSLESS_HP,
72};
73
74enum {
75 NV_ENC_H264_PROFILE_BASELINE,
76 NV_ENC_H264_PROFILE_MAIN,
77 NV_ENC_H264_PROFILE_HIGH,
78 NV_ENC_H264_PROFILE_HIGH_444P,
79};
80
81enum {
82 NV_ENC_HEVC_PROFILE_MAIN,
83 NV_ENC_HEVC_PROFILE_MAIN_10,
84 NV_ENC_HEVC_PROFILE_REXT,
85};
86
87enum {
88 NVENC_LOWLATENCY = 1,
89 NVENC_LOSSLESS = 2,
90 NVENC_ONE_PASS = 4,
91 NVENC_TWO_PASSES = 8,
92};
93
94enum {
95 LIST_DEVICES = -2,
96 ANY_DEVICE,
97};
98
99typedef struct NvencContext
100{
101 AVClass *avclass;
102
103 NvencDynLoadFunctions nvenc_dload_funcs;
104
105 NV_ENC_INITIALIZE_PARAMS init_encode_params;
106 NV_ENC_CONFIG encode_config;
107 CUcontext cu_context;
108 CUcontext cu_context_internal;
109
110 int nb_surfaces;
111 NvencSurface *surfaces;
112
113 AVFifoBuffer *output_surface_queue;
114 AVFifoBuffer *output_surface_ready_queue;
115 AVFifoBuffer *timestamp_list;
116
117 struct {
118 CUdeviceptr ptr;
119 NV_ENC_REGISTERED_PTR regptr;
120 int mapped;
121 } registered_frames[MAX_REGISTERED_FRAMES];
122 int nb_registered_frames;
123
124 /* the actual data pixel format, different from
125 * AVCodecContext.pix_fmt when using hwaccel frames on input */
126 enum AVPixelFormat data_pix_fmt;
127
128 /* timestamps of the first two frames, for computing the first dts
129 * when B-frames are present */
130 int64_t initial_pts[2];
131 int first_packet_output;
132
133 void *nvencoder;
134
135 int preset;
136 int profile;
137 int level;
138 int tier;
139 int rc;
140 int cbr;
141 int twopass;
142 int device;
143 int flags;
144 int async_depth;
145 int rc_lookahead;
146 int aq;
147 int no_scenecut;
148 int forced_idr;
149 int b_adapt;
150 int temporal_aq;
151 int zerolatency;
152 int nonref_p;
153 int strict_gop;
154 int aq_strength;
155 int quality;
156 int aud;
157 int bluray_compat;
158 int init_qp_p;
159 int init_qp_b;
160 int init_qp_i;
161 int cqp;
162} NvencContext;
163
164int ff_nvenc_encode_init(AVCodecContext *avctx);
165
166int ff_nvenc_encode_close(AVCodecContext *avctx);
167
168int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
169 const AVFrame *frame, int *got_packet);
170
171extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
172
173#endif /* AVCODEC_NVENC_H */
174