FFmpeg
Loading...
Searching...
No Matches
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
28typedef void ID3D11Device;
29#endif
30
31#include <ffnvcodec/nvEncodeAPI.h>
32
34#include "libavutil/buffer.h"
35#include "libavutil/fifo.h"
36#include "libavutil/opt.h"
37#include "hwconfig.h"
38
39#include "avcodec.h"
40
41#define MAX_REGISTERED_FRAMES 64
42
43#define NVENCAPI_CHECK_VERSION(major, minor) \
44 ((major) < NVENCAPI_MAJOR_VERSION || ((major) == NVENCAPI_MAJOR_VERSION && (minor) <= NVENCAPI_MINOR_VERSION))
45
46// SDK 12.0 compile time feature checks
47#if NVENCAPI_CHECK_VERSION(12, 0)
48#define NVENC_HAVE_HEVC_OUTPUT_RECOVERY_POINT_SEI
49#endif
50
51// SDK 12.1 compile time feature checks
52#if NVENCAPI_CHECK_VERSION(12, 1)
53#define NVENC_HAVE_SPLIT_FRAME_ENCODING
54#endif
55
56// SDK 12.2 compile time feature checks
57#if NVENCAPI_CHECK_VERSION(12, 2)
58#define NVENC_HAVE_NEW_BIT_DEPTH_API
59#define NVENC_HAVE_TEMPORAL_FILTER
60#define NVENC_HAVE_LOOKAHEAD_LEVEL
61#define NVENC_HAVE_UHQ_TUNING
62#define NVENC_HAVE_UNIDIR_B
63#define NVENC_HAVE_TIME_CODE // added in 12.0, but incomplete until 12.2
64#endif
65
66// SDK 13.0 compile time feature checks
67#if NVENCAPI_CHECK_VERSION(13, 0)
68#define NVENC_HAVE_H264_10BIT_SUPPORT
69#define NVENC_HAVE_422_SUPPORT
70#define NVENC_HAVE_SFE_FOUR_WAYS_SUPPORT
71#define NVENC_HAVE_AV1_UHQ_TUNING
72#define NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
73#define NVENC_HAVE_HEVC_AND_AV1_MASTERING_METADATA
74#define NVENC_HAVE_MVHEVC
75#endif
76
77// SDK 13.1 compile time feature checks
78#if NVENCAPI_CHECK_VERSION(13, 1)
79#define NVENC_NEW_COUNTING_TYPE
80#define NVENC_HAVE_AV1_HGOP_SUPPORT
81#define NVENC_HAVE_CUDA_ARRAY_INPUT_SUPPORT
82#endif
83
84typedef struct NvencSurface
85{
86 NV_ENC_INPUT_PTR input_surface;
89 int width;
90 int height;
91 int pitch;
92
93 NV_ENC_OUTPUT_PTR output_surface;
94 NV_ENC_BUFFER_FORMAT format;
96
104
106{
107 CudaFunctions *cuda_dl;
108 NvencFunctions *nvenc_dl;
109
110 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
113
114enum {
125};
126
127enum {
131#ifdef NVENC_HAVE_H264_10BIT_SUPPORT
132 NV_ENC_H264_PROFILE_HIGH_10,
133#endif
134#ifdef NVENC_HAVE_422_SUPPORT
135 NV_ENC_H264_PROFILE_HIGH_422,
136#endif
138};
139
140enum {
144#ifdef NVENC_HAVE_MVHEVC
145 NV_ENC_HEVC_PROFILE_MULTIVIEW_MAIN,
146#endif
147
149};
150
151enum {
156};
157
158enum {
161};
162
163enum {
167};
168
169typedef struct NvencContext
170{
172
174
175 NV_ENC_INITIALIZE_PARAMS init_encode_params;
176 NV_ENC_CONFIG encode_config;
177 CUcontext cu_context;
179 CUstream cu_stream;
181
183
186
190
195 // This is for DTS calculating, reset after flush
198
199 NV_ENC_SEI_PAYLOAD *sei_data;
201
202 struct {
203 void *ptr;
205 NV_ENC_REGISTERED_PTR regptr;
207 NV_ENC_MAP_INPUT_RESOURCE in_map;
210
211 /* the actual data pixel format, different from
212 * AVCodecContext.pix_fmt when using hwaccel frames on input */
214
216
218
220 uint32_t next_view_id;
221
224 int level;
225 int tier;
226 int rc;
230 int flags;
233 int aq;
242 float quality;
243 int aud;
245 int qmin;
246 int qmax;
250 int cqp;
254 int coder;
261 int ldkfs;
275 int mdm, cll;
280
282
284
286
288
289extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
290extern const AVCodecHWConfigInternal *const ff_nvenc_hw_configs[];
291
292#endif /* AVCODEC_NVENC_H */
Libavcodec external API header.
refcounted data buffer API
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
A generic FIFO API.
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
const AVCodecHWConfigInternal *const ff_nvenc_hw_configs[]
Definition nvenc.c:92
enum AVPixelFormat ff_nvenc_pix_fmts[]
Definition nvenc.c:53
@ NVENC_TWO_PASSES
Definition nvenc.h:155
@ NVENC_LOSSLESS
Definition nvenc.h:153
@ NVENC_LOWLATENCY
Definition nvenc.h:152
@ NVENC_ONE_PASS
Definition nvenc.h:154
@ NVENC_RGB_MODE_DISABLED
Definition nvenc.h:164
@ NVENC_RGB_MODE_420
Definition nvenc.h:165
@ NVENC_RGB_MODE_444
Definition nvenc.h:166
@ NV_ENC_H264_PROFILE_MAIN
Definition nvenc.h:129
@ NV_ENC_H264_PROFILE_HIGH
Definition nvenc.h:130
@ NV_ENC_H264_PROFILE_HIGH_444P
Definition nvenc.h:137
@ NV_ENC_H264_PROFILE_BASELINE
Definition nvenc.h:128
int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition nvenc.c:3177
int ff_nvenc_encode_close(AVCodecContext *avctx)
Definition nvenc.c:2033
@ LIST_DEVICES
Definition nvenc.h:159
@ ANY_DEVICE
Definition nvenc.h:160
@ PRESET_SLOW
Definition nvenc.h:115
@ PRESET_P4
Definition nvenc.h:121
@ PRESET_P5
Definition nvenc.h:122
@ PRESET_FAST
Definition nvenc.h:117
@ PRESET_P2
Definition nvenc.h:119
@ PRESET_MEDIUM
Definition nvenc.h:116
@ PRESET_P3
Definition nvenc.h:120
@ PRESET_P7
Definition nvenc.h:124
@ PRESET_P1
Definition nvenc.h:118
@ PRESET_P6
Definition nvenc.h:123
void ID3D11Device
Definition nvenc.h:28
int ff_nvenc_encode_init(AVCodecContext *avctx)
Definition nvenc.c:2118
@ NV_ENC_HEVC_PROFILE_REXT
Definition nvenc.h:143
@ NV_ENC_HEVC_PROFILE_MAIN
Definition nvenc.h:141
@ NV_ENC_HEVC_PROFILE_COUNT
Definition nvenc.h:148
@ NV_ENC_HEVC_PROFILE_MAIN_10
Definition nvenc.h:142
void ff_nvenc_encode_flush(AVCodecContext *avctx)
Definition nvenc.c:3228
#define MAX_REGISTERED_FRAMES
Definition nvenc.h:41
AVOptions.
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
Definition fifo.c:35
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
NvencDynLoadFunctions nvenc_dload_funcs
Definition nvenc.h:173
AVFrame * frame
Definition nvenc.h:182
CUcontext cu_context
Definition nvenc.h:177
int strict_gop
Definition nvenc.h:240
struct NvencContext::@072337001227035330003263257343131226321271123317 registered_frames[MAX_REGISTERED_FRAMES]
int rc_lookahead
Definition nvenc.h:232
int split_encode_mode
Definition nvenc.h:274
int init_qp_b
Definition nvenc.h:248
enum AVPixelFormat data_pix_fmt
Definition nvenc.h:213
int forced_idr
Definition nvenc.h:235
int no_scenecut
Definition nvenc.h:234
int init_qp_i
Definition nvenc.h:249
int qp_cr_offset
Definition nvenc.h:252
int device
Definition nvenc.h:229
int rgb_mode
Definition nvenc.h:270
int init_qp_p
Definition nvenc.h:247
int sei_data_size
Definition nvenc.h:200
int qp_cb_offset
Definition nvenc.h:251
NV_ENC_REGISTERED_PTR regptr
Definition nvenc.h:205
AVFifo * output_surface_queue
Definition nvenc.h:192
int intra_refresh
Definition nvenc.h:263
int constrained_encoding
Definition nvenc.h:265
int64_t initial_delay_time
Definition nvenc.h:197
int mapped
Definition nvenc.h:206
AVFifo * output_surface_ready_queue
Definition nvenc.h:193
int ldkfs
Definition nvenc.h:261
float quality
Definition nvenc.h:242
int multiview_supported
Definition nvenc.h:277
ID3D11Device * d3d11_device
Definition nvenc.h:180
int udu_sei
Definition nvenc.h:266
int timing_info
Definition nvenc.h:267
int tf_level
Definition nvenc.h:271
int max_slice_size
Definition nvenc.h:269
NV_ENC_INITIALIZE_PARAMS init_encode_params
Definition nvenc.h:175
NvencFrameData * frame_data_array
Definition nvenc.h:187
AVFifo * timestamp_list
Definition nvenc.h:194
NV_ENC_CONFIG encode_config
Definition nvenc.h:176
NV_ENC_MAP_INPUT_RESOURCE in_map
Definition nvenc.h:207
int ptr_index
Definition nvenc.h:204
int cbr_padding
Definition nvenc.h:276
int s12m_tc
Definition nvenc.h:257
AVClass * avclass
Definition nvenc.h:171
CUcontext cu_context_internal
Definition nvenc.h:178
int temporal_aq
Definition nvenc.h:237
int tile_rows
Definition nvenc.h:227
int async_depth
Definition nvenc.h:231
CUstream cu_stream
Definition nvenc.h:179
int display_sei_sent
Definition nvenc.h:278
int preset
Definition nvenc.h:222
uint32_t frame_idx_counter
Definition nvenc.h:219
int nonref_p
Definition nvenc.h:239
int level
Definition nvenc.h:224
int coder
Definition nvenc.h:254
int aq_strength
Definition nvenc.h:241
int flags
Definition nvenc.h:230
int b_ref_mode
Definition nvenc.h:255
int multipass
Definition nvenc.h:260
int lookahead_level
Definition nvenc.h:272
uint64_t output_frame_num
Definition nvenc.h:196
int extra_sei
Definition nvenc.h:262
AVFifo * unused_surface_queue
Definition nvenc.h:191
NV_ENC_SEI_PAYLOAD * sei_data
Definition nvenc.h:199
int highbitdepth
Definition nvenc.h:268
int single_slice_intra_refresh
Definition nvenc.h:264
void * ptr
Definition nvenc.h:203
int frame_data_array_pos
Definition nvenc.h:189
int frame_data_array_nb
Definition nvenc.h:188
int bluray_compat
Definition nvenc.h:244
void * nvencoder
Definition nvenc.h:217
int profile
Definition nvenc.h:223
int weighted_pred
Definition nvenc.h:253
int b_adapt
Definition nvenc.h:236
int zerolatency
Definition nvenc.h:238
NvencSurface * surfaces
Definition nvenc.h:185
int multiview
Definition nvenc.h:277
int dpb_size
Definition nvenc.h:258
uint32_t next_view_id
Definition nvenc.h:220
int nb_surfaces
Definition nvenc.h:184
int unidir_b
Definition nvenc.h:273
int nb_registered_frames
Definition nvenc.h:209
int a53_cc
Definition nvenc.h:256
int tile_cols
Definition nvenc.h:228
int support_dyn_bitrate
Definition nvenc.h:215
int tuning_info
Definition nvenc.h:259
NvencFunctions * nvenc_dl
Definition nvenc.h:108
CudaFunctions * cuda_dl
Definition nvenc.h:107
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
Definition nvenc.h:110
int64_t duration
Definition nvenc.h:99
AVBufferRef * frame_opaque_ref
Definition nvenc.h:102
void * frame_opaque
Definition nvenc.h:101
NV_ENC_OUTPUT_PTR output_surface
Definition nvenc.h:93
int width
Definition nvenc.h:89
AVFrame * in_ref
Definition nvenc.h:87
NV_ENC_BUFFER_FORMAT format
Definition nvenc.h:94
int reg_idx
Definition nvenc.h:88
int height
Definition nvenc.h:90
NV_ENC_INPUT_PTR input_surface
Definition nvenc.h:86
int pitch
Definition nvenc.h:91