2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVCODEC_NVENC_H
20 #define AVCODEC_NVENC_H
22 #include "compat/nvenc/nvEncodeAPI.h"
26 #include "compat/cuda/dynlink_loader.h"
27 #include "libavutil/fifo.h"
28 #include "libavutil/opt.h"
32 #define MAX_REGISTERED_FRAMES 64
34 typedef struct NvencSurface
36 NV_ENC_INPUT_PTR input_surface;
38 NV_ENC_MAP_INPUT_RESOURCE in_map;
44 NV_ENC_OUTPUT_PTR output_surface;
45 NV_ENC_BUFFER_FORMAT format;
49 typedef struct NvencDynLoadFunctions
51 CudaFunctions *cuda_dl;
52 NvencFunctions *nvenc_dl;
54 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
55 int nvenc_device_count;
56 } NvencDynLoadFunctions;
66 PRESET_LOW_LATENCY_DEFAULT ,
67 PRESET_LOW_LATENCY_HQ ,
68 PRESET_LOW_LATENCY_HP,
69 PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
74 NV_ENC_H264_PROFILE_BASELINE,
75 NV_ENC_H264_PROFILE_MAIN,
76 NV_ENC_H264_PROFILE_HIGH,
77 NV_ENC_H264_PROFILE_HIGH_444P,
81 NV_ENC_HEVC_PROFILE_MAIN,
82 NV_ENC_HEVC_PROFILE_MAIN_10,
83 NV_ENC_HEVC_PROFILE_REXT,
98 typedef struct NvencContext
102 NvencDynLoadFunctions nvenc_dload_funcs;
104 NV_ENC_INITIALIZE_PARAMS init_encode_params;
105 NV_ENC_CONFIG encode_config;
106 CUcontext cu_context;
107 CUcontext cu_context_internal;
110 NvencSurface *surfaces;
112 AVFifoBuffer *unused_surface_queue;
113 AVFifoBuffer *output_surface_queue;
114 AVFifoBuffer *output_surface_ready_queue;
115 AVFifoBuffer *timestamp_list;
119 NV_ENC_REGISTERED_PTR regptr;
121 } registered_frames[MAX_REGISTERED_FRAMES];
122 int nb_registered_frames;
124 /* the actual data pixel format, different from
125 * AVCodecContext.pix_fmt when using hwaccel frames on input */
126 enum AVPixelFormat data_pix_fmt;
128 /* timestamps of the first two frames, for computing the first dts
129 * when B-frames are present */
130 int64_t initial_pts[2];
131 int first_packet_output;
164 int ff_nvenc_encode_init(AVCodecContext *avctx);
166 int ff_nvenc_encode_close(AVCodecContext *avctx);
168 int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
169 const AVFrame *frame, int *got_packet);
171 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
173 #endif /* AVCODEC_NVENC_H */