2016-05-25 13:04:28 +00:00
|
|
|
/*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVCODEC_NVENC_H
|
|
|
|
#define AVCODEC_NVENC_H
|
|
|
|
|
2017-11-25 23:05:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2017-11-15 18:15:23 +00:00
|
|
|
#if CONFIG_D3D11VA
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "libavutil/hwcontext_d3d11va.h"
|
|
|
|
#else
|
|
|
|
typedef void ID3D11Device;
|
|
|
|
#endif
|
|
|
|
|
2018-02-26 00:20:51 +00:00
|
|
|
#include <ffnvcodec/nvEncodeAPI.h>
|
2016-05-25 13:04:28 +00:00
|
|
|
|
2016-10-10 10:55:59 +00:00
|
|
|
#include "compat/cuda/dynlink_loader.h"
|
2016-05-25 13:04:28 +00:00
|
|
|
#include "libavutil/fifo.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
|
|
|
#include "avcodec.h"
|
|
|
|
|
|
|
|
#define MAX_REGISTERED_FRAMES 64
|
2017-05-09 11:57:39 +00:00
|
|
|
#define RC_MODE_DEPRECATED 0x800000
|
|
|
|
#define RCD(rc_mode) ((rc_mode) | RC_MODE_DEPRECATED)
|
2016-05-25 13:04:28 +00:00
|
|
|
|
2018-04-13 07:36:49 +00:00
|
|
|
#define NVENCAPI_CHECK_VERSION(major, minor) \
|
|
|
|
((major) < NVENCAPI_MAJOR_VERSION || ((major) == NVENCAPI_MAJOR_VERSION && (minor) <= NVENCAPI_MINOR_VERSION))
|
|
|
|
|
2018-04-11 12:22:20 +00:00
|
|
|
// SDK 8.1 compile time feature checks
|
2018-04-13 07:36:49 +00:00
|
|
|
#if NVENCAPI_CHECK_VERSION(8, 1)
|
2018-04-11 12:22:20 +00:00
|
|
|
#define NVENC_HAVE_BFRAME_REF_MODE
|
|
|
|
#define NVENC_HAVE_QP_MAP_MODE
|
|
|
|
#endif
|
|
|
|
|
2016-05-25 13:04:28 +00:00
|
|
|
typedef struct NvencSurface
|
|
|
|
{
|
|
|
|
NV_ENC_INPUT_PTR input_surface;
|
|
|
|
AVFrame *in_ref;
|
|
|
|
int reg_idx;
|
|
|
|
int width;
|
|
|
|
int height;
|
2016-09-07 16:15:22 +00:00
|
|
|
int pitch;
|
2016-05-25 13:04:28 +00:00
|
|
|
|
|
|
|
NV_ENC_OUTPUT_PTR output_surface;
|
|
|
|
NV_ENC_BUFFER_FORMAT format;
|
|
|
|
int size;
|
|
|
|
} NvencSurface;
|
|
|
|
|
|
|
|
typedef struct NvencDynLoadFunctions
|
|
|
|
{
|
2016-10-10 10:55:59 +00:00
|
|
|
CudaFunctions *cuda_dl;
|
|
|
|
NvencFunctions *nvenc_dl;
|
2016-05-25 13:04:28 +00:00
|
|
|
|
|
|
|
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs;
|
|
|
|
int nvenc_device_count;
|
|
|
|
} NvencDynLoadFunctions;
|
|
|
|
|
2016-05-25 14:05:50 +00:00
|
|
|
enum {
|
|
|
|
PRESET_DEFAULT = 0,
|
|
|
|
PRESET_SLOW,
|
|
|
|
PRESET_MEDIUM,
|
|
|
|
PRESET_FAST,
|
|
|
|
PRESET_HP,
|
|
|
|
PRESET_HQ,
|
|
|
|
PRESET_BD ,
|
|
|
|
PRESET_LOW_LATENCY_DEFAULT ,
|
|
|
|
PRESET_LOW_LATENCY_HQ ,
|
|
|
|
PRESET_LOW_LATENCY_HP,
|
|
|
|
PRESET_LOSSLESS_DEFAULT, // lossless presets must be the last ones
|
|
|
|
PRESET_LOSSLESS_HP,
|
|
|
|
};
|
|
|
|
|
2016-05-25 14:26:25 +00:00
|
|
|
enum {
|
|
|
|
NV_ENC_H264_PROFILE_BASELINE,
|
|
|
|
NV_ENC_H264_PROFILE_MAIN,
|
|
|
|
NV_ENC_H264_PROFILE_HIGH,
|
|
|
|
NV_ENC_H264_PROFILE_HIGH_444P,
|
|
|
|
};
|
|
|
|
|
2016-08-25 15:18:03 +00:00
|
|
|
enum {
|
|
|
|
NV_ENC_HEVC_PROFILE_MAIN,
|
|
|
|
NV_ENC_HEVC_PROFILE_MAIN_10,
|
2016-09-28 12:21:03 +00:00
|
|
|
NV_ENC_HEVC_PROFILE_REXT,
|
2016-08-25 15:18:03 +00:00
|
|
|
};
|
|
|
|
|
2016-05-25 14:05:50 +00:00
|
|
|
enum {
|
|
|
|
NVENC_LOWLATENCY = 1,
|
|
|
|
NVENC_LOSSLESS = 2,
|
|
|
|
NVENC_ONE_PASS = 4,
|
|
|
|
NVENC_TWO_PASSES = 8,
|
|
|
|
};
|
|
|
|
|
2016-05-29 12:23:26 +00:00
|
|
|
enum {
|
|
|
|
LIST_DEVICES = -2,
|
|
|
|
ANY_DEVICE,
|
|
|
|
};
|
|
|
|
|
2016-05-25 13:04:28 +00:00
|
|
|
typedef struct NvencContext
|
|
|
|
{
|
|
|
|
AVClass *avclass;
|
|
|
|
|
|
|
|
NvencDynLoadFunctions nvenc_dload_funcs;
|
|
|
|
|
|
|
|
NV_ENC_INITIALIZE_PARAMS init_encode_params;
|
|
|
|
NV_ENC_CONFIG encode_config;
|
|
|
|
CUcontext cu_context;
|
|
|
|
CUcontext cu_context_internal;
|
2017-11-11 15:51:58 +00:00
|
|
|
ID3D11Device *d3d11_device;
|
2016-05-25 13:04:28 +00:00
|
|
|
|
2016-05-29 10:07:34 +00:00
|
|
|
int nb_surfaces;
|
2016-05-25 13:04:28 +00:00
|
|
|
NvencSurface *surfaces;
|
|
|
|
|
2017-04-25 21:57:56 +00:00
|
|
|
AVFifoBuffer *unused_surface_queue;
|
2016-05-25 13:04:28 +00:00
|
|
|
AVFifoBuffer *output_surface_queue;
|
|
|
|
AVFifoBuffer *output_surface_ready_queue;
|
|
|
|
AVFifoBuffer *timestamp_list;
|
|
|
|
|
2017-09-02 17:30:21 +00:00
|
|
|
int encoder_flushing;
|
|
|
|
|
2016-05-25 13:04:28 +00:00
|
|
|
struct {
|
2017-11-11 15:51:58 +00:00
|
|
|
void *ptr;
|
|
|
|
int ptr_index;
|
2016-05-25 13:04:28 +00:00
|
|
|
NV_ENC_REGISTERED_PTR regptr;
|
|
|
|
int mapped;
|
2018-01-26 19:16:53 +00:00
|
|
|
NV_ENC_MAP_INPUT_RESOURCE in_map;
|
2016-05-25 13:04:28 +00:00
|
|
|
} registered_frames[MAX_REGISTERED_FRAMES];
|
|
|
|
int nb_registered_frames;
|
|
|
|
|
|
|
|
/* the actual data pixel format, different from
|
|
|
|
* AVCodecContext.pix_fmt when using hwaccel frames on input */
|
|
|
|
enum AVPixelFormat data_pix_fmt;
|
|
|
|
|
2016-05-31 16:59:35 +00:00
|
|
|
/* timestamps of the first two frames, for computing the first dts
|
|
|
|
* when B-frames are present */
|
|
|
|
int64_t initial_pts[2];
|
|
|
|
int first_packet_output;
|
2016-05-25 13:04:28 +00:00
|
|
|
|
2018-05-03 00:15:52 +00:00
|
|
|
int support_dyn_bitrate;
|
|
|
|
|
2016-05-25 13:04:28 +00:00
|
|
|
void *nvencoder;
|
|
|
|
|
2016-05-25 14:05:50 +00:00
|
|
|
int preset;
|
2016-05-25 14:26:25 +00:00
|
|
|
int profile;
|
2016-05-25 15:00:52 +00:00
|
|
|
int level;
|
2016-05-25 15:06:02 +00:00
|
|
|
int tier;
|
2016-05-25 16:39:54 +00:00
|
|
|
int rc;
|
2016-05-25 13:04:28 +00:00
|
|
|
int cbr;
|
|
|
|
int twopass;
|
2016-05-29 12:23:26 +00:00
|
|
|
int device;
|
2016-05-25 14:05:50 +00:00
|
|
|
int flags;
|
2016-05-29 10:07:34 +00:00
|
|
|
int async_depth;
|
2016-08-25 15:20:03 +00:00
|
|
|
int rc_lookahead;
|
2016-09-24 15:55:00 +00:00
|
|
|
int aq;
|
|
|
|
int no_scenecut;
|
2016-10-12 18:51:43 +00:00
|
|
|
int forced_idr;
|
2016-09-24 15:55:00 +00:00
|
|
|
int b_adapt;
|
|
|
|
int temporal_aq;
|
|
|
|
int zerolatency;
|
|
|
|
int nonref_p;
|
|
|
|
int strict_gop;
|
|
|
|
int aq_strength;
|
2017-05-10 06:41:17 +00:00
|
|
|
float quality;
|
2016-12-30 21:02:42 +00:00
|
|
|
int aud;
|
2016-12-30 21:04:31 +00:00
|
|
|
int bluray_compat;
|
2017-02-28 05:39:12 +00:00
|
|
|
int init_qp_p;
|
|
|
|
int init_qp_b;
|
|
|
|
int init_qp_i;
|
2017-03-23 16:01:40 +00:00
|
|
|
int cqp;
|
2017-05-09 14:24:54 +00:00
|
|
|
int weighted_pred;
|
2017-08-30 19:06:25 +00:00
|
|
|
int coder;
|
2018-04-11 12:22:20 +00:00
|
|
|
int b_ref_mode;
|
2018-08-21 12:28:15 +00:00
|
|
|
int a53_cc;
|
2016-05-25 13:04:28 +00:00
|
|
|
} NvencContext;
|
|
|
|
|
|
|
|
int ff_nvenc_encode_init(AVCodecContext *avctx);
|
|
|
|
|
|
|
|
int ff_nvenc_encode_close(AVCodecContext *avctx);
|
|
|
|
|
2017-09-02 17:30:21 +00:00
|
|
|
int ff_nvenc_send_frame(AVCodecContext *avctx, const AVFrame *frame);
|
|
|
|
|
|
|
|
int ff_nvenc_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
|
|
|
|
|
2016-05-25 13:04:28 +00:00
|
|
|
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|
|
|
const AVFrame *frame, int *got_packet);
|
|
|
|
|
|
|
|
extern const enum AVPixelFormat ff_nvenc_pix_fmts[];
|
|
|
|
|
|
|
|
#endif /* AVCODEC_NVENC_H */
|