Go to the documentation of this file.
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(¶ms);
70 vvenc_get_config(encoder, ¶ms);
71 if ((
int)params.m_verbosity >=
level)
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;
99 params->m_matrixCoefficients = (int) avctx->
colorspace;
101 params->m_transferCharacteristics = (int) avctx->
color_trc;
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;
144 parse_ret = vvenc_set_param(params, en->
key, en->
value);
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;
182 params->m_RCPass = 1;
184 params->m_RCPass = 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(¶ms);
261 params.m_DecodingRefreshType = VVENC_DRT_IDR;
264 params.m_GOPSize = 1;
265 params.m_IntraPeriod = 1;
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;
274 params.m_level = (vvencLevel)avctx->
level;
277 if (VVENC_PARAM_BAD_VALUE == vvenc_set_param(¶ms,
"level",
s->level)) {
297 s->encoder = vvenc_encoder_create();
304 ret = vvenc_encoder_open(
s->encoder, ¶ms);
307 vvenc_get_last_error(
s->encoder));
311 vvenc_get_config(
s->encoder, ¶ms);
315 av_log(avctx,
AV_LOG_INFO,
"%s\n", vvenc_get_config_as_string(¶ms, params.m_verbosity));
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);
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",
AVPixelFormat
Pixel format.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVColorSpace colorspace
YUV colorspace type.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
This structure describes decoded (raw) audio or video data.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
#define AV_PIX_FMT_YUV420P10
#define AV_LOG_VERBOSE
Detailed information.
static const FFCodecDefault vvenc_defaults[]
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
AVCodec p
The public AVCodec.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
int flags
AV_CODEC_FLAG_*.
#define FF_CODEC_ENCODE_CB(func)
static int vvenc_parse_vvenc_params(AVCodecContext *avctx, vvenc_config *params)
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
static void vvenc_log_callback(void *ctx, int level, const char *fmt, va_list args)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const FFCodec ff_libvvenc_encoder
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t rc_max_rate
maximum bitrate
#define CODEC_LONG_NAME(str)
int av_log_get_level(void)
Get the current log level.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
#define CODEC_PIXFMTS_ARRAY(array)
static av_cold int vvenc_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
int64_t bit_rate
the average bitrate
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
int level
Encoding level descriptor.
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
static void vvenc_set_color_format(AVCodecContext *avctx, vvenc_config *params)
@ AVCOL_PRI_BT2020
ITU-R BT2020.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
static enum AVPixelFormat pix_fmts_vvenc[]
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
#define AVERROR_EXTERNAL
Generic error in an external library.
int flags
A combination of AV_PKT_FLAG values.
#define AV_LOG_INFO
Standard information.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
static const AVOption options[]
static int vvenc_set_rc_mode(AVCodecContext *avctx, vvenc_config *params)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
static av_cold int vvenc_close(AVCodecContext *avctx)
AVDictionary * vvenc_opts
#define AV_CODEC_FLAG_CLOSED_GOP
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static void vvenc_set_framerate(AVCodecContext *avctx, vvenc_config *params)
#define AV_INPUT_BUFFER_PADDING_SIZE
main external API structure.
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static void vvenc_set_pic_format(AVCodecContext *avctx, vvenc_config *params)
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static av_cold int vvenc_init(AVCodecContext *avctx)
static void vvenc_set_verbository(vvenc_config *params)
const AVProfile ff_vvc_profiles[]
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int width
picture width / height.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int vvenc_init_extradata(AVCodecContext *avctx, VVenCContext *s)
@ 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...
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.