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 <nvEncodeAPI.h>
23 
24 #include "config.h"
25 
26 #include "libavutil/fifo.h"
27 #include "libavutil/opt.h"
28 
29 #include "avcodec.h"
30 
31 #if CONFIG_CUDA
33 #else
34 
35 #if defined(_WIN32)
36 #define CUDAAPI __stdcall
37 #else
38 #define CUDAAPI
39 #endif
40 
41 typedef enum cudaError_enum {
43 } CUresult;
44 typedef int CUdevice;
45 typedef void* CUcontext;
46 typedef void* CUdeviceptr;
47 #endif
48 
49 #define MAX_REGISTERED_FRAMES 64
50 
51 typedef struct NvencSurface
52 {
53  NV_ENC_INPUT_PTR input_surface;
55  NV_ENC_MAP_INPUT_RESOURCE in_map;
56  int reg_idx;
57  int width;
58  int height;
59 
60  NV_ENC_OUTPUT_PTR output_surface;
61  NV_ENC_BUFFER_FORMAT format;
62  int size;
63  int lockCount;
64 } NvencSurface;
65 
66 typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
68 typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
69 typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
70 typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
71 typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
74 
75 typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
76 
77 typedef struct NvencDynLoadFunctions
78 {
79 #if !CONFIG_CUDA
80  void *cuda;
81 #endif
82  void *nvenc;
83 
92 
93  NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
96 
97 enum {
108  PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
110 };
111 
112 enum {
117 };
118 
119 enum {
124 };
125 
126 enum {
129 };
130 
131 typedef struct NvencContext
132 {
134 
136 
137  NV_ENC_INITIALIZE_PARAMS init_encode_params;
138  NV_ENC_CONFIG encode_config;
141 
144 
148 
149  struct {
151  NV_ENC_REGISTERED_PTR regptr;
152  int mapped;
155 
156  /* the actual data pixel format, different from
157  * AVCodecContext.pix_fmt when using hwaccel frames on input */
159 
160  /* timestamps of the first two frames, for computing the first dts
161  * when B-frames are present */
162  int64_t initial_pts[2];
164 
165  void *nvencoder;
166 
167  int preset;
168  int profile;
169  int level;
170  int tier;
171  int rc;
172  int cbr;
173  int twopass;
174  int device;
175  int flags;
177 } NvencContext;
178 
180 
182 
184  const AVFrame *frame, int *got_packet);
185 
186 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
187 
188 #endif /* AVCODEC_NVENC_H */
AVClass * avclass
Definition: nvenc.h:133
void * nvencoder
Definition: nvenc.h:165
enum AVPixelFormat ff_nvenc_pix_fmts[]
Definition: nvenc.c:76
int twopass
Definition: nvenc.h:173
NV_ENC_BUFFER_FORMAT format
Definition: nvenc.h:61
int ff_nvenc_encode_init(AVCodecContext *avctx)
Definition: nvenc.c:1157
int height
Definition: nvenc.h:58
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
AVFifoBuffer * timestamp_list
Definition: nvenc.h:147
int mapped
Definition: nvenc.h:152
AVFrame * in_ref
Definition: nvenc.h:54
NV_ENC_MAP_INPUT_RESOURCE in_map
Definition: nvenc.h:55
int CUdevice
Definition: nvenc.h:44
PCUCTXDESTROY cu_ctx_destroy
Definition: nvenc.h:91
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
Definition: nvenc.h:93
NvencDynLoadFunctions nvenc_dload_funcs
Definition: nvenc.h:135
int first_packet_output
Definition: nvenc.h:163
PCUDEVICEGETNAME cu_device_get_name
Definition: nvenc.h:87
static AVPacket pkt
int preset
Definition: nvenc.h:167
int nvenc_device_count
Definition: nvenc.h:94
NV_ENC_INPUT_PTR input_surface
Definition: nvenc.h:53
CUcontext cu_context
Definition: nvenc.h:139
AVOptions.
PCUDEVICEGETCOUNT cu_device_get_count
Definition: nvenc.h:85
PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability
Definition: nvenc.h:88
CUresult(CUDAAPI * PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev)
Definition: nvenc.h:71
int ff_nvenc_encode_close(AVCodecContext *avctx)
Definition: nvenc.c:1080
CUresult(CUDAAPI * PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev)
Definition: nvenc.h:70
NV_ENC_INITIALIZE_PARAMS init_encode_params
Definition: nvenc.h:137
static AVFrame * frame
#define MAX_REGISTERED_FRAMES
Definition: nvenc.h:49
#define CUDAAPI
Definition: nvenc.h:38
AVFifoBuffer * output_surface_ready_queue
Definition: nvenc.h:146
CUdeviceptr ptr
Definition: nvenc.h:150
CUcontext cu_context_internal
Definition: nvenc.h:140
An API-specific header for AV_HWDEVICE_TYPE_CUDA.
int async_depth
Definition: nvenc.h:176
int rc
Definition: nvenc.h:171
NVENCSTATUS(NVENCAPI * PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList)
Definition: nvenc.h:75
int nb_registered_frames
Definition: nvenc.h:154
PCUDEVICEGET cu_device_get
Definition: nvenc.h:86
GLsizei count
Definition: opengl_enc.c:109
CUresult(CUDAAPI * PCUDEVICEGET)(CUdevice *device, int ordinal)
Definition: nvenc.h:68
int level
Definition: nvenc.h:169
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: nvenc.c:1583
PCUINIT cu_init
Definition: nvenc.h:84
int flags
Definition: nvenc.h:175
NV_ENC_REGISTERED_PTR regptr
Definition: nvenc.h:151
int lockCount
Definition: nvenc.h:63
CUresult(CUDAAPI * PCUDEVICEGETCOUNT)(int *count)
Definition: nvenc.h:67
AVFormatContext * ctx
Definition: movenc.c:48
CUresult
Definition: nvenc.h:41
int profile
Definition: nvenc.h:168
AVFifoBuffer * output_surface_queue
Definition: nvenc.h:145
enum AVPixelFormat data_pix_fmt
Definition: nvenc.h:158
PCUCTXCREATE cu_ctx_create
Definition: nvenc.h:89
NV_ENC_CONFIG encode_config
Definition: nvenc.h:138
Libavcodec external API header.
int64_t initial_pts[2]
Definition: nvenc.h:162
main external API structure.
Definition: avcodec.h:1649
a very simple circular buffer FIFO implementation
CUresult(CUDAAPI * PCUCTXDESTROY)(CUcontext ctx)
Definition: nvenc.h:73
void * CUdeviceptr
Definition: nvenc.h:46
Describe the class of an AVClass context structure.
Definition: log.h:67
struct NvencContext::@85 registered_frames[MAX_REGISTERED_FRAMES]
int width
Definition: nvenc.h:57
CUresult(CUDAAPI * PCUINIT)(unsigned int Flags)
Definition: nvenc.h:66
int cbr
Definition: nvenc.h:172
static int flags
Definition: cpu.c:47
int reg_idx
Definition: nvenc.h:56
PCUCTXPOPCURRENT cu_ctx_pop_current
Definition: nvenc.h:90
int size
Definition: nvenc.h:62
NvencSurface * surfaces
Definition: nvenc.h:143
int len
int device
Definition: nvenc.h:174
int nb_surfaces
Definition: nvenc.h:142
CUresult(CUDAAPI * PCUCTXPOPCURRENT)(CUcontext *pctx)
Definition: nvenc.h:72
int tier
Definition: nvenc.h:170
void * CUcontext
Definition: nvenc.h:45
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1557
NV_ENC_OUTPUT_PTR output_surface
Definition: nvenc.h:60
CUresult(CUDAAPI * PCUDEVICEGETNAME)(char *name, int len, CUdevice dev)
Definition: nvenc.h:69
const char * name
Definition: opengl_enc.c:103