Partially based on the work of Timo Rothenpieler <timo@rothenpieler.org> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>tags/n2.7
@@ -31,6 +31,7 @@ version <next>: | |||
- Canopus HQ/HQA decoder | |||
- Automatically rotate videos based on metadata in avconv | |||
- improved Quickdraw compatibility | |||
- NVIDIA NVENC-accelerated H.264 and HEVC encoding support | |||
version 11: | |||
@@ -220,6 +220,7 @@ External library support: | |||
--enable-libxvid enable Xvid encoding via xvidcore, | |||
native MPEG-4/Xvid encoder exists [no] | |||
--enable-mmal enable decoding via MMAL [no] | |||
--enable-nvenc enable encoding via NVENC [no] | |||
--enable-openssl enable openssl [no] | |||
--enable-x11grab enable X11 grabbing (legacy) [no] | |||
--enable-zlib enable zlib [autodetect] | |||
@@ -1191,6 +1192,7 @@ EXTERNAL_LIBRARY_LIST=" | |||
libxcb_xfixes | |||
libxvid | |||
mmal | |||
nvenc | |||
openssl | |||
x11grab | |||
zlib | |||
@@ -1483,6 +1485,7 @@ SYSTEM_FUNCS=" | |||
inet_aton | |||
isatty | |||
jack_port_get_latency_range | |||
LoadLibrary | |||
localtime_r | |||
mach_absolute_time | |||
MapViewOfFile | |||
@@ -1780,6 +1783,8 @@ mpegaudio_select="mpegaudiodsp" | |||
mpegaudiodsp_select="dct" | |||
mpegvideo_select="blockdsp hpeldsp idctdsp me_cmp videodsp" | |||
mpegvideoenc_select="me_cmp mpegvideo pixblockdsp qpeldsp" | |||
nvenc_deps_any="dlopen LoadLibrary" | |||
nvenc_extralibs='$ldl' | |||
qsvdec_select="qsv" | |||
qsvenc_select="qsv" | |||
@@ -1849,11 +1854,13 @@ h263i_decoder_select="h263_decoder" | |||
h263p_encoder_select="h263_encoder" | |||
h264_decoder_select="cabac golomb h264chroma h264dsp h264pred h264qpel startcode videodsp" | |||
h264_decoder_suggest="error_resilience" | |||
h264_nvenc_encoder_deps="nvenc" | |||
h264_qsv_decoder_deps="libmfx" | |||
h264_qsv_decoder_select="h264_mp4toannexb_bsf h264_parser qsvdec h264_qsv_hwaccel" | |||
h264_qsv_encoder_deps="libmfx" | |||
h264_qsv_encoder_select="qsvenc" | |||
hevc_decoder_select="bswapdsp cabac golomb videodsp" | |||
hevc_nvenc_encoder_deps="nvenc" | |||
huffyuv_decoder_select="bswapdsp huffyuvdsp" | |||
huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp" | |||
iac_decoder_select="imc_decoder" | |||
@@ -3822,6 +3829,7 @@ die_license_disabled gpl x11grab | |||
die_license_disabled nonfree libfaac | |||
die_license_disabled nonfree libfdk_aac | |||
die_license_disabled nonfree nvenc | |||
die_license_disabled nonfree openssl | |||
die_license_disabled version3 libopencore_amrnb | |||
@@ -4188,6 +4196,7 @@ check_func_headers windows.h CoTaskMemFree -lole32 | |||
check_func_headers windows.h GetProcessAffinityMask | |||
check_func_headers windows.h GetProcessTimes | |||
check_func_headers windows.h GetSystemTimeAsFileTime | |||
check_func_headers windows.h LoadLibrary | |||
check_func_headers windows.h MapViewOfFile | |||
check_func_headers windows.h SetConsoleTextAttribute | |||
check_func_headers windows.h Sleep | |||
@@ -4340,6 +4349,13 @@ if enabled libdc1394; then | |||
die "ERROR: No version of libdc1394 found " | |||
fi | |||
if enabled nvenc; then | |||
check_header cuda.h || die "ERROR: cuda.h not found."; | |||
check_header nvEncodeAPI.h || die "ERROR: nvEncodeAPI.h not found."; | |||
check_cpp_condition nvEncodeAPI.h "NVENCAPI_MAJOR_VERSION >= 5" || | |||
die "ERROR: NVENC API version 4 or older is not supported"; | |||
fi | |||
if check_pkg_config sdl SDL_events.h SDL_PollEvent; then | |||
check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags && | |||
check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x010300" $sdl_cflags && | |||
@@ -82,6 +82,7 @@ OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \ | |||
motion_est.o ratecontrol.o \ | |||
mpegvideoencdsp.o | |||
OBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o | |||
OBJS-${CONFIG_NVENC} += nvenc.o | |||
OBJS-$(CONFIG_QPELDSP) += qpeldsp.o | |||
OBJS-$(CONFIG_QSV) += qsv.o | |||
OBJS-$(CONFIG_QSVDEC) += qsvdec.o | |||
@@ -228,11 +229,13 @@ OBJS-$(CONFIG_H264_DECODER) += h264.o h264_cabac.o h264_cavlc.o \ | |||
h264_mb.o h264_picture.o h264_ps.o \ | |||
h264_refs.o h264_sei.o h264_slice.o | |||
OBJS-$(CONFIG_H264_MMAL_DECODER) += mmaldec.o | |||
OBJS-$(CONFIG_H264_NVENC_ENCODER) += nvenc_h264.o | |||
OBJS-$(CONFIG_H264_QSV_DECODER) += qsvdec_h264.o | |||
OBJS-$(CONFIG_H264_QSV_ENCODER) += qsvenc_h264.o | |||
OBJS-$(CONFIG_HEVC_DECODER) += hevc.o hevc_mvs.o hevc_ps.o hevc_sei.o \ | |||
hevc_cabac.o hevc_refs.o hevcpred.o \ | |||
hevcdsp.o hevc_filter.o | |||
OBJS-$(CONFIG_HEVC_NVENC_ENCODER) += nvenc_hevc.o | |||
OBJS-$(CONFIG_HNM4_VIDEO_DECODER) += hnm4video.o | |||
OBJS-$(CONFIG_HQ_HQA_DECODER) += hq_hqa.o hq_hqadata.o hq_hqadsp.o \ | |||
canopus.o | |||
@@ -478,7 +478,9 @@ void avcodec_register_all(void) | |||
/* external libraries, that shouldn't be used by default if one of the | |||
* above is available */ | |||
REGISTER_ENCODER(LIBOPENH264, libopenh264); | |||
REGISTER_ENCODER(H264_NVENC, h264_nvenc); | |||
REGISTER_ENCODER(H264_QSV, h264_qsv); | |||
REGISTER_ENCODER(HEVC_NVENC, hevc_nvenc); | |||
/* parsers */ | |||
REGISTER_PARSER(AAC, aac); | |||
@@ -0,0 +1,135 @@ | |||
/* | |||
* This file is part of Libav. | |||
* | |||
* Libav 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. | |||
* | |||
* Libav 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 Libav; 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 | |||
#include <cuda.h> | |||
#include <nvEncodeAPI.h> | |||
#include "libavutil/fifo.h" | |||
#include "libavutil/opt.h" | |||
#include "avcodec.h" | |||
typedef struct NVENCInputSurface { | |||
NV_ENC_INPUT_PTR in; | |||
NV_ENC_BUFFER_FORMAT format; | |||
int locked; | |||
} NVENCInputSurface; | |||
typedef struct NVENCOutputSurface { | |||
NV_ENC_OUTPUT_PTR out; | |||
NVENCInputSurface *in; | |||
int busy; | |||
} NVENCOutputSurface; | |||
typedef CUresult(CUDAAPI *PCUINIT)(unsigned int Flags); | |||
typedef CUresult(CUDAAPI *PCUDEVICEGETCOUNT)(int *count); | |||
typedef CUresult(CUDAAPI *PCUDEVICEGET)(CUdevice *device, int ordinal); | |||
typedef CUresult(CUDAAPI *PCUDEVICEGETNAME)(char *name, int len, CUdevice dev); | |||
typedef CUresult(CUDAAPI *PCUDEVICECOMPUTECAPABILITY)(int *major, int *minor, CUdevice dev); | |||
typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUdevice dev); | |||
typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx); | |||
typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx); | |||
typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList); | |||
typedef struct NVENCLibraryContext | |||
{ | |||
void *cuda; | |||
void *nvenc; | |||
PCUINIT cu_init; | |||
PCUDEVICEGETCOUNT cu_device_get_count; | |||
PCUDEVICEGET cu_device_get; | |||
PCUDEVICEGETNAME cu_device_get_name; | |||
PCUDEVICECOMPUTECAPABILITY cu_device_compute_capability; | |||
PCUCTXCREATE cu_ctx_create; | |||
PCUCTXPOPCURRENT cu_ctx_pop_current; | |||
PCUCTXDESTROY cu_ctx_destroy; | |||
NV_ENCODE_API_FUNCTION_LIST nvenc_funcs; | |||
} NVENCLibraryContext; | |||
enum { | |||
PRESET_DEFAULT, | |||
PRESET_HP, | |||
PRESET_HQ, | |||
PRESET_BD , | |||
PRESET_LOW_LATENCY_DEFAULT , | |||
PRESET_LOW_LATENCY_HQ , | |||
PRESET_LOW_LATENCY_HP, | |||
PRESET_LOSSLESS_DEFAULT, | |||
PRESET_LOSSLESS_HP, | |||
}; | |||
enum { | |||
NV_ENC_H264_PROFILE_BASELINE, | |||
NV_ENC_H264_PROFILE_MAIN, | |||
NV_ENC_H264_PROFILE_HIGH, | |||
NV_ENC_H264_PROFILE_HIGH_444, | |||
NV_ENC_H264_PROFILE_CONSTRAINED_HIGH, | |||
}; | |||
enum { | |||
NVENC_LOWLATENCY = 1, | |||
NVENC_LOSSLESS, | |||
}; | |||
enum { | |||
LIST_DEVICES = -2, | |||
ANY_DEVICE, | |||
}; | |||
typedef struct NVENCContext { | |||
AVClass *class; | |||
NVENCLibraryContext nvel; | |||
NV_ENC_INITIALIZE_PARAMS params; | |||
NV_ENC_CONFIG config; | |||
CUcontext cu_context; | |||
int nb_surfaces; | |||
NVENCInputSurface *in; | |||
NVENCOutputSurface *out; | |||
AVFifoBuffer *timestamps; | |||
AVFifoBuffer *pending, *ready; | |||
int64_t last_dts; | |||
void *nvenc_ctx; | |||
int preset; | |||
int profile; | |||
int level; | |||
int tier; | |||
int rc; | |||
int device; | |||
int flags; | |||
} NVENCContext; | |||
int ff_nvenc_encode_init(AVCodecContext *avctx); | |||
int ff_nvenc_encode_close(AVCodecContext *avctx); | |||
int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt, | |||
const AVFrame *frame, int *got_packet); | |||
#endif /* AVCODEC_NVENC_H */ |
@@ -0,0 +1,110 @@ | |||
/* | |||
* This file is part of Libav. | |||
* | |||
* Libav 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. | |||
* | |||
* Libav 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 Libav; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
*/ | |||
#include "libavutil/internal.h" | |||
#include "libavutil/opt.h" | |||
#include "avcodec.h" | |||
#include "internal.h" | |||
#include "nvenc.h" | |||
#define OFFSET(x) offsetof(NVENCContext, x) | |||
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||
static const AVOption options[] = { | |||
{ "preset", "Set the encoding preset", OFFSET(preset), AV_OPT_TYPE_INT, { .i64 = PRESET_HQ }, PRESET_DEFAULT, PRESET_LOSSLESS_HP, VE, "preset" }, | |||
{ "default", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_DEFAULT }, 0, 0, VE, "preset" }, | |||
{ "hp", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_HP }, 0, 0, VE, "preset" }, | |||
{ "hq", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_HQ }, 0, 0, VE, "preset" }, | |||
{ "bd", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_BD }, 0, 0, VE, "preset" }, | |||
{ "ll", "low latency", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOW_LATENCY_DEFAULT }, 0, 0, VE, "preset" }, | |||
{ "llhq", "low latency hq", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOW_LATENCY_HQ }, 0, 0, VE, "preset" }, | |||
{ "llhp", "low latency hp", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOW_LATENCY_HP }, 0, 0, VE, "preset" }, | |||
{ "profile", "Set the encoding profile", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = NV_ENC_H264_PROFILE_HIGH }, NV_ENC_H264_PROFILE_BASELINE, NV_ENC_H264_PROFILE_CONSTRAINED_HIGH, VE, "profile" }, | |||
{ "baseline", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_BASELINE }, 0, 0, VE, "profile" }, | |||
{ "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_MAIN }, 0, 0, VE, "profile" }, | |||
{ "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH }, 0, 0, VE, "profile" }, | |||
{ "high_444", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH_444 }, 0, 0, VE, "profile" }, | |||
{ "constrained_high", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_CONSTRAINED_HIGH }, 0, 0, VE, "profile" }, | |||
{ "level", "Set the encoding level restriction", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = NV_ENC_LEVEL_AUTOSELECT }, NV_ENC_LEVEL_AUTOSELECT, NV_ENC_LEVEL_H264_51, VE, "level" }, | |||
{ "1.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_1 }, 0, 0, VE, "level" }, | |||
{ "1.b", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_1b }, 0, 0, VE, "level" }, | |||
{ "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_11 }, 0, 0, VE, "level" }, | |||
{ "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_12 }, 0, 0, VE, "level" }, | |||
{ "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_13 }, 0, 0, VE, "level" }, | |||
{ "2.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_2 }, 0, 0, VE, "level" }, | |||
{ "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_21 }, 0, 0, VE, "level" }, | |||
{ "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_22 }, 0, 0, VE, "level" }, | |||
{ "3.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_3 }, 0, 0, VE, "level" }, | |||
{ "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_31 }, 0, 0, VE, "level" }, | |||
{ "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_32 }, 0, 0, VE, "level" }, | |||
{ "4.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_4 }, 0, 0, VE, "level" }, | |||
{ "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_41 }, 0, 0, VE, "level" }, | |||
{ "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_42 }, 0, 0, VE, "level" }, | |||
{ "5.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_5 }, 0, 0, VE, "level" }, | |||
{ "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_H264_51 }, 0, 0, VE, "level" }, | |||
{ "rc", "Override the preset rate-control", OFFSET(rc), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0, VE }, | |||
{ "constqp", "Constant QP mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_CONSTQP }, 0, 0, VE, "rc" }, | |||
{ "vbr", "Variable bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_VBR }, 0, 0, VE, "rc" }, | |||
{ "cbr", "Constant bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_CBR }, 0, 0, VE, "rc" }, | |||
{ "vbr_minqp", "Variable bitrate mode with MinQP", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_VBR_MINQP }, 0, 0, VE, "rc" }, | |||
{ "ll_2pass_quality", "Multi-pass optimized for image quality (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_QUALITY }, 0, 0, VE, "rc" }, | |||
{ "ll_2pass_size", "Multi-pass optimized for constant frame size (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP }, 0, 0, VE, "rc" }, | |||
{ "vbr_2pass", "Multi-pass variable bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_VBR }, 0, 0, VE, "rc" }, | |||
{ "surfaces", "Number of concurrent surfaces", OFFSET(nb_surfaces), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, INT_MAX, VE }, | |||
{ "device", "Select a specific NVENC device", OFFSET(device), AV_OPT_TYPE_INT, { .i64 = -1 }, -2, INT_MAX, VE, "device" }, | |||
{ "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "device" }, | |||
{ "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "device" }, | |||
{ NULL } | |||
}; | |||
static const AVClass nvenc_hevc_class = { | |||
.class_name = "nvenc_h264", | |||
.item_name = av_default_item_name, | |||
.option = options, | |||
.version = LIBAVUTIL_VERSION_INT, | |||
}; | |||
static const AVCodecDefault defaults[] = { | |||
{ "b", "0" }, | |||
{ "qmin", "-1" }, | |||
{ "qmax", "-1" }, | |||
{ "qdiff", "-1" }, | |||
{ "qblur", "-1" }, | |||
{ "qcomp", "-1" }, | |||
{ NULL }, | |||
}; | |||
AVCodec ff_h264_nvenc_encoder = { | |||
.name = "nvenc_h264", | |||
.long_name = NULL_IF_CONFIG_SMALL("NVIDIA NVENC H264 encoder"), | |||
.type = AVMEDIA_TYPE_VIDEO, | |||
.id = AV_CODEC_ID_H264, | |||
.init = ff_nvenc_encode_init, | |||
.encode2 = ff_nvenc_encode_frame, | |||
.close = ff_nvenc_encode_close, | |||
.priv_data_size = sizeof(NVENCContext), | |||
.priv_class = &nvenc_hevc_class, | |||
.defaults = defaults, | |||
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, | |||
AV_PIX_FMT_YUV420P, | |||
AV_PIX_FMT_YUV444P, | |||
AV_PIX_FMT_NONE }, | |||
.capabilities = CODEC_CAP_DELAY, | |||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |||
}; |
@@ -0,0 +1,108 @@ | |||
/* | |||
* This file is part of Libav. | |||
* | |||
* Libav 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. | |||
* | |||
* Libav 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 Libav; if not, write to the Free Software | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
*/ | |||
#include "libavutil/internal.h" | |||
#include "libavutil/opt.h" | |||
#include "avcodec.h" | |||
#include "internal.h" | |||
#include "nvenc.h" | |||
#define OFFSET(x) offsetof(NVENCContext, x) | |||
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||
static const AVOption options[] = { | |||
{ "preset", "Set the encoding preset", OFFSET(preset), AV_OPT_TYPE_INT, { .i64 = PRESET_HQ }, PRESET_DEFAULT, PRESET_LOSSLESS_HP, VE, "preset" }, | |||
{ "default", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_DEFAULT }, 0, 0, VE, "preset" }, | |||
{ "hp", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_HP }, 0, 0, VE, "preset" }, | |||
{ "hq", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_HQ }, 0, 0, VE, "preset" }, | |||
{ "bd", "", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_BD }, 0, 0, VE, "preset" }, | |||
{ "ll", "low latency", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOW_LATENCY_DEFAULT }, 0, 0, VE, "preset" }, | |||
{ "llhq", "low latency hq", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOW_LATENCY_HQ }, 0, 0, VE, "preset" }, | |||
{ "llhp", "low latency hp", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOW_LATENCY_HP }, 0, 0, VE, "preset" }, | |||
{ "lossless", "lossless", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOSSLESS_DEFAULT }, 0, 0, VE, "preset" }, | |||
{ "losslesshp", "lossless hp", 0, AV_OPT_TYPE_CONST, { .i64 = PRESET_LOSSLESS_HP }, 0, 0, VE, "preset" }, | |||
{ "profile", "Set the encoding profile", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_HEVC_MAIN }, FF_PROFILE_HEVC_MAIN, FF_PROFILE_HEVC_MAIN, VE, "profile" }, | |||
{ "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_HEVC_MAIN }, 0, 0, VE, "profile" }, | |||
{ "level", "Set the encoding level restriction", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = NV_ENC_LEVEL_AUTOSELECT }, NV_ENC_LEVEL_AUTOSELECT, NV_ENC_LEVEL_HEVC_62, VE, "level" }, | |||
{ "1.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_1 }, 0, 0, VE, "level" }, | |||
{ "2.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_2 }, 0, 0, VE, "level" }, | |||
{ "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_21 }, 0, 0, VE, "level" }, | |||
{ "3.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_3 }, 0, 0, VE, "level" }, | |||
{ "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_31 }, 0, 0, VE, "level" }, | |||
{ "4.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_4 }, 0, 0, VE, "level" }, | |||
{ "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_41 }, 0, 0, VE, "level" }, | |||
{ "5.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_5 }, 0, 0, VE, "level" }, | |||
{ "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_51 }, 0, 0, VE, "level" }, | |||
{ "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_52 }, 0, 0, VE, "level" }, | |||
{ "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_6 }, 0, 0, VE, "level" }, | |||
{ "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_61 }, 0, 0, VE, "level" }, | |||
{ "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_LEVEL_HEVC_62 }, 0, 0, VE, "level" }, | |||
{ "tier", "Set the encoding tier", OFFSET(tier), AV_OPT_TYPE_INT, { .i64 = NV_ENC_TIER_HEVC_MAIN }, NV_ENC_TIER_HEVC_MAIN, NV_ENC_TIER_HEVC_HIGH, VE, "tier"}, | |||
{ "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TIER_HEVC_MAIN }, 0, 0, VE, "tier" }, | |||
{ "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TIER_HEVC_HIGH }, 0, 0, VE, "tier" }, | |||
{ "rc", "Override the preset rate-control", OFFSET(rc), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0, VE, "rc" }, | |||
{ "constqp", "Constant QP mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_CONSTQP }, 0, 0, VE, "rc" }, | |||
{ "vbr", "Variable bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_VBR }, 0, 0, VE, "rc" }, | |||
{ "cbr", "Constant bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_CBR }, 0, 0, VE, "rc" }, | |||
{ "vbr_minqp", "Variable bitrate mode with MinQP", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_VBR_MINQP }, 0, 0, VE, "rc" }, | |||
{ "ll_2pass_quality", "Multi-pass optimized for image quality (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_QUALITY }, 0, 0, VE, "rc" }, | |||
{ "ll_2pass_size", "Multi-pass optimized for constant frame size (only for low-latency presets)", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_FRAMESIZE_CAP }, 0, 0, VE, "rc" }, | |||
{ "vbr_2pass", "Multi-pass variable bitrate mode", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_PARAMS_RC_2_PASS_VBR }, 0, 0, VE, "rc" }, | |||
{ "surfaces", "Number of concurrent surfaces", OFFSET(nb_surfaces), AV_OPT_TYPE_INT, { .i64 = 32 }, 0, INT_MAX, VE }, | |||
{ "device", "Select a specific NVENC device", OFFSET(device), AV_OPT_TYPE_INT, { .i64 = -1 }, -2, INT_MAX, VE, "device" }, | |||
{ "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "device" }, | |||
{ "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "device" }, | |||
{ NULL } | |||
}; | |||
static const AVClass nvenc_hevc_class = { | |||
.class_name = "nvenc_hevc", | |||
.item_name = av_default_item_name, | |||
.option = options, | |||
.version = LIBAVUTIL_VERSION_INT, | |||
}; | |||
static const AVCodecDefault defaults[] = { | |||
{ "b", "0" }, | |||
{ "qmin", "-1" }, | |||
{ "qmax", "-1" }, | |||
{ "qdiff", "-1" }, | |||
{ "qblur", "-1" }, | |||
{ "qcomp", "-1" }, | |||
{ NULL }, | |||
}; | |||
AVCodec ff_hevc_nvenc_encoder = { | |||
.name = "nvenc_hevc", | |||
.long_name = NULL_IF_CONFIG_SMALL("NVIDIA NVENC HEVC encoder"), | |||
.type = AVMEDIA_TYPE_VIDEO, | |||
.id = AV_CODEC_ID_HEVC, | |||
.init = ff_nvenc_encode_init, | |||
.encode2 = ff_nvenc_encode_frame, | |||
.close = ff_nvenc_encode_close, | |||
.priv_data_size = sizeof(NVENCContext), | |||
.priv_class = &nvenc_hevc_class, | |||
.defaults = defaults, | |||
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, | |||
AV_PIX_FMT_YUV420P, | |||
AV_PIX_FMT_YUV444P, | |||
AV_PIX_FMT_NONE }, | |||
.capabilities = CODEC_CAP_DELAY, | |||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | |||
}; |
@@ -29,7 +29,7 @@ | |||
#include "libavutil/version.h" | |||
#define LIBAVCODEC_VERSION_MAJOR 56 | |||
#define LIBAVCODEC_VERSION_MINOR 25 | |||
#define LIBAVCODEC_VERSION_MINOR 26 | |||
#define LIBAVCODEC_VERSION_MICRO 0 | |||
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | |||