23#include <vvenc/vvenc.h>
24#include <vvenc/vvencCfg.h>
25#include <vvenc/version.h>
44#define VVENC_VERSION_INT AV_VERSION_INT(VVENC_VERSION_MAJOR, \
45 VVENC_VERSION_MINOR, \
64 const char *fmt, va_list args)
67 vvencEncoder *encoder =
ctx;
69 vvenc_config_default(&
params);
70 vvenc_get_config(encoder, &
params);
72 vfprintf(
level == 1 ? stderr : stdout, fmt, args);
79 params->m_verbosity = VVENC_SILENT;
81 params->m_verbosity = VVENC_DETAILS;
83 params->m_verbosity = VVENC_NOTICE;
85 params->m_verbosity = VVENC_WARNING;
90 params->m_internChromaFormat = VVENC_CHROMA_420;
91 params->m_inputBitDepth[0] = 10;
105 VVENC_HDR_PQ_BT2020 : VVENC_HDR_PQ;
111 VVENC_HDR_HLG_BT2020 : VVENC_HDR_HLG;
114 if (
params->m_HdrMode == VVENC_HDR_OFF &&
116 params->m_vuiParametersPresent = 1;
117 params->m_colourDescriptionPresent =
true;
131 params->m_TicksPerSecond = -1;
146 case VVENC_PARAM_BAD_NAME:
150 case VVENC_PARAM_BAD_VALUE:
160 "not available. Use option 'passlogfile'\n");
165 "not available. Use option 'pass'\n", en->
key);
174 params->m_RCNumPasses = 1;
180 params->m_RCNumPasses = 2;
188#if VVENC_VERSION_INT >= AV_VERSION_INT(1,8,0)
192#if VVENC_VERSION_INT < AV_VERSION_INT(1,11,0)
197 "needs at least vvenc version >= 1.11.0 (current version %s)\n", vvenc_get_version());
209 ret = vvenc_get_headers(
s->encoder,
s->au);
212 vvenc_get_last_error(
s->encoder));
216 if (
s->au->payloadUsedSize <= 0) {
237 vvencPresetMode
preset = (vvencPresetMode)
s->preset;
244 vvenc_config_default(&
params);
261 params.m_DecodingRefreshType = VVENC_DRT_IDR;
267 params.m_IntraPeriodSec =
s->intra_refresh_sec;
269 params.m_AccessUnitDelimiter =
true;
270 params.m_usePerceptQPA =
s->qpa;
271 params.m_levelTier = (vvencTier)
s->tier;
273 if (avctx->
level > 0)
277 if (VVENC_PARAM_BAD_VALUE == vvenc_set_param(&
params,
"level",
s->level)) {
297 s->encoder = vvenc_encoder_create();
304 ret = vvenc_encoder_open(
s->encoder, &
params);
307 vvenc_get_last_error(
s->encoder));
311 vvenc_get_config(
s->encoder, &
params);
317 if (
params.m_RCNumPasses == 2) {
318 ret = vvenc_init_pass(
s->encoder,
params.m_RCPass - 1,
s->stats);
321 vvenc_get_last_error(
s->encoder));
326 s->au = vvenc_accessUnit_alloc();
331 vvenc_accessUnit_alloc_payload(
s->au, avctx->
width * avctx->
height);
332 if (!
s->au->payload) {
342 s->encode_done =
false;
351 vvenc_accessUnit_free(
s->au,
true);
354 vvenc_print_summary(
s->encoder);
356 if (0 != vvenc_encoder_close(
s->encoder))
367 vvencYUVBuffer *pyuvbuf;
368 vvencYUVBuffer yuvbuf;
373 vvenc_YUVBuffer_default(&yuvbuf);
374 yuvbuf.planes[0].ptr = (int16_t *)
frame->data[0];
375 yuvbuf.planes[1].ptr = (int16_t *)
frame->data[1];
376 yuvbuf.planes[2].ptr = (int16_t *)
frame->data[2];
378 yuvbuf.planes[0].width =
frame->width;
379 yuvbuf.planes[0].height =
frame->height;
380 yuvbuf.planes[0].stride =
frame->linesize[0] >> 1;
382 yuvbuf.planes[1].width =
frame->width >> 1;
383 yuvbuf.planes[1].height =
frame->height >> 1;
384 yuvbuf.planes[1].stride =
frame->linesize[1] >> 1;
386 yuvbuf.planes[2].width =
frame->width >> 1;
387 yuvbuf.planes[2].height =
frame->height >> 1;
388 yuvbuf.planes[2].stride =
frame->linesize[2] >> 1;
390 yuvbuf.cts =
frame->pts;
391 yuvbuf.ctsValid =
true;
395 if (!
s->encode_done) {
396 if (vvenc_encode(
s->encoder, pyuvbuf,
s->au, &
s->encode_done) != 0)
401 if (
s->au->payloadUsedSize > 0) {
406 memcpy(
pkt->data,
s->au->payload,
s->au->payloadUsedSize);
409 pkt->pts =
s->au->cts;
411 pkt->dts =
s->au->dts;
426#define OFFSET(x) offsetof(VVenCContext, x)
427#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
430 {
"faster",
"0", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_FASTER}, INT_MIN, INT_MAX,
VE,
"preset" },
431 {
"fast",
"1", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_FAST}, INT_MIN, INT_MAX,
VE,
"preset" },
432 {
"medium",
"2", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_MEDIUM}, INT_MIN, INT_MAX,
VE,
"preset" },
433 {
"slow",
"3", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_SLOW}, INT_MIN, INT_MAX,
VE,
"preset" },
434 {
"slower",
"4", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_SLOWER}, INT_MIN, INT_MAX,
VE,
"preset" },
436 {
"qpa",
"set subjective (perceptually motivated) optimization",
OFFSET(qpa),
AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1,
VE},
439 {
"period",
"set (intra) refresh period in seconds",
OFFSET(intra_refresh_sec),
AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX,
VE },
440 {
"vvenc-params",
"set the vvenc configuration using a :-separated list of key=value parameters",
OFFSET(vvenc_opts),
AV_OPT_TYPE_DICT, { 0 }, 0, 0,
VE },
462 .p.name =
"libvvenc",
469 .p.priv_class = &
class,
470 .p.wrapper_name =
"libvvenc",
SwsAArch64OpImplParams params
const FFCodec ff_libvvenc_encoder
static AVFormatContext * ctx
Libavcodec external API header.
Convenience header that includes libavutil's core.
#define CODEC_PIXFMTS_ARRAY(array)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal and external API header
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static CheckasmStats stats
reference-counted frame API
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_log_get_level(void)
Get the current log level.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define LIBAVUTIL_VERSION_INT
common internal api header.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static void vvenc_set_color_format(AVCodecContext *avctx, vvenc_config *params)
static enum AVPixelFormat pix_fmts_vvenc[]
static const FFCodecDefault vvenc_defaults[]
static av_cold int vvenc_init(AVCodecContext *avctx)
static int vvenc_init_extradata(AVCodecContext *avctx, VVenCContext *s)
static void vvenc_set_verbository(vvenc_config *params)
static av_cold int vvenc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static void vvenc_log_callback(void *ctx, int level, const char *fmt, va_list args)
static void vvenc_set_framerate(AVCodecContext *avctx, vvenc_config *params)
static int vvenc_set_rc_mode(AVCodecContext *avctx, vvenc_config *params)
static int vvenc_parse_vvenc_params(AVCodecContext *avctx, vvenc_config *params)
static void vvenc_set_pic_format(AVCodecContext *avctx, vvenc_config *params)
static av_cold int vvenc_close(AVCodecContext *avctx)
Memory handling functions.
#define AV_PIX_FMT_YUV420P10
AVPixelFormat
Pixel format.
@ AVCOL_PRI_BT2020
ITU-R BT2020.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
const AVProfile ff_vvc_profiles[]
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
int width
picture width / height.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int level
Encoding level descriptor.
int64_t bit_rate
the average bitrate
enum AVColorSpace colorspace
YUV colorspace type.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int64_t rc_max_rate
maximum bitrate
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
AVDictionary * vvenc_opts