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
33 #define RC_MODE_DEPRECATED 0x800000
34 #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED)
36 typedef struct NvencSurface
38 NV_ENC_INPUT_PTR input_surface;
40 NV_ENC_MAP_INPUT_RESOURCE in_map;
46 NV_ENC_OUTPUT_PTR output_surface;
47 NV_ENC_BUFFER_FORMAT format;
51 typedef struct NvencDynLoadFunctions
53 CudaFunctions *cuda_dl;
54 NvencFunctions *nvenc_dl;
56 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
57 int nvenc_device_count;
58 } NvencDynLoadFunctions;
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
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,
83 NV_ENC_HEVC_PROFILE_MAIN,
84 NV_ENC_HEVC_PROFILE_MAIN_10,
85 NV_ENC_HEVC_PROFILE_REXT,
100 typedef struct NvencContext
104 NvencDynLoadFunctions nvenc_dload_funcs;
106 NV_ENC_INITIALIZE_PARAMS init_encode_params;
107 NV_ENC_CONFIG encode_config;
108 CUcontext cu_context;
109 CUcontext cu_context_internal;
112 NvencSurface *surfaces;
114 AVFifoBuffer *unused_surface_queue;
115 AVFifoBuffer *output_surface_queue;
116 AVFifoBuffer *output_surface_ready_queue;
117 AVFifoBuffer *timestamp_list;
119 int encoder_flushing;
123 NV_ENC_REGISTERED_PTR regptr;
125 } registered_frames[MAX_REGISTERED_FRAMES];
126 int nb_registered_frames;
128 /* the actual data pixel format, different from
129 * AVCodecContext.pix_fmt when using hwaccel frames on input */
130 enum AVPixelFormat data_pix_fmt;
132 /* timestamps of the first two frames, for computing the first dts
133 * when B-frames are present */
134 int64_t initial_pts[2];
135 int first_packet_output;
170 int ff_nvenc_encode_init(AVCodecContext *avctx);
172 int ff_nvenc_encode_close(AVCodecContext *avctx);
174 int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame);
176 int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
178 int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
179 const AVFrame *frame, int *got_packet);
181 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
183 #endif /* AVCODEC_NVENC_H */