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