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;
133 #if FF_API_TICKS_PER_FRAME
136 params->m_TicksPerSecond = -1;
137 #if FF_API_TICKS_PER_FRAME
139 params->m_TicksPerSecond =
157 parse_ret = vvenc_set_param(params, en->
key, en->
value);
159 case VVENC_PARAM_BAD_NAME:
163 case VVENC_PARAM_BAD_VALUE:
173 "not available. Use option 'passlogfile'\n");
178 "not available. Use option 'pass'\n", en->
key);
187 params->m_RCNumPasses = 1;
193 params->m_RCNumPasses = 2;
195 params->m_RCPass = 1;
197 params->m_RCPass = 2;
201 #if VVENC_VERSION_INT >= AV_VERSION_INT(1,8,0)
205 #if VVENC_VERSION_INT < AV_VERSION_INT(1,11,0)
210 "needs at least vvenc version >= 1.11.0 (current version %s)\n", vvenc_get_version());
222 ret = vvenc_get_headers(
s->encoder,
s->au);
225 vvenc_get_last_error(
s->encoder));
229 if (
s->au->payloadUsedSize <= 0) {
250 vvencPresetMode
preset = (vvencPresetMode)
s->preset;
257 vvenc_config_default(¶ms);
274 params.m_DecodingRefreshType = VVENC_DRT_IDR;
277 params.m_GOPSize = 1;
278 params.m_IntraPeriod = 1;
280 params.m_IntraPeriodSec =
s->intra_refresh_sec;
282 params.m_AccessUnitDelimiter =
true;
283 params.m_usePerceptQPA =
s->qpa;
284 params.m_levelTier = (vvencTier)
s->tier;
287 params.m_level = (vvencLevel)avctx->
level;
290 if (VVENC_PARAM_BAD_VALUE == vvenc_set_param(¶ms,
"level",
s->level)) {
310 s->encoder = vvenc_encoder_create();
317 ret = vvenc_encoder_open(
s->encoder, ¶ms);
320 vvenc_get_last_error(
s->encoder));
324 vvenc_get_config(
s->encoder, ¶ms);
328 av_log(avctx,
AV_LOG_INFO,
"%s\n", vvenc_get_config_as_string(¶ms, params.m_verbosity));
330 if (params.m_RCNumPasses == 2) {
331 ret = vvenc_init_pass(
s->encoder, params.m_RCPass - 1,
s->stats);
334 vvenc_get_last_error(
s->encoder));
339 s->au = vvenc_accessUnit_alloc();
344 vvenc_accessUnit_alloc_payload(
s->au, avctx->
width * avctx->
height);
345 if (!
s->au->payload) {
355 s->encode_done =
false;
364 vvenc_accessUnit_free(
s->au,
true);
367 vvenc_print_summary(
s->encoder);
369 if (0 != vvenc_encoder_close(
s->encoder))
380 vvencYUVBuffer *pyuvbuf;
381 vvencYUVBuffer yuvbuf;
386 vvenc_YUVBuffer_default(&yuvbuf);
387 yuvbuf.planes[0].ptr = (int16_t *)
frame->data[0];
388 yuvbuf.planes[1].ptr = (int16_t *)
frame->data[1];
389 yuvbuf.planes[2].ptr = (int16_t *)
frame->data[2];
391 yuvbuf.planes[0].width =
frame->width;
392 yuvbuf.planes[0].height =
frame->height;
393 yuvbuf.planes[0].stride =
frame->linesize[0] >> 1;
395 yuvbuf.planes[1].width =
frame->width >> 1;
396 yuvbuf.planes[1].height =
frame->height >> 1;
397 yuvbuf.planes[1].stride =
frame->linesize[1] >> 1;
399 yuvbuf.planes[2].width =
frame->width >> 1;
400 yuvbuf.planes[2].height =
frame->height >> 1;
401 yuvbuf.planes[2].stride =
frame->linesize[2] >> 1;
403 yuvbuf.cts =
frame->pts;
404 yuvbuf.ctsValid =
true;
408 if (!
s->encode_done) {
409 if (vvenc_encode(
s->encoder, pyuvbuf,
s->au, &
s->encode_done) != 0)
414 if (
s->au->payloadUsedSize > 0) {
419 memcpy(
pkt->
data,
s->au->payload,
s->au->payloadUsedSize);
439 #define OFFSET(x) offsetof(VVenCContext, x)
440 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
443 {
"faster",
"0", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_FASTER}, INT_MIN, INT_MAX,
VE,
"preset" },
444 {
"fast",
"1", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_FAST}, INT_MIN, INT_MAX,
VE,
"preset" },
445 {
"medium",
"2", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_MEDIUM}, INT_MIN, INT_MAX,
VE,
"preset" },
446 {
"slow",
"3", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_SLOW}, INT_MIN, INT_MAX,
VE,
"preset" },
447 {
"slower",
"4", 0,
AV_OPT_TYPE_CONST, {.i64 = VVENC_SLOWER}, INT_MIN, INT_MAX,
VE,
"preset" },
449 {
"qpa",
"set subjective (perceptually motivated) optimization",
OFFSET(qpa),
AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1,
VE},
452 {
"period",
"set (intra) refresh period in seconds",
OFFSET(intra_refresh_sec),
AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX,
VE },
453 {
"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 },
475 .
p.
name =
"libvvenc",
482 .p.priv_class = &
class,
483 .p.wrapper_name =
"libvvenc",
#define FF_ENABLE_DEPRECATION_WARNINGS
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)
static __device__ float ceil(float a)
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.
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.
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
#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 FF_DISABLE_DEPRECATION_WARNINGS
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.