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>
25 #include "libavutil/fifo.h"
26 #include "libavutil/opt.h"
30 typedef struct NVENCInputSurface {
32 NV_ENC_BUFFER_FORMAT format;
36 typedef struct NVENCOutputSurface {
37 NV_ENC_OUTPUT_PTR out;
38 NVENCInputSurface *in;
42 typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags);
43 typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count);
44 typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal);
45 typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev);
46 typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev);
47 typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev);
48 typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
49 typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
51 typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
53 typedef struct NVENCLibraryContext
59 PCUDEVICEGETCOUNT cu_device_get_count;
60 PCUDEVICEGET cu_device_get;
61 PCUDEVICEGETNAME cu_device_get_name;
62 PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability;
63 PCUCTXCREATE cu_ctx_create;
64 PCUCTXPOPCURRENT cu_ctx_pop_current;
65 PCUCTXDESTROY cu_ctx_destroy;
67 NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
68 } NVENCLibraryContext;
75 PRESET_LOW_LATENCY_DEFAULT ,
76 PRESET_LOW_LATENCY_HQ ,
77 PRESET_LOW_LATENCY_HP,
78 PRESET_LOSSLESS_DEFAULT,
83 NV_ENC_H264_PROFILE_BASELINE,
84 NV_ENC_H264_PROFILE_MAIN,
85 NV_ENC_H264_PROFILE_HIGH,
86 NV_ENC_H264_PROFILE_HIGH_444,
87 NV_ENC_H264_PROFILE_CONSTRAINED_HIGH,
100 typedef struct NVENCContext {
102 NVENCLibraryContext nvel;
104 NV_ENC_INITIALIZE_PARAMS params;
105 NV_ENC_CONFIG config;
107 CUcontext cu_context;
110 NVENCInputSurface *in;
111 NVENCOutputSurface *out;
112 AVFifoBuffer *timestamps;
113 AVFifoBuffer *pending, *ready;
128 int ff_nvenc_encode_init(AVCodecContext *avctx);
130 int ff_nvenc_encode_close(AVCodecContext *avctx);
132 int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
133 const AVFrame *frame, int *got_packet);
135 #endif /* AVCODEC_NVENC_H */