34 #define NVENC_CAP 0x30
35 #define IS_CBR(rc) (rc == NV_ENC_PARAMS_RC_CBR || \
36 rc == NV_ENC_PARAMS_RC_CBR_LOWDELAY_HQ || \
37 rc == NV_ENC_PARAMS_RC_CBR_HQ)
51 #define IS_10BIT(pix_fmt) (pix_fmt == AV_PIX_FMT_P010 || \
52 pix_fmt == AV_PIX_FMT_YUV444P16)
54 #define IS_YUV444(pix_fmt) (pix_fmt == AV_PIX_FMT_YUV444P || \
55 pix_fmt == AV_PIX_FMT_YUV444P16)
101 *desc =
"unknown error";
106 const char *error_string)
117 #if defined(_WIN32) || defined(__CYGWIN__)
118 const char *minver =
"378.66";
120 const char *minver =
"378.13";
122 av_log(avctx, level,
"The minimum required Nvidia driver for nvenc is %s or newer\n", minver);
130 uint32_t nvenc_max_ver;
147 av_log(avctx,
AV_LOG_VERBOSE,
"Loaded Nvenc version %d.%d\n", nvenc_max_ver >> 4, nvenc_max_ver & 0xf);
150 av_log(avctx,
AV_LOG_ERROR,
"Driver does not support the required nvenc API version. "
151 "Required: %d.%d Found: %d.%d\n",
153 nvenc_max_ver >> 4, nvenc_max_ver & 0xf);
194 int i, ret,
count = 0;
213 for (i = 0; i <
count; i++) {
267 if (ret < avctx->
width) {
274 if (ret < avctx->
height) {
281 if (ret < avctx->max_b_frames) {
291 "Interlaced encoding is not supported. Supported level: %d\n",
334 char name[128] = { 0};
335 int major, minor, ret;
347 "Cannot access the CUDA device %d\n",
364 av_log(avctx, loglevel,
"[ GPU #%d - < %s > has Compute SM %d.%d ]\n", idx, name, major, minor);
365 if (((major << 4) | minor) <
NVENC_CAP) {
366 av_log(avctx, loglevel,
"does not support NVENC\n");
375 av_log(avctx,
AV_LOG_FATAL,
"Failed creating CUDA context for NVENC: 0x%x\n", (
int)cu_res);
393 av_log(avctx, loglevel,
"supports NVENC\n");
451 device_hwctx = hwdev_ctx->
hwctx;
464 av_log(avctx,
AV_LOG_FATAL,
"Provided device doesn't support required NVENC features\n");
468 int i, nb_devices = 0;
472 "Cannot init CUDA\n");
478 "Cannot enumerate the CUDA devices\n");
490 for (i = 0; i < nb_devices; ++i) {
515 #define PRESET_ALIAS(alias, name, ...) \
516 [PRESET_ ## alias] = { NV_ENC_PRESET_ ## name ## _GUID, __VA_ARGS__ }
518 #define PRESET(name, ...) PRESET_ALIAS(name, name, __VA_ARGS__)
567 }
else if (ctx->
cqp >= 0) {
585 if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
597 qp_inter_p = (avctx->
qmax + 3 * avctx->
qmin) / 4;
598 }
else if (avctx->
qmin >= 0) {
605 qp_inter_p = avctx->
qmin;
665 if (avctx->
qmin < 0) {
667 "The variable bitrate rate-control requires "
668 "the 'qmin' option set.\n");
702 "Defined rc_lookahead requires more surfaces, "
703 "increasing used surfaces %d -> %d\n", ctx->
nb_surfaces, nb_surfaces);
710 "Defined b-frame requires more surfaces, "
711 "increasing used surfaces %d -> %d\n", ctx->
nb_surfaces, nb_surfaces);
730 av_log(avctx,
AV_LOG_WARNING,
"Using global_quality with nvenc is deprecated. Use qp instead.\n");
759 }
else if (ctx->
cqp >= 0) {
763 }
else if (avctx->
qmin >= 0 && avctx->
qmax >= 0) {
780 }
else if (ctx->
rc >= 0) {
810 "Lookahead not enabled. Increase buffer delay (-delay).\n");
817 "Lookahead enabled: depth %d, scenecut %s, B-adapt %s.\n",
838 int tmp_quality = (
int)(ctx->
quality * 256.0f);
872 if (avctx->
refs >= 0) {
960 if (avctx->
refs >= 0) {
1057 return nvenc_print_error(avctx, nv_status,
"Cannot get the preset configuration");
1069 av_reduce(&dw, &dh, dw, dh, 1024 * 1024);
1300 uint32_t outSize = 0;
1301 char tmpHeader[256];
1321 memcpy(avctx->
extradata, tmpHeader, outSize);
1412 "hw_frames_ctx must be set when using GPU frames as input\n");
1456 int dst_linesize[4] = {
1457 lock_buffer_params->
pitch,
1458 lock_buffer_params->
pitch,
1459 lock_buffer_params->
pitch,
1460 lock_buffer_params->
pitch
1466 dst_linesize[1] = dst_linesize[2] >>= 1;
1531 reg.width = frames_ctx->
width;
1532 reg.height = frames_ctx->
height;
1534 reg.resourceToRegister = frame->
data[0];
1584 nvenc_frame->
reg_idx = reg_idx;
1597 return nvenc_print_error(avctx, nv_status,
"Failed locking nvenc input buffer");
1662 if ((ts0 < 0 && ts1 > INT64_MAX + ts0) ||
1663 (ts0 > 0 && ts1 < INT64_MIN + ts0))
1667 if ((delta < 0 && ts0 > INT64_MAX + delta) ||
1668 (delta > 0 && ts0 < INT64_MIN + delta))
1687 uint32_t slice_mode_data;
1688 uint32_t *slice_offsets =
NULL;
1707 slice_offsets =
av_mallocz(slice_mode_data *
sizeof(*slice_offsets));
1733 nvenc_print_error(avctx, nv_status,
"Failed unlocking bitstream buffer, expect the gates of mordor to open");
1760 av_log(avctx,
AV_LOG_ERROR,
"Unknown picture type encountered, expect the output to be broken.\n");
1761 av_log(avctx,
AV_LOG_ERROR,
"Please report this error and include as much information on how to reproduce it as possible.\n");
1766 #if FF_API_CODED_FRAME
1795 int nb_ready, nb_pending;
1806 return nb_ready > 0;
1807 return (nb_ready > 0) && (nb_ready + nb_pending >= ctx->
async_depth);
1981 }
else if (res < 0) {
#define FF_PROFILE_H264_MAIN
uint32_t version
[in]: Struct version.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
PNVENCGETENCODEGUIDS nvEncGetEncodeGUIDs
[out]: Client should access NvEncGetEncodeGUIDs() API through this pointer.
uint32_t idrPeriod
[in]: Specifies the IDR interval.
tcuDeviceGetName * cuDeviceGetName
const struct AVCodec * codec
const char const char void * val
PNVENCCREATEBITSTREAMBUFFER nvEncCreateBitstreamBuffer
[out]: Client should access NvEncCreateBitstreamBuffer() API through this pointer.
av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
static enum AVPixelFormat pix_fmt
uint32_t vbvBufferSize
[in]: Specifies the VBV(HRD) buffer size.
Field encoding bottom field first.
NV_ENC_BUFFER_FORMAT format
NV_ENC_QP constQP
[in]: Specifies the initial QP to be used for encoding, these values would be used for all frames if ...
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
struct NvencContext::@101 registered_frames[MAX_REGISTERED_FRAMES]
This structure describes decoded (raw) audio or video data.
static av_cold int nvenc_setup_codec_config(AVCodecContext *avctx)
AVFifoBuffer * timestamp_list
uint32_t encodeWidth
[in]: Specifies the encode width.
uint32_t enableTemporalAQ
[in]: Set this to 1 to enable temporal AQ for H.264
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
static void flush(AVCodecContext *avctx)
This indicates that the HW encoder is busy encoding and is unable to encode the input.
static const GUID NV_ENC_H264_PROFILE_HIGH_444_GUID
NvencFunctions * nvenc_dl
static const GUID NV_ENC_HEVC_PROFILE_MAIN10_GUID
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static av_cold void set_vbr(AVCodecContext *avctx)
Indicates end of the input stream.
This indicates that the NvEncRegisterResource API failed to register the resource.
GUID presetGUID
[in]: Specifies the preset for encoding.
void * device
[in]: Pointer to client device.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Indicates HW support for Weighted Predicition.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
#define RC_MODE_DEPRECATED
Memory handling functions.
#define NV_ENC_SEQUENCE_PARAM_PAYLOAD_VER
Macro for constructing the version field of _NV_ENC_SEQUENCE_PARAM_PAYLOAD.
static av_cold int nvenc_setup_device(AVCodecContext *avctx)
void * outputBitstream
[in]: Pointer to the bitstream buffer being locked.
uint32_t * sliceOffsets
[in,out]: Array which receives the slice offsets.
uint32_t inBufferSize
[in]: Specifies the size of the spsppsBuffer provied by the client
int max_bitrate
Maximum bitrate of the stream, in bits per second.
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
NV_ENC_CONFIG_H264 h264Config
[in]: Specifies the H.264-specific encoder configuration.
NV_ENC_MAP_INPUT_RESOURCE in_map
enum AVColorRange color_range
MPEG vs JPEG YUV range.
PNVENCGETENCODECAPS nvEncGetEncodeCaps
[out]: Client should access NvEncGetEncodeCaps() API through this pointer.
#define NV_ENC_CREATE_INPUT_BUFFER_VER
NV_ENC_CREATE_INPUT_BUFFER struct version.
uint32_t chromaFormatIDC
[in]: Specifies the chroma format.
#define PRESET_ALIAS(alias, name,...)
static av_cold int nvenc_setup_surfaces(AVCodecContext *avctx)
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs
NV_ENC_OUTPUT_PTR bitstreamBuffer
[out]: Pointer to the output bitstream buffer
VBR, high quality (slower)
NvencDynLoadFunctions nvenc_dload_funcs
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
int width
The allocated dimensions of the frames in this pool.
NV_ENCODE_API_FUNCTION_LIST.
This indicates that one or more of the parameter passed to the API call is invalid.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint32_t qpPrimeYZeroTransformBypassFlag
[in]: To enable lossless encode set this to 1, set QP to 0 and RC_mode to NV_ENC_PARAMS_RC_CONSTQP an...
This indicates that the encoder device supplied by the client is not valid.
This indicates that an unknown internal error has occurred.
int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
static const GUID NV_ENC_HEVC_PROFILE_FREXT_GUID
NV_ENC_H264_ADAPTIVE_TRANSFORM_MODE adaptiveTransformMode
[in]: Specifies the AdaptiveTransform Mode.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_cold int nvenc_recalc_surfaces(AVCodecContext *avctx)
NV_ENC_CODEC_PIC_PARAMS codecPicParams
[in]: Specifies the codec specific per-picture encoding parameters.
uint32_t enableAQ
[in]: Set this to 1 to enable adaptive quantization (Spatial).
NV_ENC_PARAMS_FRAME_FIELD_MODE frameFieldMode
[in]: Specifies the frame/field mode.
float i_quant_offset
qscale offset between P and I-frames
static void nvenc_override_rate_control(AVCodecContext *avctx)
static NvencSurface * get_free_frame(NvencContext *ctx)
static av_cold void nvenc_setup_rate_control(AVCodecContext *avctx)
NV_ENC_QP maxQP
[in]: Specifies the maximum QP used for rate control.
PNVENCUNLOCKINPUTBUFFER nvEncUnlockInputBuffer
[out]: Client should access NvEncUnlockInputBuffer() API through this pointer.
10 bit Planar YUV444 [Y plane followed by U and V planes].
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
NV_ENC_INPUT_PTR input_surface
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static const GUID NV_ENC_H264_PROFILE_MAIN_GUID
NV_ENC_QP initialRCQP
[in]: Specifies the initial QP used for rate control.
Bi-directionally predicted with only Intra MBs.
NV_ENC_PARAMS_RC_MODE rateControlMode
[in]: Specifies the rate control mode.
This indicates that an invalid struct version was used by the client.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
PNVENCDESTROYINPUTBUFFER nvEncDestroyInputBuffer
[out]: Client should access NvEncDestroyInputBuffer() API through this pointer.
This indicates that API call returned with no errors.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
uint32_t strictGOPTarget
[in]: Set this to 1 to minimize GOP-to-GOP rate fluctuations
NV_ENC_CONFIG_H264_VUI_PARAMETERS h264VUIParameters
[in]: Specifies the H264 video usability info pamameters
#define FF_PROFILE_H264_BASELINE
PNVENCCREATEINPUTBUFFER nvEncCreateInputBuffer
[out]: Client should access NvEncCreateInputBuffer() API through this pointer.
NV_ENC_CONFIG * encodeConfig
[in]: Specifies the advanced codec specific structure.
AVFifoBuffer * unused_surface_queue
uint32_t inputWidth
[in]: Specifies the input buffer width
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Indicates HW support for field mode encoding.
PNVENCGETENCODEGUIDCOUNT nvEncGetEncodeGUIDCount
[out]: Client should access NvEncGetEncodeGUIDCount() API through this pointer.
enum AVPixelFormat ff_nvenc_pix_fmts[]
NV_ENC_PIC_PARAMS_HEVC hevcPicParams
[in]: HEVC encode picture params.
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
PNVENCLOCKBITSTREAM nvEncLockBitstream
[out]: Client should access NvEncLockBitstream() API through this pointer.
Indicates HW support for 10 bit encoding.
uint32_t colourMatrix
[in]: Specifies the matrix coefficients used in deriving the luma and chroma from the RGB primaries (...
#define FF_PROFILE_HEVC_MAIN
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Input struct for querying Encoding capabilities.
Field encoding top field first.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER
Macro for constructing the version field of ::_NV_ENC_OPEN_ENCODE_SESSIONEX_PARAMS.
static void cuda_free_functions(CudaFunctions **functions)
NV_ENC_INITIALIZE_PARAMS init_encode_params
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
uint32_t maxNumRefFrames
[in]: Specifies the DPB size used for encoding.
static av_cold int nvenc_alloc_surface(AVCodecContext *avctx, int idx)
NV_ENC_OUTPUT_PTR outputBitstream
[in]: Specifies the pointer to output buffer.
uint32_t outputBufferingPeriodSEI
[in]: Set to 1 to write SEI buffering period syntax in the bitstream
This indicates encode driver requires more input buffers to produce an output bitstream.
#define MAX_REGISTERED_FRAMES
Indicates HW support for lossless encoding.
static av_cold int nvenc_setup_extradata(AVCodecContext *avctx)
This indicates that the client is attempting to use a feature that is not available for the license t...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
Encode the current picture as an Intra picture.
Encode the current picture as an IDR picture.
NV_ENC_BUFFER_FORMAT
Input buffer formats.
static int nvenc_check_capabilities(AVCodecContext *avctx)
#define AV_PIX_FMT_YUV444P16
static int nvenc_register_frame(AVCodecContext *avctx, const AVFrame *frame)
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
uint8_t targetQuality
[in]: Target CQ (Constant Quality) level for VBR mode (range 0-51 with 0-automatic) ...
#define FF_PROFILE_HEVC_MAIN_10
tcuCtxPushCurrent_v2 * cuCtxPushCurrent
This indicates that the completion event passed in NvEncEncodePicture() API has not been registered w...
#define NV_ENC_MAP_INPUT_RESOURCE_VER
Macro for constructing the version field of _NV_ENC_MAP_INPUT_RESOURCE.
uint32_t * outSPSPPSPayloadSize
[out]: Size of the sequence and picture header in bytes written by the NvEncodeAPI interface to the S...
AVFifoBuffer * output_surface_ready_queue
uint32_t apiVersion
[in]: API version.
uint32_t version
[in]: Struct version.
This indicates that the NvEncLockBitstream() failed to lock the output buffer.
uint32_t enableInitialRCQP
[in]: Set this to 1 if user suppplied initial QP is used for rate control.
PNVENCLOCKINPUTBUFFER nvEncLockInputBuffer
[out]: Client should access NvEncLockInputBuffer() API through this pointer.
CUcontext cu_context_internal
An API-specific header for AV_HWDEVICE_TYPE_CUDA.
uint8_t targetQualityLSB
[in]: Fractional part of target quality (as 8.8 fixed point format)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint32_t outputBufferingPeriodSEI
[in]: Set 1 to write SEI buffering period syntax in the bitstream
uint32_t inputPitch
[in]: Specifies the input buffer pitch.
uint32_t outputPictureTimingSEI
[in]: Set 1 to write SEI picture timing syntax in the bitstream
uint32_t disableIadapt
[in]: Set this to 1 to disable adaptive I-frame insertion at scene cuts (only has an effect when look...
PNVENCGETSEQUENCEPARAMS nvEncGetSequenceParams
[out]: Client should access NvEncGetSequenceParams() API through this pointer.
NV_ENC_H264_ENTROPY_CODING_MODE entropyCodingMode
[in]: Specifies the entropy coding mode.
uint32_t colourPrimaries
[in]: Specifies color primaries for converting to RGB(as defined in Annex E of the ITU-T Specificatio...
static av_cold int nvenc_open_session(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
static const GUID NV_ENC_CODEC_H264_GUID
Indicates HW support for lookahead encoding (enableLookahead=1).
input resource type is a cuda device pointer surface
static void timestamp_queue_enqueue(AVFifoBuffer *queue, int64_t timestamp)
NV_ENC_CONFIG presetCfg
[out]: preset config returned by the Nvidia Video Encoder interface.
uint32_t chromaFormatIDC
[in]: Specifies the chroma format.
#define NV_ENC_LOCK_BITSTREAM_VER
Macro for constructing the version field of _NV_ENC_LOCK_BITSTREAM.
uint32_t colourDescriptionPresentFlag
[in]: If set to 1, it specifies that the colourPrimaries, transferCharacteristics and colourMatrix ar...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int qmax
maximum quantizer
This indicates that the size of the user buffer passed by the client is insufficient for the requeste...
uint64_t inputTimeStamp
[in]: Specifies presentation timestamp associated with the input picture.
uint32_t disableBadapt
[in]: Set this to 1 to disable adaptive B-frame decision (only has an effect when lookahead is enable...
static int nvenc_map_error(NVENCSTATUS err, const char **desc)
NV_ENC_CAPS capsToQuery
[in]: Specifies the encode capability to be queried.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
static const GUID NV_ENC_H264_PROFILE_BASELINE_GUID
uint32_t videoFullRangeFlag
[in]: Specifies the output range of the luma and chroma samples(as defined in Annex E of the ITU-T Sp...
#define FF_PROFILE_H264_HIGH
int flags
AV_CODEC_FLAG_*.
uint32_t bitstreamSizeInBytes
[out]: Actual number of bytes generated and copied to the memory pointed by bitstreamBufferPtr.
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_PIX_FMT_0BGR32
PNVENCGETENCODEPRESETCONFIG nvEncGetEncodePresetConfig
[out]: Client should access NvEncGetEncodePresetConfig() API through this pointer.
This indicates that the client is attempting to unregister a resource that has not been successfully ...
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
uint32_t maxNumRefFramesInDPB
[in]: Specifies the maximum number of references frames in the DPB.
uint32_t averageBitRate
[in]: Specifies the average bitrate(in bits/sec) used for encoding.
int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame)
static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
static NV_ENC_BUFFER_FORMAT nvenc_map_buffer_format(enum AVPixelFormat pix_fmt)
NV_ENC_PIC_PARAMS_H264 h264PicParams
[in]: H264 encode picture params.
static av_cold void set_constqp(AVCodecContext *avctx)
PNVENCREGISTERRESOURCE nvEncRegisterResource
[out]: Client should access NvEncRegisterResource() API through this pointer.
static void * av_mallocz_array(size_t nmemb, size_t size)
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
uint32_t videoSignalTypePresentFlag
[in]: If set to 1, it specifies that the videoFormat, videoFullRangeFlag and colourDescriptionPresent...
int flags
A combination of AV_PKT_FLAG values.
Encoder Session Creation parameters.
int rc_buffer_size
decoder bitstream buffer size
static int nvenc_check_codec_support(AVCodecContext *avctx)
uint32_t enableWeightedPrediction
[in]: Set this to 1 to enable weighted prediction.
uint32_t version
[in]: Struct version.
GUID profileGUID
[in]: Specifies the codec profile guid.
uint32_t pixelBitDepthMinus8
[in]: Specifies pixel bit depth minus 8.
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
PNVENCENCODEPICTURE nvEncEncodePicture
[out]: Client should access NvEncEncodePicture() API through this pointer.
int refs
number of reference frames
uint32_t version
[in]: Struct version.
#define NVENCAPI_MAJOR_VERSION
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
This indicates that the client is attempting to use a feature that is not implemented for the current...
enum AVPictureType pict_type
Picture type of the frame.
10 bit Semi-Planar YUV [Y plane followed by interleaved UV plane].
static int nvenc_upload_frame(AVCodecContext *avctx, const AVFrame *frame, NvencSurface *nvenc_frame)
tcuCtxCreate_v2 * cuCtxCreate
uint32_t repeatSPSPPS
[in]: Set to 1 to enable writing of Sequence and Picture parameter for every IDR frame ...
NV_ENC_REGISTERED_PTR regptr
static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
PNVENCOPENENCODESESSIONEX nvEncOpenEncodeSessionEx
[out]: Client should access NvEncOpenEncodeSession() API through this pointer.
NV_ENC_QP minQP
[in]: Specifies the minimum QP used for rate control.
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
uint32_t encodePicFlags
[in]: Specifies bit-wise OR`ed encode pic flags.
This indicates that device passed to the API call is invalid.
av_cold int ff_nvenc_encode_init(AVCodecContext *avctx)
This indicates that the client is attempting to unmap a resource that has not been successfully mappe...
static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencSurface *tmpoutsurf)
Maximum output height supported.
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Entropy coding mode is CABAC.
int width
picture width / height.
uint32_t idrPeriod
[in]: Specifies the IDR interval.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
uint32_t version
[in]: Struct version.
uint16_t lookaheadDepth
[in]: Maximum depth of lookahead with range 0-32 (only used if enableLookahead=1) ...
tNvEncodeAPICreateInstance * NvEncodeAPICreateInstance
uint32_t aqStrength
[in]: When AQ (Spatial) is enabled (i.e.
uint32_t version
[in]: Struct version.
#define NV_ENCODE_API_FUNCTION_LIST_VER
Macro for constructing the version field of ::_NV_ENCODEAPI_FUNCTION_LIST.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
uint32_t zeroReorderDelay
[in]: Set this to 1 to indicate zero latency operation (no reordering delay, num_reorder_frames=0) ...
Maximum output width supported.
static int nvenc_copy_frame(AVCodecContext *avctx, NvencSurface *nv_surface, NV_ENC_LOCK_INPUT_BUFFER *lock_buffer_params, const AVFrame *frame)
#define IS_YUV444(pix_fmt)
static int cuda_load_functions(CudaFunctions **functions)
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
PNVENCDESTROYBITSTREAMBUFFER nvEncDestroyBitstreamBuffer
[out]: Client should access NvEncDestroyBitstreamBuffer() API through this pointer.
AVFifoBuffer * output_surface_queue
#define NV_ENC_INITIALIZE_PARAMS_VER
macro for constructing the version field of _NV_ENC_INITIALIZE_PARAMS
#define NV_ENC_PRESET_CONFIG_VER
macro for constructing the version field of _NV_ENC_PRESET_CONFIG
uint32_t maxBitRate
[in]: Specifies the maximum bitrate for the encoded output.
static void nvenc_print_driver_requirement(AVCodecContext *avctx, int level)
uint32_t enableLookahead
[in]: Set this to 1 to enable lookahead with depth <lookaheadDepth> (if lookahead is enabled...
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
HW acceleration through CUDA.
static void error(const char *err)
static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
#define FF_ARRAY_ELEMS(a)
the normal 2^n-1 "JPEG" YUV ranges
uint32_t level
[in]: Specifies the encoding level.
static int nvenc_print_error(void *log_ctx, NVENCSTATUS err, const char *error_string)
enum AVPixelFormat data_pix_fmt
#define IS_10BIT(pix_fmt)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define NV_ENC_CAPS_PARAM_VER
NV_ENC_CAPS_PARAM struct version.
PNVENCUNREGISTERRESOURCE nvEncUnregisterResource
[out]: Client should access NvEncUnregisterResource() API through this pointer.
uint32_t inputHeight
[in]: Specifies the input buffer height
This structure describes the bitrate properties of an encoded bitstream.
static void nvenc_free_functions(NvencFunctions **functions)
#define AV_LOG_INFO
Standard information.
NV_ENC_CONFIG encode_config
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
uint32_t outputPictureTimingSEI
[in]: Set to 1 to write SEI picture timing syntax in the bitstream.
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
uint32_t doNotWait
[in]: If this flag is set, the NvEncodeAPI interface will return buffer pointer even if operation is ...
PNVENCMAPINPUTRESOURCE nvEncMapInputResource
[out]: Client should access NvEncMapInputResource() API through this pointer.
encode device type is a cuda device
void * bitstreamBufferPtr
[out]: Pointer to the generated output bitstream.
Creation parameters for output bitstream buffer.
NV_ENC_H264_FMO_MODE fmoMode
[in]: Specified the FMO Mode.
main external API structure.
uint32_t frameRateNum
[in]: Specifies the numerator for frame rate used for encoding in frames per second ( Frame rate = fr...
uint8_t * data
The data buffer.
int qmin
minimum quantizer
uint32_t frameAvgQP
[out]: Average QP of the frame.
uint32_t disableSPSPPS
[in]: Set 1 to disable VPS,SPS and PPS signalling in the bitstream.
Rate Control Configuration Paramters.
Indicates HW support for temporal AQ encoding (enableTemporalAQ=1).
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
NV_ENC_RC_PARAMS rcParams
[in]: Specifies the rate control parameters for the current encoding session.
This struct is allocated as AVHWDeviceContext.hwctx.
static int nvenc_check_cap(AVCodecContext *avctx, NV_ENC_CAPS cap)
This indicates that one or more of the pointers passed to the API call is invalid.
GUID encodeGUID
[in]: Specifies the Encode GUID for which the encoder is being created.
NV_ENC_INPUT_PTR inputBuffer
[in]: Specifies the input buffer pointer.
uint32_t level
[in]: Specifies the level of the encoded bitstream.
uint32_t transferCharacteristics
[in]: Specifies the opto-electronic transfer characteristics to use (as defined in Annex E of the ITU...
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
This struct describes a set or pool of "hardware" frames (i.e.
This indicates that an API call was made in wrong sequence/order.
Indicates HW support for YUV444 mode encoding.
#define NV_ENC_PIC_PARAMS_VER
Macro for constructing the version field of _NV_ENC_PIC_PARAMS.
static void nvenc_codec_specific_pic_params(AVCodecContext *avctx, NV_ENC_PIC_PARAMS *params)
float b_quant_offset
qscale offset between IP and B-frames
static const struct @95 nvenc_errors[]
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
PNVENCUNMAPINPUTRESOURCE nvEncUnmapInputResource
[out]: Client should access NvEncUnmapInputResource() API through this pointer.
static int nvenc_find_free_reg_resource(AVCodecContext *avctx)
uint32_t frameRateDen
[in]: Specifies the denominator for frame rate used for encoding in frames per second ( Frame rate = ...
NV_ENC_CONFIG_HEVC_VUI_PARAMETERS hevcVUIParameters
[in]: Specifies the HEVC video usability info pamameters
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
NV_ENC_CONFIG_HEVC hevcConfig
[in]: Specifies the HEVC-specific encoder configuration.
int global_quality
Global quality for codecs which cannot change it per frame.
uint32_t gopLength
[in]: Specifies the number of pictures in one GOP.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
uint64_t outputTimeStamp
[out]: Presentation timestamp associated with the encoded output.
This indicates that devices pass by the client is not supported.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
tcuDeviceGetCount * cuDeviceGetCount
#define NVENCAPI_MINOR_VERSION
static const GUID NV_ENC_HEVC_PROFILE_MAIN_GUID
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
NV_ENC_CAPS
Encoder capabilities enumeration.
uint32_t sliceMode
[in]: This parameter in conjunction with sliceModeData specifies the way in which the picture is divi...
Bi-directionally predicted picture.
This indicates that completion event passed in NvEncEncodePicture() call is invalid.
NV_ENC_PIC_TYPE pictureType
[out]: Picture type of the encoded picture.
#define NV_ENC_REGISTER_RESOURCE_VER
Macro for constructing the version field of _NV_ENC_REGISTER_RESOURCE.
static int64_t timestamp_queue_dequeue(AVFifoBuffer *queue)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
uint32_t tier
[in]: Specifies the level tier of the encoded bitstream.
This indicates that an unsupported parameter was passed by the client.
NV_ENC_DEVICE_TYPE deviceType
[in]: Specified the device Type
static int output_ready(AVCodecContext *avctx, int flush)
uint32_t version
[in]: Struct version.
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
PNVENCDESTROYENCODER nvEncDestroyEncoder
[out]: Client should access NvEncDestroyEncoder() API through this pointer.
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
NV_ENC_PIC_STRUCT pictureStruct
[in]: Specifies structure of the input picture.
#define NV_ENC_PARAMS_RC_VBR_MINQP
Deprecated.
tcuCtxPopCurrent_v2 * cuCtxPopCurrent
static const GUID NV_ENC_CODEC_HEVC_GUID
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
uint32_t outputAUD
[in]: Set 1 to write Access Unit Delimiter syntax.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
#define NV_ENC_BUFFER_FORMAT_YV12_PL
uint32_t darWidth
[in]: Specifies the display aspect ratio Width.
#define FF_PROFILE_HEVC_REXT
tcuDeviceComputeCapability * cuDeviceComputeCapability
static int nvenc_set_timestamp(AVCodecContext *avctx, NV_ENC_LOCK_BITSTREAM *params, AVPacket *pkt)
#define FF_ENABLE_DEPRECATION_WARNINGS
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int top_field_first
If the content is interlaced, is top field displayed first.
uint32_t repeatSPSPPS
[in]: Set 1 to output VPS,SPS and PPS for every IDR frame.
static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
static av_cold int nvenc_check_device(AVCodecContext *avctx, int idx)
int avg_bitrate
Average bitrate of the stream, in bits per second.
#define NV_ENC_BUFFER_FORMAT_NV12_PL
uint32_t enableMaxQP
[in]: Set this to 1 if maximum QP used for rate control.
uint32_t sliceModeData
[in]: Specifies the parameter needed for sliceMode.
low-delay CBR, high quality
uint32_t darHeight
[in]: Specifies the display aspect ratio height.
uint32_t enableEncodeAsync
[in]: Set this to 1 to enable asynchronous mode and is expected to use events to get picture completi...
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define NV_ENC_CREATE_BITSTREAM_BUFFER_VER
NV_ENC_CREATE_BITSTREAM_BUFFER struct version.
tcuCtxDestroy_v2 * cuCtxDestroy
static const GUID NV_ENC_H264_PROFILE_HIGH_GUID
int32_t frameIntervalP
[in]: Specifies the GOP pattern as follows: frameIntervalP = 0: I, 1: IPP, 2: IBP, 3: IBBP If goplength is set to NVENC_INFINITE_GOPLENGTH frameIntervalP should be set to 1.
NV_ENC_BUFFER_FORMAT bufferFmt
[in]: Specifies the input buffer format.
#define NV_ENC_CONFIG_VER
macro for constructing the version field of _NV_ENC_CONFIG
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
PNVENCINITIALIZEENCODER nvEncInitializeEncoder
[out]: Client should access NvEncInitializeEncoder() API through this pointer.
uint32_t enablePTD
[in]: Set this to 1 to enable the Picture Type Decision is be taken by the NvEncodeAPI interface...
static av_cold void set_lossless(AVCodecContext *avctx)
uint32_t version
[in]: Struct version.
uint32_t outputAUD
[in]: Set to 1 to write access unit delimiter syntax in bitstream
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
uint32_t enableMinQP
[in]: Set this to 1 if minimum QP used for rate control.
CBR, high quality (slower)
PNVENCUNLOCKBITSTREAM nvEncUnlockBitstream
[out]: Client should access NvEncUnlockBitstream() API through this pointer.
#define FFSWAP(type, a, b)
#define NV_ENC_BUFFER_FORMAT_YUV444_PL
uint32_t encodeHeight
[in]: Specifies the encode height.
uint32_t enableNonRefP
[in]: Set this to 1 to enable automatic insertion of non-reference P-frames (no effect if enablePTD=0...
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
#define NV_ENC_LOCK_INPUT_BUFFER_VER
Macro for constructing the version field of _NV_ENC_LOCK_INPUT_BUFFER.
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
void * spsppsBuffer
[in]: Specifies bitstream header pointer of size NV_ENC_SEQUENCE_PARAM_PAYLOAD::inBufferSize.
tcuDeviceGet * cuDeviceGet
uint32_t videoFormat
[in]: Specifies the source video format(as defined in Annex E of the ITU-T Specification).
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
tNvEncodeAPIGetMaxSupportedVersion * NvEncodeAPIGetMaxSupportedVersion
uint32_t version
[in]: Client should pass NV_ENCODE_API_FUNCTION_LIST_VER.
This indicates that the encoder has not been initialized with NvEncInitializeEncoder() or that initia...
uint32_t version
[in]: Struct version.
NV_ENC_OUTPUT_PTR output_surface
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint32_t disableSPSPPS
[in]: Set to 1 to disable writing of Sequence and Picture parameter info in bitstream ...
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void nvenc_map_preset(NvencContext *ctx)
This indicates that device passed to the API call is no longer available and needs to be reinitialize...
This indicates that no encode capable devices were detected.
#define AV_PIX_FMT_0RGB32
int64_t rc_max_rate
maximum bitrate
Maximum number of B-Frames supported.
This indicates that NvEncMapInputResource() API failed to map the client provided input resource...
NV_ENC_CODEC_CONFIG encodeCodecConfig
[in]: Specifies the codec specific config parameters through this union.
static int nvenc_load_functions(NvencFunctions **functions)
This indicates that the API call failed because it was unable to allocate enough memory to perform th...
Adaptive Transform 8x8 mode should be used.