FFmpeg
nvenc.h
Go to the documentation of this file.
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 "config.h"
23 
24 #if CONFIG_D3D11VA
25 #define COBJMACROS
27 #else
28 typedef void ID3D11Device;
29 #endif
30 
31 #include <ffnvcodec/nvEncodeAPI.h>
32 
34 #include "libavutil/fifo.h"
35 #include "libavutil/opt.h"
36 #include "hwconfig.h"
37 
38 #include "avcodec.h"
39 
40 #define MAX_REGISTERED_FRAMES 64
41 #define RC_MODE_DEPRECATED 0x800000
42 #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED)
43 
44 #define NVENCAPI_CHECK_VERSION(major, minor) \
45  ((major) < NVENCAPI_MAJOR_VERSION || ((major) == NVENCAPI_MAJOR_VERSION && (minor) <= NVENCAPI_MINOR_VERSION))
46 
47 // SDK 8.1 compile time feature checks
48 #if NVENCAPI_CHECK_VERSION(8, 1)
49 #define NVENC_HAVE_BFRAME_REF_MODE
50 #define NVENC_HAVE_QP_MAP_MODE
51 #endif
52 
53 // SDK 9.0 compile time feature checks
54 #if NVENCAPI_CHECK_VERSION(9, 0)
55 #define NVENC_HAVE_HEVC_BFRAME_REF_MODE
56 #endif
57 
58 // SDK 9.1 compile time feature checks
59 #if NVENCAPI_CHECK_VERSION(9, 1)
60 #define NVENC_HAVE_MULTIPLE_REF_FRAMES
61 #define NVENC_HAVE_CUSTREAM_PTR
62 #define NVENC_HAVE_GETLASTERRORSTRING
63 #endif
64 
65 // SDK 10.0 compile time feature checks
66 #if NVENCAPI_CHECK_VERSION(10, 0)
67 #define NVENC_HAVE_NEW_PRESETS
68 #define NVENC_HAVE_MULTIPASS
69 #define NVENC_HAVE_LDKFS
70 #define NVENC_HAVE_H264_LVL6
71 #endif
72 
73 typedef struct NvencSurface
74 {
75  NV_ENC_INPUT_PTR input_surface;
77  int reg_idx;
78  int width;
79  int height;
80  int pitch;
81 
82  NV_ENC_OUTPUT_PTR output_surface;
83  NV_ENC_BUFFER_FORMAT format;
84  int size;
85 } NvencSurface;
86 
87 typedef struct NvencDynLoadFunctions
88 {
89  CudaFunctions *cuda_dl;
90  NvencFunctions *nvenc_dl;
91 
92  NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
95 
96 enum {
107  PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
109 #ifdef NVENC_HAVE_NEW_PRESETS
110  PRESET_P1,
111  PRESET_P2,
112  PRESET_P3,
113  PRESET_P4,
114  PRESET_P5,
115  PRESET_P6,
116  PRESET_P7,
117 #endif
118 };
119 
120 enum {
125 };
126 
127 enum {
131 };
132 
133 enum {
138 };
139 
140 enum {
143 };
144 
145 typedef struct NvencContext
146 {
148 
150 
151  NV_ENC_INITIALIZE_PARAMS init_encode_params;
152  NV_ENC_CONFIG encode_config;
153  CUcontext cu_context;
155  CUstream cu_stream;
157 
159 
162 
167 
168  struct {
169  void *ptr;
171  NV_ENC_REGISTERED_PTR regptr;
172  int mapped;
173  NV_ENC_MAP_INPUT_RESOURCE in_map;
174  } registered_frames[MAX_REGISTERED_FRAMES];
176 
177  /* the actual data pixel format, different from
178  * AVCodecContext.pix_fmt when using hwaccel frames on input */
179  enum AVPixelFormat data_pix_fmt;
180 
182 
183  void *nvencoder;
184 
185  int preset;
186  int profile;
187  int level;
188  int tier;
189  int rc;
190  int cbr;
191  int twopass;
192  int device;
193  int flags;
196  int aq;
199  int b_adapt;
202  int nonref_p;
205  float quality;
206  int aud;
211  int cqp;
213  int coder;
215  int a53_cc;
216  int s12m_tc;
217  int dpb_size;
220  int ldkfs;
221 } NvencContext;
222 
224 
226 
228 
230 
231 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
233 
234 #endif /* AVCODEC_NVENC_H */
int no_scenecut
Definition: nvenc.h:197
AVClass * avclass
Definition: nvenc.h:147
void * nvencoder
Definition: nvenc.h:183
int support_dyn_bitrate
Definition: nvenc.h:181
enum AVPixelFormat ff_nvenc_pix_fmts[]
Definition: nvenc.c:51
int twopass
Definition: nvenc.h:191
NV_ENC_BUFFER_FORMAT format
Definition: nvenc.h:83
int ff_nvenc_encode_init(AVCodecContext *avctx)
Definition: nvenc.c:1606
int height
Definition: nvenc.h:79
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
AVFifoBuffer * timestamp_list
Definition: nvenc.h:166
NvencFunctions * nvenc_dl
Definition: nvenc.h:90
int mapped
Definition: nvenc.h:172
AVFrame * in_ref
Definition: nvenc.h:76
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
int forced_idr
Definition: nvenc.h:198
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
Definition: nvenc.h:92
NvencDynLoadFunctions nvenc_dload_funcs
Definition: nvenc.h:149
ID3D11Device * d3d11_device
Definition: nvenc.h:156
static AVPacket pkt
int init_qp_b
Definition: nvenc.h:209
int preset
Definition: nvenc.h:185
int pitch
Definition: nvenc.h:80
int nvenc_device_count
Definition: nvenc.h:93
NV_ENC_INPUT_PTR input_surface
Definition: nvenc.h:75
void ff_nvenc_encode_flush(AVCodecContext *avctx)
Definition: nvenc.c:2322
int aq
Definition: nvenc.h:196
int b_ref_mode
Definition: nvenc.h:214
CUcontext cu_context
Definition: nvenc.h:153
AVFifoBuffer * unused_surface_queue
Definition: nvenc.h:163
AVOptions.
int init_qp_p
Definition: nvenc.h:208
int ff_nvenc_encode_close(AVCodecContext *avctx)
Definition: nvenc.c:1529
int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: nvenc.c:2271
float quality
Definition: nvenc.h:205
NV_ENC_INITIALIZE_PARAMS init_encode_params
Definition: nvenc.h:151
#define MAX_REGISTERED_FRAMES
Definition: nvenc.h:40
AVFifoBuffer * output_surface_ready_queue
Definition: nvenc.h:165
CUcontext cu_context_internal
Definition: nvenc.h:154
int ptr_index
Definition: nvenc.h:170
int async_depth
Definition: nvenc.h:194
void * ptr
Definition: nvenc.h:169
int coder
Definition: nvenc.h:213
int rc
Definition: nvenc.h:189
const AVCodecHWConfigInternal * ff_nvenc_hw_configs[]
Definition: nvenc.c:67
int nb_registered_frames
Definition: nvenc.h:175
int level
Definition: nvenc.h:187
void ID3D11Device
Definition: nvenc.h:28
int bluray_compat
Definition: nvenc.h:207
int aq_strength
Definition: nvenc.h:204
int flags
Definition: nvenc.h:193
NV_ENC_REGISTERED_PTR regptr
Definition: nvenc.h:171
int dpb_size
Definition: nvenc.h:217
int profile
Definition: nvenc.h:186
AVFifoBuffer * output_surface_queue
Definition: nvenc.h:164
int tuning_info
Definition: nvenc.h:218
CudaFunctions * cuda_dl
Definition: nvenc.h:89
NV_ENC_CONFIG encode_config
Definition: nvenc.h:152
Libavcodec external API header.
int strict_gop
Definition: nvenc.h:203
int temporal_aq
Definition: nvenc.h:200
main external API structure.
Definition: avcodec.h:526
int init_qp_i
Definition: nvenc.h:210
a very simple circular buffer FIFO implementation
Describe the class of an AVClass context structure.
Definition: log.h:67
int width
Definition: nvenc.h:78
int multipass
Definition: nvenc.h:219
int nonref_p
Definition: nvenc.h:202
int cbr
Definition: nvenc.h:190
int s12m_tc
Definition: nvenc.h:216
int reg_idx
Definition: nvenc.h:77
int b_adapt
Definition: nvenc.h:199
int weighted_pred
Definition: nvenc.h:212
int rc_lookahead
Definition: nvenc.h:195
int size
Definition: nvenc.h:84
NvencSurface * surfaces
Definition: nvenc.h:161
NV_ENC_MAP_INPUT_RESOURCE in_map
Definition: nvenc.h:173
CUstream cu_stream
Definition: nvenc.h:155
int device
Definition: nvenc.h:192
int nb_surfaces
Definition: nvenc.h:160
int aud
Definition: nvenc.h:206
int cqp
Definition: nvenc.h:211
int tier
Definition: nvenc.h:188
int ldkfs
Definition: nvenc.h:220
int a53_cc
Definition: nvenc.h:215
AVFrame * frame
Definition: nvenc.h:158
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: packet.h:332
NV_ENC_OUTPUT_PTR output_surface
Definition: nvenc.h:82
int zerolatency
Definition: nvenc.h:201