2 * This file is part of Libav.
4 * Libav 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 * Libav 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 Libav; 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
23 #include <nvEncodeAPI.h>
27 #include "libavutil/fifo.h"
28 #include "libavutil/opt.h"
32 #define MAX_REGISTERED_FRAMES 64
34 typedef struct NVENCFrame {
37 NV_ENC_MAP_INPUT_RESOURCE in_map;
40 NV_ENC_OUTPUT_PTR out;
41 NV_ENC_BUFFER_FORMAT format;
45 typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
46 typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
47 typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
48 typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
49 typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
50 typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
51 typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
52 typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
54 typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
56 typedef struct NVENCLibraryContext
64 PCUDEVICEGETCOUNT cu_device_get_count;
65 PCUDEVICEGET cu_device_get;
66 PCUDEVICEGETNAME cu_device_get_name;
67 PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
68 PCUCTXCREATE cu_ctx_create;
69 PCUCTXPOPCURRENT cu_ctx_pop_current;
70 PCUCTXDESTROY cu_ctx_destroy;
72 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
73 } NVENCLibraryContext;
80 PRESET_LOW_LATENCY_DEFAULT ,
81 PRESET_LOW_LATENCY_HQ ,
82 PRESET_LOW_LATENCY_HP,
83 PRESET_LOSSLESS_DEFAULT,
88 NV_ENC_H264_PROFILE_BASELINE,
89 NV_ENC_H264_PROFILE_MAIN,
90 NV_ENC_H264_PROFILE_HIGH,
91 NV_ENC_H264_PROFILE_HIGH_444,
92 NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
105 typedef struct NVENCContext {
107 NVENCLibraryContext nvel;
109 NV_ENC_INITIALIZE_PARAMS params;
110 NV_ENC_CONFIG config;
112 CUcontext cu_context;
113 CUcontext cu_context_internal;
117 AVFifoBuffer *timestamps;
118 AVFifoBuffer *pending, *ready;
122 NV_ENC_REGISTERED_PTR regptr;
124 } registered_frames[MAX_REGISTERED_FRAMES];
125 int nb_registered_frames;
127 /* the actual data pixel format, different from
128 * AVCodecContext.pix_fmt when using hwaccel frames on input */
129 enum AVPixelFormat data_pix_fmt;
131 /* timestamps of the first two frames, for computing the first dts
132 * when b-frames are present */
133 int64_t initial_pts[2];
134 int first_packet_output;
147 int ff_nvenc_encode_init(AVCodecContext *avctx);
149 int ff_nvenc_encode_close(AVCodecContext *avctx);
151 int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
152 const AVFrame *frame, int *got_packet);
154 extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
156 #endif /* AVCODEC_NVENC_H */