FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
nvenc.c File Reference
#include <dlfcn.h>
#include <nvEncodeAPI.h>
#include "libavutil/internal.h"
#include "libavutil/imgutils.h"
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "internal.h"
#include "thread.h"

Go to the source code of this file.

Data Structures

struct  NvencInputSurface
 
struct  NvencOutputSurface
 
struct  NvencData
 
struct  NvencDataList
 
struct  NvencDynLoadFunctions
 
struct  NvencValuePair
 
struct  NvencContext
 

Macros

#define CUDAAPI
 
#define LOAD_FUNC(l, s)   dlsym(l, s)
 
#define DL_CLOSE_FUNC(l)   dlclose(l)
 
#define CHECK_LOAD_FUNC(t, f, s)
 
#define check_cuda_errors(f)   if (!check_cuda_errors(avctx, f, #f)) goto error
 
#define OFFSET(x)   offsetof(NvencContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Typedefs

typedef int CUdevice
 
typedef voidCUcontext
 
typedef CUresult(CUDAAPIPCUINIT )(unsigned int Flags)
 
typedef CUresult(CUDAAPIPCUDEVICEGETCOUNT )(int *count)
 
typedef CUresult(CUDAAPIPCUDEVICEGET )(CUdevice *device, int ordinal)
 
typedef CUresult(CUDAAPIPCUDEVICEGETNAME )(char *name, int len, CUdevice dev)
 
typedef CUresult(CUDAAPIPCUDEVICECOMPUTECAPABILITY )(int *major, int *minor, CUdevice dev)
 
typedef CUresult(CUDAAPIPCUCTXCREATE )(CUcontext *pctx, unsigned int flags, CUdevice dev)
 
typedef CUresult(CUDAAPIPCUCTXPOPCURRENT )(CUcontext *pctx)
 
typedef CUresult(CUDAAPIPCUCTXDESTROY )(CUcontext ctx)
 
typedef NVENCSTATUS(NVENCAPI * PNVENCODEAPICREATEINSTANCE )(NV_ENCODE_API_FUNCTION_LIST *functionList)
 

Enumerations

enum  CUresult { CUDA_SUCCESS = 0 }
 

Functions

static int input_string_to_uint32 (AVCodecContext *avctx, const NvencValuePair *pair, const char *input, uint32_t *output)
 
static NvencDatadata_queue_dequeue (NvencDataList *queue)
 
static int data_queue_enqueue (NvencDataList *queue, NvencData *data)
 
static int out_surf_queue_enqueue (NvencDataList *queue, NvencOutputSurface *surface)
 
static NvencOutputSurfaceout_surf_queue_dequeue (NvencDataList *queue)
 
static int timestamp_queue_enqueue (NvencDataList *queue, int64_t timestamp)
 
static int64_t timestamp_queue_dequeue (NvencDataList *queue)
 
static av_cold int nvenc_dyload_cuda (AVCodecContext *avctx)
 
static av_cold int check_cuda_errors (AVCodecContext *avctx, CUresult err, const char *func)
 
static av_cold int nvenc_check_cuda (AVCodecContext *avctx)
 
static av_cold int nvenc_dyload_nvenc (AVCodecContext *avctx)
 
static av_cold void nvenc_unload_nvenc (AVCodecContext *avctx)
 
static av_cold int nvenc_encode_init (AVCodecContext *avctx)
 
static av_cold int nvenc_encode_close (AVCodecContext *avctx)
 
static int process_output_surface (AVCodecContext *avctx, AVPacket *pkt, AVFrame *coded_frame, NvencOutputSurface *tmpoutsurf)
 
static int nvenc_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 

Variables

static const NvencValuePair nvenc_h264_level_pairs []
 
static const NvencValuePair nvenc_hevc_level_pairs []
 
static enum AVPixelFormat pix_fmts_nvenc []
 
static const AVOption options []
 
static const AVCodecDefault nvenc_defaults []
 

Macro Definition Documentation

#define CUDAAPI

Definition at line 42 of file nvenc.c.

#define LOAD_FUNC (   l,
  s 
)    dlsym(l, s)

Definition at line 49 of file nvenc.c.

Referenced by nvenc_dyload_nvenc().

#define DL_CLOSE_FUNC (   l)    dlclose(l)

Definition at line 50 of file nvenc.c.

Referenced by nvenc_dyload_cuda(), nvenc_dyload_nvenc(), and nvenc_unload_nvenc().

#define CHECK_LOAD_FUNC (   t,
  f,
  s 
)
Value:
do { \
(f) = (t)LOAD_FUNC(dl_fn->cuda_lib, s); \
if (!(f)) { \
av_log(avctx, AV_LOG_FATAL, "Failed loading %s from CUDA library\n", s); \
goto error; \
} \
} while (0)
const char * s
Definition: avisynth_c.h:631
if()
Definition: avfilter.c:975
#define LOAD_FUNC(l, s)
Definition: nvenc.c:49
#define av_log(a,...)
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:170

Definition at line 332 of file nvenc.c.

Referenced by nvenc_dyload_cuda().

#define check_cuda_errors (   f)    if (!check_cuda_errors(avctx, f, #f)) goto error

Definition at line 389 of file nvenc.c.

Referenced by nvenc_check_cuda().

#define OFFSET (   x)    offsetof(NvencContext, x)

Definition at line 1383 of file nvenc.c.

Definition at line 1384 of file nvenc.c.

Typedef Documentation

typedef int CUdevice

Definition at line 56 of file nvenc.c.

typedef void* CUcontext

Definition at line 57 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUINIT)(unsigned int Flags)

Definition at line 59 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICEGETCOUNT)(int *count)

Definition at line 60 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICEGET)(CUdevice *device, int ordinal)

Definition at line 61 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICEGETNAME)(char *name, int len, CUdevice dev)

Definition at line 62 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev)

Definition at line 63 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev)

Definition at line 64 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUCTXPOPCURRENT)(CUcontext *pctx)

Definition at line 65 of file nvenc.c.

typedef CUresult(CUDAAPI * PCUCTXDESTROY)(CUcontext ctx)

Definition at line 66 of file nvenc.c.

typedef NVENCSTATUS(NVENCAPI* PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList)

Definition at line 68 of file nvenc.c.

Enumeration Type Documentation

enum CUresult
Enumerator
CUDA_SUCCESS 

Definition at line 53 of file nvenc.c.

Function Documentation

static int input_string_to_uint32 ( AVCodecContext avctx,
const NvencValuePair pair,
const char *  input,
uint32_t *  output 
)
static

Definition at line 219 of file nvenc.c.

Referenced by nvenc_encode_init().

static NvencData* data_queue_dequeue ( NvencDataList queue)
static

Definition at line 231 of file nvenc.c.

Referenced by data_queue_enqueue(), out_surf_queue_dequeue(), and timestamp_queue_dequeue().

static int data_queue_enqueue ( NvencDataList queue,
NvencData data 
)
static

Definition at line 251 of file nvenc.c.

Referenced by out_surf_queue_enqueue(), and timestamp_queue_enqueue().

static int out_surf_queue_enqueue ( NvencDataList queue,
NvencOutputSurface surface 
)
static

Definition at line 296 of file nvenc.c.

Referenced by nvenc_encode_frame().

static NvencOutputSurface* out_surf_queue_dequeue ( NvencDataList queue)
static

Definition at line 304 of file nvenc.c.

Referenced by nvenc_encode_frame().

static int timestamp_queue_enqueue ( NvencDataList queue,
int64_t  timestamp 
)
static

Definition at line 314 of file nvenc.c.

Referenced by nvenc_encode_frame().

static int64_t timestamp_queue_dequeue ( NvencDataList queue)
static

Definition at line 322 of file nvenc.c.

Referenced by process_output_surface().

static av_cold int nvenc_dyload_cuda ( AVCodecContext avctx)
static

Definition at line 341 of file nvenc.c.

Referenced by nvenc_check_cuda().

static av_cold int check_cuda_errors ( AVCodecContext avctx,
CUresult  err,
const char *  func 
)
static

Definition at line 381 of file nvenc.c.

static av_cold int nvenc_check_cuda ( AVCodecContext avctx)
static

Definition at line 391 of file nvenc.c.

Referenced by nvenc_dyload_nvenc().

static av_cold int nvenc_dyload_nvenc ( AVCodecContext avctx)
static

Definition at line 460 of file nvenc.c.

Referenced by nvenc_encode_init().

static av_cold void nvenc_unload_nvenc ( AVCodecContext avctx)
static

Definition at line 518 of file nvenc.c.

Referenced by nvenc_encode_close(), and nvenc_encode_init().

static av_cold int nvenc_encode_init ( AVCodecContext avctx)
static

Definition at line 543 of file nvenc.c.

static av_cold int nvenc_encode_close ( AVCodecContext avctx)
static

Definition at line 1040 of file nvenc.c.

static int process_output_surface ( AVCodecContext avctx,
AVPacket pkt,
AVFrame coded_frame,
NvencOutputSurface tmpoutsurf 
)
static

Definition at line 1070 of file nvenc.c.

Referenced by nvenc_encode_frame().

static int nvenc_encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame frame,
int *  got_packet 
)
static

Definition at line 1172 of file nvenc.c.

Variable Documentation

const NvencValuePair nvenc_h264_level_pairs[]
static
Initial value:
= {
{ "auto", NV_ENC_LEVEL_AUTOSELECT },
{ "1" , NV_ENC_LEVEL_H264_1 },
{ "1.0" , NV_ENC_LEVEL_H264_1 },
{ "1b" , NV_ENC_LEVEL_H264_1b },
{ "1.0b", NV_ENC_LEVEL_H264_1b },
{ "1.1" , NV_ENC_LEVEL_H264_11 },
{ "1.2" , NV_ENC_LEVEL_H264_12 },
{ "1.3" , NV_ENC_LEVEL_H264_13 },
{ "2" , NV_ENC_LEVEL_H264_2 },
{ "2.0" , NV_ENC_LEVEL_H264_2 },
{ "2.1" , NV_ENC_LEVEL_H264_21 },
{ "2.2" , NV_ENC_LEVEL_H264_22 },
{ "3" , NV_ENC_LEVEL_H264_3 },
{ "3.0" , NV_ENC_LEVEL_H264_3 },
{ "3.1" , NV_ENC_LEVEL_H264_31 },
{ "3.2" , NV_ENC_LEVEL_H264_32 },
{ "4" , NV_ENC_LEVEL_H264_4 },
{ "4.0" , NV_ENC_LEVEL_H264_4 },
{ "4.1" , NV_ENC_LEVEL_H264_41 },
{ "4.2" , NV_ENC_LEVEL_H264_42 },
{ "5" , NV_ENC_LEVEL_H264_5 },
{ "5.0" , NV_ENC_LEVEL_H264_5 },
{ "5.1" , NV_ENC_LEVEL_H264_51 },
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 168 of file nvenc.c.

const NvencValuePair nvenc_hevc_level_pairs[]
static
Initial value:
= {
{ "auto", NV_ENC_LEVEL_AUTOSELECT },
{ "1" , NV_ENC_LEVEL_HEVC_1 },
{ "1.0" , NV_ENC_LEVEL_HEVC_1 },
{ "2" , NV_ENC_LEVEL_HEVC_2 },
{ "2.0" , NV_ENC_LEVEL_HEVC_2 },
{ "2.1" , NV_ENC_LEVEL_HEVC_21 },
{ "3" , NV_ENC_LEVEL_HEVC_3 },
{ "3.0" , NV_ENC_LEVEL_HEVC_3 },
{ "3.1" , NV_ENC_LEVEL_HEVC_31 },
{ "4" , NV_ENC_LEVEL_HEVC_4 },
{ "4.0" , NV_ENC_LEVEL_HEVC_4 },
{ "4.1" , NV_ENC_LEVEL_HEVC_41 },
{ "5" , NV_ENC_LEVEL_HEVC_5 },
{ "5.0" , NV_ENC_LEVEL_HEVC_5 },
{ "5.1" , NV_ENC_LEVEL_HEVC_51 },
{ "5.2" , NV_ENC_LEVEL_HEVC_52 },
{ "6" , NV_ENC_LEVEL_HEVC_6 },
{ "6.0" , NV_ENC_LEVEL_HEVC_6 },
{ "6.1" , NV_ENC_LEVEL_HEVC_61 },
{ "6.2" , NV_ENC_LEVEL_HEVC_62 },
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 195 of file nvenc.c.

enum AVPixelFormat pix_fmts_nvenc[]
static
Initial value:
= {
}
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:91

Definition at line 1378 of file nvenc.c.

const AVOption options[]
static
Initial value:
= {
{ "preset", "Set the encoding preset (one of hq, hp, bd, ll, llhq, llhp, default)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "hq" }, 0, 0, VE },
{ "profile", "Set the encoding profile (high, main or baseline)", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ "level", "Set the encoding level restriction (auto, 1.0, 1.0b, 1.1, 1.2, ..., 4.2, 5.0, 5.1)", OFFSET(level), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ "tier", "Set the encoding tier (main or high)", OFFSET(tier), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
{ "cbr", "Use cbr encoding mode", OFFSET(cbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "2pass", "Use 2pass cbr encoding mode (low latency mode only)", OFFSET(twopass), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE },
{ "gpu", "Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.", OFFSET(gpu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: nvenc.c:1383
int profile
Definition: mxfenc.c:1804
#define VE
Definition: nvenc.c:1384
uint8_t level
Definition: svq3.c:150
preset
Definition: vf_curves.c:46

Definition at line 1385 of file nvenc.c.

const AVCodecDefault nvenc_defaults[]
static
Initial value:
= {
{ "b", "0" },
{ "qmin", "-1" },
{ "qmax", "-1" },
{ "qdiff", "-1" },
{ "qblur", "-1" },
{ "qcomp", "-1" },
{ NULL },
}
#define NULL
Definition: coverity.c:32

Definition at line 1396 of file nvenc.c.