FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
37 #include "avcodec.h"
38 
39 #define MAX_REGISTERED_FRAMES 64
40 #define RC_MODE_DEPRECATED 0x800000
41 #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED)
42 
43 #define NVENCAPI_CHECK_VERSION(major, minor) \
44  ((major) < NVENCAPI_MAJOR_VERSION || ((major) == NVENCAPI_MAJOR_VERSION && (minor) <= NVENCAPI_MINOR_VERSION))
45 
46 // SDK 8.1 compile time feature checks
47 #if NVENCAPI_CHECK_VERSION(8, 1)
48 #define NVENC_HAVE_BFRAME_REF_MODE
49 #define NVENC_HAVE_QP_MAP_MODE
50 #endif
51 
52 typedef struct NvencSurface
53 {
54  NV_ENC_INPUT_PTR input_surface;
56  int reg_idx;
57  int width;
58  int height;
59  int pitch;
60 
61  NV_ENC_OUTPUT_PTR output_surface;
62  NV_ENC_BUFFER_FORMAT format;
63  int size;
64 } NvencSurface;
65 
66 typedef struct NvencDynLoadFunctions
67 {
68  CudaFunctions *cuda_dl;
69  NvencFunctions *nvenc_dl;
70 
71  NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
74 
75 enum {
86  PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
88 };
89 
90 enum {
95 };
96 
97 enum {
101 };
102 
103 enum {
108 };
109 
110 enum {
113 };
114 
115 typedef struct NvencContext
116 {
118 
120 
121  NV_ENC_INITIALIZE_PARAMS init_encode_params;
122  NV_ENC_CONFIG encode_config;
123  CUcontext cu_context;
126 
129 
134 
136 
137  struct {
138  void *ptr;
140  NV_ENC_REGISTERED_PTR regptr;
141  int mapped;
142  NV_ENC_MAP_INPUT_RESOURCE in_map;
145 
146  /* the actual data pixel format, different from
147  * AVCodecContext.pix_fmt when using hwaccel frames on input */
149 
150  /* timestamps of the first two frames, for computing the first dts
151  * when B-frames are present */
152  int64_t initial_pts[2];
154 
156 
157  void *nvencoder;
158 
159  int preset;
160  int profile;
161  int level;
162  int tier;
163  int rc;
164  int cbr;
165  int twopass;
166  int device;
167  int flags;
170  int aq;
173  int b_adapt;
176  int nonref_p;
179  float quality;
180  int aud;
185  int cqp;
187  int coder;
189  int a53_cc;
190 } NvencContext;
191 
193 
195 
196 int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame);
197 
199 
201  const AVFrame *frame, int *got_packet);
202 
203 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
204 
205 #endif /* AVCODEC_NVENC_H */
int no_scenecut
Definition: nvenc.h:171
AVClass * avclass
Definition: nvenc.h:117
void * nvencoder
Definition: nvenc.h:157
int support_dyn_bitrate
Definition: nvenc.h:155
enum AVPixelFormat ff_nvenc_pix_fmts[]
Definition: nvenc.c:39
int twopass
Definition: nvenc.h:165
NV_ENC_BUFFER_FORMAT format
Definition: nvenc.h:62
int ff_nvenc_encode_init(AVCodecContext *avctx)
Definition: nvenc.c:1483
int height
Definition: nvenc.h:58
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
AVFifoBuffer * timestamp_list
Definition: nvenc.h:133
NvencFunctions * nvenc_dl
Definition: nvenc.h:69
int mapped
Definition: nvenc.h:141
AVFrame * in_ref
Definition: nvenc.h:55
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
int encoder_flushing
Definition: nvenc.h:135
int forced_idr
Definition: nvenc.h:172
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
Definition: nvenc.h:71
NvencDynLoadFunctions nvenc_dload_funcs
Definition: nvenc.h:119
ID3D11Device * d3d11_device
Definition: nvenc.h:125
int first_packet_output
Definition: nvenc.h:153
static AVPacket pkt
int init_qp_b
Definition: nvenc.h:183
int preset
Definition: nvenc.h:159
int pitch
Definition: nvenc.h:59
int nvenc_device_count
Definition: nvenc.h:72
NV_ENC_INPUT_PTR input_surface
Definition: nvenc.h:54
int aq
Definition: nvenc.h:170
int b_ref_mode
Definition: nvenc.h:188
CUcontext cu_context
Definition: nvenc.h:123
AVFifoBuffer * unused_surface_queue
Definition: nvenc.h:130
AVOptions.
int init_qp_p
Definition: nvenc.h:182
int ff_nvenc_encode_close(AVCodecContext *avctx)
Definition: nvenc.c:1408
int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: nvenc.c:2164
float quality
Definition: nvenc.h:179
NV_ENC_INITIALIZE_PARAMS init_encode_params
Definition: nvenc.h:121
static AVFrame * frame
#define MAX_REGISTERED_FRAMES
Definition: nvenc.h:39
AVFifoBuffer * output_surface_ready_queue
Definition: nvenc.h:132
CUcontext cu_context_internal
Definition: nvenc.h:124
int ptr_index
Definition: nvenc.h:139
int async_depth
Definition: nvenc.h:168
void * ptr
Definition: nvenc.h:138
int coder
Definition: nvenc.h:187
int rc
Definition: nvenc.h:163
int nb_registered_frames
Definition: nvenc.h:144
int level
Definition: nvenc.h:161
void ID3D11Device
Definition: nvenc.h:28
int bluray_compat
Definition: nvenc.h:181
int aq_strength
Definition: nvenc.h:178
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: nvenc.c:2200
int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Definition: nvenc.c:2036
int flags
Definition: nvenc.h:167
NV_ENC_REGISTERED_PTR regptr
Definition: nvenc.h:140
int profile
Definition: nvenc.h:160
AVFifoBuffer * output_surface_queue
Definition: nvenc.h:131
CudaFunctions * cuda_dl
Definition: nvenc.h:68
enum AVPixelFormat data_pix_fmt
Definition: nvenc.h:148
NV_ENC_CONFIG encode_config
Definition: nvenc.h:122
struct NvencContext::@124 registered_frames[MAX_REGISTERED_FRAMES]
Libavcodec external API header.
int strict_gop
Definition: nvenc.h:177
int temporal_aq
Definition: nvenc.h:174
int64_t initial_pts[2]
Definition: nvenc.h:152
main external API structure.
Definition: avcodec.h:1533
int init_qp_i
Definition: nvenc.h:184
a very simple circular buffer FIFO implementation
Describe the class of an AVClass context structure.
Definition: log.h:67
int width
Definition: nvenc.h:57
int nonref_p
Definition: nvenc.h:176
int cbr
Definition: nvenc.h:164
int reg_idx
Definition: nvenc.h:56
int b_adapt
Definition: nvenc.h:173
int weighted_pred
Definition: nvenc.h:186
int rc_lookahead
Definition: nvenc.h:169
int size
Definition: nvenc.h:63
NvencSurface * surfaces
Definition: nvenc.h:128
NV_ENC_MAP_INPUT_RESOURCE in_map
Definition: nvenc.h:142
int device
Definition: nvenc.h:166
int nb_surfaces
Definition: nvenc.h:127
int aud
Definition: nvenc.h:180
int cqp
Definition: nvenc.h:185
int tier
Definition: nvenc.h:162
int a53_cc
Definition: nvenc.h:189
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: avcodec.h:1422
NV_ENC_OUTPUT_PTR output_surface
Definition: nvenc.h:61
int zerolatency
Definition: nvenc.h:175