Go to the documentation of this file.
63 #define OFFSET(x) offsetof(LIBVMAFContext, x)
64 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
69 {
"log_fmt",
"Set the format of the log (csv, json, xml, or sub).",
OFFSET(log_fmt),
AV_OPT_TYPE_STRING, {.str=
"xml"}, 0, 1,
FLAGS},
76 {
"n_threads",
"Set number of threads to be used when computing vmaf.",
OFFSET(n_threads),
AV_OPT_TYPE_INT, {.i64=0}, 0, UINT_MAX,
FLAGS},
77 {
"n_subsample",
"Set interval for frame subsampling used when computing vmaf.",
OFFSET(n_subsample),
AV_OPT_TYPE_INT, {.i64=1}, 1, UINT_MAX,
FLAGS},
93 return VMAF_PIX_FMT_YUV420P;
98 return VMAF_PIX_FMT_YUV422P;
103 return VMAF_PIX_FMT_YUV444P;
105 return VMAF_PIX_FMT_UNKNOWN;
111 const int bytes_per_value = bpc > 8 ? 2 : 1;
117 for (
unsigned i = 0;
i < 3;
i++) {
118 uint8_t *src_data =
src->data[
i];
119 uint8_t *dst_data = dst->data[
i];
120 for (
unsigned j = 0; j < dst->h[
i]; j++) {
121 memcpy(dst_data, src_data, bytes_per_value * dst->w[
i]);
122 src_data +=
src->linesize[
i];
123 dst_data += dst->stride[
i];
134 VmafPicture pic_ref, pic_dist;
141 if (
ctx->is_disabled || !
ref)
153 vmaf_picture_unref(&pic_ref);
157 err = vmaf_read_pictures(
s->vmaf, &pic_ref, &pic_dist,
s->frame_cnt++);
170 char *str_copy =
NULL;
171 char *saveptr =
NULL;
179 for (
char *p =
str; *p; p++) {
193 for (
unsigned i = 0;
i < cnt2;
i++) {
207 for (
unsigned i = 0;
i < *cnt;
i++) {
232 "could not parse feature config: %s\n",
s->feature_cfg);
236 for (
unsigned i = 0;
i < dict_cnt;
i++) {
237 char *feature_name =
NULL;
238 VmafFeatureDictionary *feature_opts_dict =
NULL;
243 feature_name = e->
value;
247 err = vmaf_feature_dictionary_set(&feature_opts_dict, e->
key,
251 "could not set feature option: %s.%s=%s\n",
257 err = vmaf_use_feature(
s->vmaf, feature_name, feature_opts_dict);
260 "problem during vmaf_use_feature: %s\n", feature_name);
266 for (
unsigned i = 0;
i < dict_cnt;
i++) {
281 if (!
s->model_cfg)
return 0;
287 "could not parse model config: %s\n",
s->model_cfg);
291 s->model_cnt = dict_cnt;
296 for (
unsigned i = 0;
i < dict_cnt;
i++) {
297 VmafModelConfig model_cfg = { 0 };
305 VMAF_MODEL_FLAG_DISABLE_CLIP : 0;
311 VMAF_MODEL_FLAG_ENABLE_TRANSFORM : 0;
316 model_cfg.name = e->
value;
332 err = vmaf_model_load(&
s->model[
i], &model_cfg,
version);
335 "could not load libvmaf model with version: %s\n",
341 if (path && !
s->model[
i]) {
342 err = vmaf_model_load_from_path(&
s->model[
i], &model_cfg, path);
345 "could not load libvmaf model with path: %s\n",
353 "could not load libvmaf model with config: %s\n",
359 VmafFeatureDictionary *feature_opts_dict =
NULL;
360 char *feature_opt =
NULL;
362 char *feature_name =
av_strtok(e->
key,
".", &feature_opt);
366 err = vmaf_feature_dictionary_set(&feature_opts_dict,
367 feature_opt, e->
value);
370 "could not set feature option: %s.%s=%s\n",
371 feature_name, feature_opt, e->
value);
376 err = vmaf_model_feature_overload(
s->model[
i], feature_name,
380 "could not overload feature: %s\n", feature_name);
387 for (
unsigned i = 0;
i <
s->model_cnt;
i++) {
388 err = vmaf_use_features_from_model(
s->vmaf,
s->model[
i]);
391 "problem during vmaf_use_features_from_model\n");
398 for (
unsigned i = 0;
i < dict_cnt;
i++) {
410 return VMAF_LOG_LEVEL_NONE;
412 return VMAF_LOG_LEVEL_ERROR;
414 return VMAF_LOG_LEVEL_WARNING;
416 return VMAF_LOG_LEVEL_INFO;
418 return VMAF_LOG_LEVEL_DEBUG;
420 return VMAF_LOG_LEVEL_INFO;
427 VmafModel *model =
NULL;
428 VmafModelCollection *model_collection =
NULL;
429 enum VmafModelFlags
flags = VMAF_MODEL_FLAGS_DEFAULT;
432 VmafModelConfig model_cfg = {
437 if (
s->enable_transform ||
s->phone_model)
438 flags |= VMAF_MODEL_FLAG_ENABLE_TRANSFORM;
441 goto extra_metrics_only;
443 if (
s->enable_conf_interval) {
444 err = vmaf_model_collection_load_from_path(&model, &model_collection,
445 &model_cfg,
s->model_path);
448 "problem loading model file: %s\n",
s->model_path);
452 err = vmaf_use_features_from_model_collection(
s->vmaf, model_collection);
455 "problem loading feature extractors from model file: %s\n",
460 err = vmaf_model_load_from_path(&model, &model_cfg,
s->model_path);
463 "problem loading model file: %s\n",
s->model_path);
466 err = vmaf_use_features_from_model(
s->vmaf, model);
469 "problem loading feature extractors from model file: %s\n",
477 VmafFeatureDictionary *
d =
NULL;
478 vmaf_feature_dictionary_set(&
d,
"enable_chroma",
"false");
480 err = vmaf_use_feature(
s->vmaf,
"psnr",
d);
483 "problem loading feature extractor: psnr\n");
489 err = vmaf_use_feature(
s->vmaf,
"float_ssim",
NULL);
492 "problem loading feature extractor: ssim\n");
498 err = vmaf_use_feature(
s->vmaf,
"float_ms_ssim",
NULL);
501 "problem loading feature extractor: ms_ssim\n");
515 VmafConfiguration cfg = {
517 .n_subsample =
s->n_subsample,
518 .n_threads =
s->n_threads,
521 err = vmaf_init(&
s->vmaf, cfg);
554 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w) {
559 if (
ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
564 if (
ctx->inputs[0]->format !=
ctx->inputs[1]->format) {
573 s->bpc =
desc->comp[0].depth;
588 outlink->
w = mainlink->
w;
589 outlink->
h = mainlink->
h;
609 return VMAF_OUTPUT_FORMAT_XML;
611 return VMAF_OUTPUT_FORMAT_JSON;
613 return VMAF_OUTPUT_FORMAT_CSV;
615 return VMAF_OUTPUT_FORMAT_SUB;
618 return VMAF_OUTPUT_FORMAT_XML;
625 return VMAF_POOL_METHOD_MIN;
627 return VMAF_POOL_METHOD_MEAN;
629 return VMAF_POOL_METHOD_HARMONIC_MEAN;
632 return VMAF_POOL_METHOD_MEAN;
645 err = vmaf_read_pictures(
s->vmaf,
NULL,
NULL, 0);
648 "problem flushing libvmaf context.\n");
651 for (
unsigned i = 0;
i <
s->model_cnt;
i++) {
654 &vmaf_score, 0,
s->frame_cnt - 1);
657 "problem getting pooled vmaf score.\n");
664 if (
s->log_path && !err)
670 for (
unsigned i = 0;
i <
s->model_cnt;
i++) {
672 vmaf_model_destroy(
s->model[
i]);
703 .preinit = libvmaf_framesync_preinit,
708 .priv_class = &libvmaf_class,
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define AV_LOG_WARNING
Something somehow does not look correct.
AVPixelFormat
Pixel format.
static double psnr(double d)
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
static const AVFilterPad libvmaf_inputs[]
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
#define AV_LOG_QUIET
Print no output.
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define FILTER_PIXFMTS_ARRAY(array)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
This structure describes decoded (raw) audio or video data.
static enum VmafOutputFormat log_fmt_map(const char *log_fmt)
@ AV_PIX_FMT_YUV420P16LE
planar YUV 4:2:0, 24bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
const char * name
Filter name.
A link between two filters.
@ AV_PIX_FMT_YUV444P16LE
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
@ AV_PIX_FMT_YUV420P12LE
planar YUV 4:2:0,18bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
A filter pad used for either input or output.
@ AV_PIX_FMT_YUV420P10LE
planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian
@ AV_PIX_FMT_YUV444P12LE
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const AVFilter ff_vf_libvmaf
static int config_input_ref(AVFilterLink *inlink)
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int copy_picture_data(AVFrame *src, VmafPicture *dst, unsigned bpc)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
FRAMESYNC_DEFINE_CLASS(libvmaf, LIBVMAFContext, fs)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUV444P10LE
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
static int activate(AVFilterContext *ctx)
int av_log_get_level(void)
Get the current log level.
@ AV_PIX_FMT_YUV422P16LE
planar YUV 4:2:2, 32bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Describe the class of an AVClass context structure.
static int do_vmaf(FFFrameSync *fs)
#define fs(width, name, subs,...)
static av_cold void uninit(AVFilterContext *ctx)
static enum AVPixelFormat pix_fmts[]
static enum VmafPoolingMethod pool_method_map(const char *pool_method)
static int config_output(AVFilterLink *outlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
@ AV_PIX_FMT_YUV422P10LE
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
AVFilterContext * src
source filter
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_LOG_INFO
Standard information.
static AVDictionary ** delimited_dict_parse(char *str, unsigned *cnt)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
static const AVFilterPad libvmaf_outputs[]
static enum VmafPixelFormat pix_fmt_map(enum AVPixelFormat av_pix_fmt)
int h
agreed upon image height
static const AVOption libvmaf_options[]
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
static int ref[MAX_W *MAX_W]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
char * av_strdup(const char *s)
Duplicate a string.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static av_cold int init(AVFilterContext *ctx)
#define FILTER_OUTPUTS(array)
static enum VmafLogLevel log_level_map(int log_level)
#define flags(name, subs,...)
static int parse_models(AVFilterContext *ctx)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
static int parse_features(AVFilterContext *ctx)
@ AV_PIX_FMT_YUV422P12LE
planar YUV 4:2:2,24bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
static int parse_deprecated_options(AVFilterContext *ctx)
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
#define AV_OPT_FLAG_DEPRECATED
set if option is deprecated, users should refer to AVOption.help text for more information