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
26 #include "libavutil/hwcontext_d3d11va.h"
28 typedef void ID3D11Device;
31 #include "compat/nvenc/nvEncodeAPI.h"
33 #include "compat/cuda/dynlink_loader.h"
34 #include "libavutil/fifo.h"
35 #include "libavutil/opt.h"
39 #define MAX_REGISTERED_FRAMES 64
40 #define RC_MODE_DEPRECATED 0x800000
41 #define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED)
43 typedef struct NvencSurface
45 NV_ENC_INPUT_PTR input_surface;
47 NV_ENC_MAP_INPUT_RESOURCE in_map;
53 NV_ENC_OUTPUT_PTR output_surface;
54 NV_ENC_BUFFER_FORMAT format;
58 typedef struct NvencDynLoadFunctions
60 CudaFunctions *cuda_dl;
61 NvencFunctions *nvenc_dl;
63 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
64 int nvenc_device_count;
65 } NvencDynLoadFunctions;
75 PRESET_LOW_LATENCY_DEFAULT ,
76 PRESET_LOW_LATENCY_HQ ,
77 PRESET_LOW_LATENCY_HP,
78 PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
83 NV_ENC_H264_PROFILE_BASELINE,
84 NV_ENC_H264_PROFILE_MAIN,
85 NV_ENC_H264_PROFILE_HIGH,
86 NV_ENC_H264_PROFILE_HIGH_444P,
90 NV_ENC_HEVC_PROFILE_MAIN,
91 NV_ENC_HEVC_PROFILE_MAIN_10,
92 NV_ENC_HEVC_PROFILE_REXT,
107 typedef struct NvencContext
111 NvencDynLoadFunctions nvenc_dload_funcs;
113 NV_ENC_INITIALIZE_PARAMS init_encode_params;
114 NV_ENC_CONFIG encode_config;
115 CUcontext cu_context;
116 CUcontext cu_context_internal;
117 ID3D11Device *d3d11_device;
120 NvencSurface *surfaces;
122 AVFifoBuffer *unused_surface_queue;
123 AVFifoBuffer *output_surface_queue;
124 AVFifoBuffer *output_surface_ready_queue;
125 AVFifoBuffer *timestamp_list;
127 int encoder_flushing;
132 NV_ENC_REGISTERED_PTR regptr;
134 } registered_frames[MAX_REGISTERED_FRAMES];
135 int nb_registered_frames;
137 /* the actual data pixel format, different from
138 * AVCodecContext.pix_fmt when using hwaccel frames on input */
139 enum AVPixelFormat data_pix_fmt;
141 /* timestamps of the first two frames, for computing the first dts
142 * when B-frames are present */
143 int64_t initial_pts[2];
144 int first_packet_output;
179 int ff_nvenc_encode_init(AVCodecContext *avctx);
181 int ff_nvenc_encode_close(AVCodecContext *avctx);
183 int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame);
185 int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
187 int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
188 const AVFrame *frame, int *got_packet);
190 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
192 #endif /* AVCODEC_NVENC_H */