| 75 | | {"model_path", "Set the model to be used for computing vmaf.", OFFSET(model_path), AV_OPT_TYPE_STRING, {.str="/usr/share/vmaf/model/vmaf_v0.6.1.json"}, 0, 1, FLAGS}, |
| 76 | | {"log_path", "Set the file path to be used to store logs.", OFFSET(log_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, |
| 77 | | {"log_fmt", "Set the format of the log (csv, json or xml).", OFFSET(log_fmt), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, |
| 78 | | {"enable_transform", "Enables transform for computing vmaf.", OFFSET(enable_transform), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, |
| 79 | | {"phone_model", "Invokes the phone model that will generate higher VMAF scores.", OFFSET(phone_model), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, |
| 80 | | {"psnr", "Enables computing psnr along with vmaf.", OFFSET(psnr), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, |
| 81 | | {"ssim", "Enables computing ssim along with vmaf.", OFFSET(ssim), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, |
| 82 | | {"ms_ssim", "Enables computing ms-ssim along with vmaf.", OFFSET(ms_ssim), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, |
| | 67 | {"model_path", "use model='path=...'.", OFFSET(model_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| | 68 | {"log_path", "Set the file path to be used to write log.", OFFSET(log_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, |
| | 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}, |
| | 70 | {"enable_transform", "use model='enable_transform=true'.", OFFSET(enable_transform), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| | 71 | {"phone_model", "use model='enable_transform=true'.", OFFSET(phone_model), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| | 72 | {"psnr", "use feature='name=psnr'.", OFFSET(psnr), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| | 73 | {"ssim", "use feature='name=ssim'.", OFFSET(ssim), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| | 74 | {"ms_ssim", "use feature='name=ms_ssim'.", OFFSET(ms_ssim), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| 86 | | {"enable_conf_interval", "Enables confidence interval.", OFFSET(enable_conf_interval), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, |
| | 78 | {"enable_conf_interval", "model='enable_conf_interval=true'.", OFFSET(enable_conf_interval), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS|AV_OPT_FLAG_DEPRECATED}, |
| | 79 | {"model", "Set the model to be used for computing vmaf.", OFFSET(model_cfg), AV_OPT_TYPE_STRING, {.str="version=vmaf_v0.6.1"}, 0, 1, FLAGS}, |
| | 80 | {"feature", "Set the feature to be used for computing vmaf.", OFFSET(feature_cfg), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, |
| 92 | | #define read_frame_fn(type, bits) \ |
| 93 | | static int read_frame_##bits##bit(float *ref_data, float *main_data, \ |
| 94 | | float *temp_data, int stride, void *ctx) \ |
| 95 | | { \ |
| 96 | | LIBVMAFContext *s = (LIBVMAFContext *) ctx; \ |
| 97 | | int ret; \ |
| 98 | | \ |
| 99 | | pthread_mutex_lock(&s->lock); \ |
| 100 | | \ |
| 101 | | while (!s->frame_set && !s->eof) { \ |
| 102 | | pthread_cond_wait(&s->cond, &s->lock); \ |
| 103 | | } \ |
| 104 | | \ |
| 105 | | if (s->frame_set) { \ |
| 106 | | int ref_stride = s->gref->linesize[0]; \ |
| 107 | | int main_stride = s->gmain->linesize[0]; \ |
| 108 | | \ |
| 109 | | const type *ref_ptr = (const type *) s->gref->data[0]; \ |
| 110 | | const type *main_ptr = (const type *) s->gmain->data[0]; \ |
| 111 | | \ |
| 112 | | float *ptr = ref_data; \ |
| 113 | | float factor = 1.f / (1 << (bits - 8)); \ |
| 114 | | \ |
| 115 | | int h = s->height; \ |
| 116 | | int w = s->width; \ |
| 117 | | \ |
| 118 | | int i,j; \ |
| 119 | | \ |
| 120 | | for (i = 0; i < h; i++) { \ |
| 121 | | for ( j = 0; j < w; j++) { \ |
| 122 | | ptr[j] = ref_ptr[j] * factor; \ |
| 123 | | } \ |
| 124 | | ref_ptr += ref_stride / sizeof(*ref_ptr); \ |
| 125 | | ptr += stride / sizeof(*ptr); \ |
| 126 | | } \ |
| 127 | | \ |
| 128 | | ptr = main_data; \ |
| 129 | | \ |
| 130 | | for (i = 0; i < h; i++) { \ |
| 131 | | for (j = 0; j < w; j++) { \ |
| 132 | | ptr[j] = main_ptr[j] * factor; \ |
| 133 | | } \ |
| 134 | | main_ptr += main_stride / sizeof(*main_ptr); \ |
| 135 | | ptr += stride / sizeof(*ptr); \ |
| 136 | | } \ |
| 137 | | } \ |
| 138 | | \ |
| 139 | | ret = !s->frame_set; \ |
| 140 | | \ |
| 141 | | av_frame_unref(s->gref); \ |
| 142 | | av_frame_unref(s->gmain); \ |
| 143 | | s->frame_set = 0; \ |
| 144 | | \ |
| 145 | | pthread_cond_signal(&s->cond); \ |
| 146 | | pthread_mutex_unlock(&s->lock); \ |
| 147 | | \ |
| 148 | | if (ret) { \ |
| 149 | | return 2; \ |
| 150 | | } \ |
| 151 | | \ |
| 152 | | return 0; \ |
| 153 | | } |
| 154 | | |
| 155 | | read_frame_fn(uint8_t, 8); |
| 156 | | read_frame_fn(uint16_t, 10); |
| 157 | | |
| 158 | | static void compute_vmaf_score(LIBVMAFContext *s) |
| 159 | | { |
| 160 | | int (*read_frame)(float *ref_data, float *main_data, float *temp_data, |
| 161 | | int stride, void *ctx); |
| 162 | | char *format; |
| 163 | | |
| 164 | | if (s->desc->comp[0].depth <= 8) { |
| 165 | | read_frame = read_frame_8bit; |
| 166 | | } else { |
| 167 | | read_frame = read_frame_10bit; |
| | 86 | static enum VmafPixelFormat pix_fmt_map(enum AVPixelFormat av_pix_fmt) |
| | 87 | { |
| | 88 | switch (av_pix_fmt) { |
| | 89 | case AV_PIX_FMT_YUV420P: |
| | 90 | case AV_PIX_FMT_YUV420P10LE: |
| | 91 | case AV_PIX_FMT_YUV420P12LE: |
| | 92 | case AV_PIX_FMT_YUV420P16LE: |
| | 93 | return VMAF_PIX_FMT_YUV420P; |
| | 94 | case AV_PIX_FMT_YUV422P: |
| | 95 | case AV_PIX_FMT_YUV422P10LE: |
| | 96 | case AV_PIX_FMT_YUV422P12LE: |
| | 97 | case AV_PIX_FMT_YUV422P16LE: |
| | 98 | return VMAF_PIX_FMT_YUV422P; |
| | 99 | case AV_PIX_FMT_YUV444P: |
| | 100 | case AV_PIX_FMT_YUV444P10LE: |
| | 101 | case AV_PIX_FMT_YUV444P12LE: |
| | 102 | case AV_PIX_FMT_YUV444P16LE: |
| | 103 | return VMAF_PIX_FMT_YUV444P; |
| | 104 | default: |
| | 105 | return VMAF_PIX_FMT_UNKNOWN; |
| 182 | | LIBVMAFContext *s = (LIBVMAFContext *) ctx; |
| 183 | | compute_vmaf_score(s); |
| 184 | | if (!s->error) { |
| 185 | | av_log(ctx, AV_LOG_INFO, "VMAF score: %f\n",s->vmaf_score); |
| 186 | | } else { |
| 187 | | pthread_mutex_lock(&s->lock); |
| 188 | | pthread_cond_signal(&s->cond); |
| 189 | | pthread_mutex_unlock(&s->lock); |
| | 111 | int err = vmaf_picture_alloc(dst, pix_fmt_map(src->format), bpc, |
| | 112 | src->width, src->height); |
| | 113 | if (err) |
| | 114 | return AVERROR(ENOMEM); |
| | 115 | |
| | 116 | for (unsigned i = 0; i < 3; i++) { |
| | 117 | uint8_t *src_data = src->data[i]; |
| | 118 | uint8_t *dst_data = dst->data[i]; |
| | 119 | for (unsigned j = 0; j < dst->h[i]; j++) { |
| | 120 | memcpy(dst_data, src_data, sizeof(*dst_data) * dst->w[i]); |
| | 121 | src_data += src->linesize[i]; |
| | 122 | dst_data += dst->stride[i]; |
| | 123 | } |
| 205 | | if (!ref) |
| 206 | | return ff_filter_frame(ctx->outputs[0], master); |
| | 140 | if (ctx->is_disabled || !ref) |
| | 141 | return ff_filter_frame(ctx->outputs[0], dist); |
| | 142 | |
| | 143 | err = copy_picture_data(ref, &pic_ref, s->bpc); |
| | 144 | if (err) { |
| | 145 | av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n"); |
| | 146 | return AVERROR(ENOMEM); |
| | 147 | } |
| | 148 | |
| | 149 | err = copy_picture_data(dist, &pic_dist, s->bpc); |
| | 150 | if (err) { |
| | 151 | av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n"); |
| | 152 | vmaf_picture_unref(&pic_ref); |
| | 153 | return AVERROR(ENOMEM); |
| | 154 | } |
| | 155 | |
| | 156 | err = vmaf_read_pictures(s->vmaf, &pic_ref, &pic_dist, s->frame_cnt++); |
| | 157 | if (err) { |
| | 158 | av_log(s, AV_LOG_ERROR, "problem during vmaf_read_pictures.\n"); |
| | 159 | return AVERROR(EINVAL); |
| | 160 | } |
| | 161 | |
| | 162 | return ff_filter_frame(ctx->outputs[0], dist); |
| | 163 | } |
| | 164 | |
| | 165 | static AVDictionary **delimited_dict_parse(char *str, unsigned *cnt) |
| | 166 | { |
| | 167 | AVDictionary **dict = NULL; |
| | 168 | char *str_copy = NULL; |
| | 169 | char *saveptr = NULL; |
| | 170 | unsigned cnt2; |
| | 171 | int err = 0; |
| | 172 | |
| | 173 | if (!str) |
| | 174 | return NULL; |
| | 175 | |
| | 176 | cnt2 = 1; |
| | 177 | for (char *p = str; *p; p++) { |
| | 178 | if (*p == '|') |
| | 179 | cnt2++; |
| | 180 | } |
| | 181 | |
| | 182 | dict = av_calloc(cnt2, sizeof(*dict)); |
| | 183 | if (!dict) |
| | 184 | goto fail; |
| | 185 | |
| | 186 | str_copy = av_strdup(str); |
| | 187 | if (!str_copy) |
| | 188 | goto fail; |
| | 189 | |
| | 190 | *cnt = 0; |
| | 191 | for (unsigned i = 0; i < cnt2; i++) { |
| | 192 | char *s = av_strtok(i == 0 ? str_copy : NULL, "|", &saveptr); |
| | 193 | if (!s) |
| | 194 | continue; |
| | 195 | err = av_dict_parse_string(&dict[(*cnt)++], s, "=", ":", 0); |
| | 196 | if (err) |
| | 197 | goto fail; |
| | 198 | } |
| | 199 | |
| | 200 | av_free(str_copy); |
| | 201 | return dict; |
| | 202 | |
| | 203 | fail: |
| | 204 | if (dict) { |
| | 205 | for (unsigned i = 0; i < *cnt; i++) { |
| | 206 | if (dict[i]) |
| | 207 | av_dict_free(&dict[i]); |
| | 208 | } |
| | 209 | av_free(dict); |
| | 210 | } |
| | 211 | |
| | 212 | av_free(str_copy); |
| | 213 | *cnt = 0; |
| | 214 | return NULL; |
| | 215 | } |
| | 216 | |
| | 217 | static int parse_features(AVFilterContext *ctx) |
| | 218 | { |
| | 219 | LIBVMAFContext *s = ctx->priv; |
| | 220 | AVDictionary **dict = NULL; |
| | 221 | unsigned dict_cnt; |
| | 222 | int err = 0; |
| 210 | | while (s->frame_set && !s->error) { |
| 211 | | pthread_cond_wait(&s->cond, &s->lock); |
| | 227 | dict = delimited_dict_parse(s->feature_cfg, &dict_cnt); |
| | 228 | if (!dict) { |
| | 229 | av_log(ctx, AV_LOG_ERROR, |
| | 230 | "could not parse feature config: %s\n", s->feature_cfg); |
| | 231 | return AVERROR(EINVAL); |
| | 232 | } |
| | 233 | |
| | 234 | for (unsigned i = 0; i < dict_cnt; i++) { |
| | 235 | char *feature_name = NULL; |
| | 236 | VmafFeatureDictionary *feature_opts_dict = NULL; |
| | 237 | AVDictionaryEntry *e = NULL; |
| | 238 | |
| | 239 | while (e = av_dict_get(dict[i], "", e, AV_DICT_IGNORE_SUFFIX)) { |
| | 240 | if (av_stristr(e->key, "name")) { |
| | 241 | feature_name = e->value; |
| | 242 | continue; |
| | 243 | } |
| | 244 | |
| | 245 | err = vmaf_feature_dictionary_set(&feature_opts_dict, e->key, |
| | 246 | e->value); |
| | 247 | if (err) { |
| | 248 | av_log(ctx, AV_LOG_ERROR, |
| | 249 | "could not set feature option: %s.%s=%s\n", |
| | 250 | feature_name, e->key, e->value); |
| | 251 | goto exit; |
| | 252 | } |
| | 253 | } |
| | 254 | |
| | 255 | err = vmaf_use_feature(s->vmaf, feature_name, feature_opts_dict); |
| | 256 | if (err) { |
| | 257 | av_log(ctx, AV_LOG_ERROR, |
| | 258 | "problem during vmaf_use_feature: %s\n", feature_name); |
| | 259 | goto exit; |
| | 260 | } |
| 224 | | s->frame_set = 1; |
| | 294 | for (unsigned i = 0; i < dict_cnt; i++) { |
| | 295 | VmafModelConfig model_cfg = { 0 }; |
| | 296 | AVDictionaryEntry *e = NULL; |
| | 297 | char *version = NULL; |
| | 298 | char *path = NULL; |
| | 299 | |
| | 300 | while (e = av_dict_get(dict[i], "", e, AV_DICT_IGNORE_SUFFIX)) { |
| | 301 | if (av_stristr(e->key, "disable_clip")) { |
| | 302 | model_cfg.flags |= av_stristr(e->value, "true") ? |
| | 303 | VMAF_MODEL_FLAG_DISABLE_CLIP : 0; |
| | 304 | continue; |
| | 305 | } |
| | 306 | |
| | 307 | if (av_stristr(e->key, "enable_transform")) { |
| | 308 | model_cfg.flags |= av_stristr(e->value, "true") ? |
| | 309 | VMAF_MODEL_FLAG_ENABLE_TRANSFORM : 0; |
| | 310 | continue; |
| | 311 | } |
| | 312 | |
| | 313 | if (av_stristr(e->key, "name")) { |
| | 314 | model_cfg.name = e->value; |
| | 315 | continue; |
| | 316 | } |
| | 317 | |
| | 318 | if (av_stristr(e->key, "version")) { |
| | 319 | version = e->value; |
| | 320 | continue; |
| | 321 | } |
| | 322 | |
| | 323 | if (av_stristr(e->key, "path")) { |
| | 324 | path = e->value; |
| | 325 | continue; |
| | 326 | } |
| | 327 | } |
| | 328 | |
| | 329 | if (version) { |
| | 330 | err = vmaf_model_load(&s->model[i], &model_cfg, version); |
| | 331 | if (err) { |
| | 332 | av_log(ctx, AV_LOG_ERROR, |
| | 333 | "could not load libvmaf model with version: %s\n", |
| | 334 | version); |
| | 335 | goto exit; |
| | 336 | } |
| | 337 | } |
| | 338 | |
| | 339 | if (path && !s->model[i]) { |
| | 340 | err = vmaf_model_load_from_path(&s->model[i], &model_cfg, path); |
| | 341 | if (err) { |
| | 342 | av_log(ctx, AV_LOG_ERROR, |
| | 343 | "could not load libvmaf model with path: %s\n", |
| | 344 | path); |
| | 345 | goto exit; |
| | 346 | } |
| | 347 | } |
| | 348 | |
| | 349 | if (!s->model[i]) { |
| | 350 | av_log(ctx, AV_LOG_ERROR, |
| | 351 | "could not load libvmaf model with config: %s\n", |
| | 352 | s->model_cfg); |
| | 353 | goto exit; |
| | 354 | } |
| | 355 | |
| | 356 | while (e = av_dict_get(dict[i], "", e, AV_DICT_IGNORE_SUFFIX)) { |
| | 357 | VmafFeatureDictionary *feature_opts_dict = NULL; |
| | 358 | char *feature_opt = NULL; |
| | 359 | |
| | 360 | char *feature_name = av_strtok(e->key, ".", &feature_opt); |
| | 361 | if (!feature_opt) |
| | 362 | continue; |
| | 363 | |
| | 364 | err = vmaf_feature_dictionary_set(&feature_opts_dict, |
| | 365 | feature_opt, e->value); |
| | 366 | if (err) { |
| | 367 | av_log(ctx, AV_LOG_ERROR, |
| | 368 | "could not set feature option: %s.%s=%s\n", |
| | 369 | feature_name, feature_opt, e->value); |
| | 370 | err = AVERROR(EINVAL); |
| | 371 | goto exit; |
| | 372 | } |
| | 373 | |
| | 374 | err = vmaf_model_feature_overload(s->model[i], feature_name, |
| | 375 | feature_opts_dict); |
| | 376 | if (err) { |
| | 377 | av_log(ctx, AV_LOG_ERROR, |
| | 378 | "could not overload feature: %s\n", feature_name); |
| | 379 | err = AVERROR(EINVAL); |
| | 380 | goto exit; |
| | 381 | } |
| | 382 | } |
| | 383 | } |
| 229 | | return ff_filter_frame(ctx->outputs[0], master); |
| | 395 | exit: |
| | 396 | for (unsigned i = 0; i < dict_cnt; i++) { |
| | 397 | if (dict[i]) |
| | 398 | av_dict_free(&dict[i]); |
| | 399 | } |
| | 400 | av_free(dict); |
| | 401 | return err; |
| | 402 | } |
| | 403 | |
| | 404 | static enum VmafLogLevel log_level_map(int log_level) |
| | 405 | { |
| | 406 | switch (log_level) { |
| | 407 | case AV_LOG_QUIET: |
| | 408 | return VMAF_LOG_LEVEL_NONE; |
| | 409 | case AV_LOG_ERROR: |
| | 410 | return VMAF_LOG_LEVEL_ERROR; |
| | 411 | case AV_LOG_WARNING: |
| | 412 | return VMAF_LOG_LEVEL_WARNING; |
| | 413 | case AV_LOG_INFO: |
| | 414 | return VMAF_LOG_LEVEL_INFO; |
| | 415 | case AV_LOG_DEBUG: |
| | 416 | return VMAF_LOG_LEVEL_DEBUG; |
| | 417 | default: |
| | 418 | return VMAF_LOG_LEVEL_INFO; |
| | 419 | } |
| | 420 | } |
| | 421 | |
| | 422 | static int parse_deprecated_options(AVFilterContext *ctx) |
| | 423 | { |
| | 424 | LIBVMAFContext *s = ctx->priv; |
| | 425 | VmafModel *model = NULL; |
| | 426 | VmafModelCollection *model_collection = NULL; |
| | 427 | enum VmafModelFlags flags = VMAF_MODEL_FLAGS_DEFAULT; |
| | 428 | int err = 0; |
| | 429 | |
| | 430 | VmafModelConfig model_cfg = { |
| | 431 | .name = "vmaf", |
| | 432 | .flags = flags, |
| | 433 | }; |
| | 434 | |
| | 435 | if (s->enable_transform || s->phone_model) |
| | 436 | flags |= VMAF_MODEL_FLAG_ENABLE_TRANSFORM; |
| | 437 | |
| | 438 | if (!s->model_path) |
| | 439 | goto extra_metrics_only; |
| | 440 | |
| | 441 | if (s->enable_conf_interval) { |
| | 442 | err = vmaf_model_collection_load_from_path(&model, &model_collection, |
| | 443 | &model_cfg, s->model_path); |
| | 444 | if (err) { |
| | 445 | av_log(ctx, AV_LOG_ERROR, |
| | 446 | "problem loading model file: %s\n", s->model_path); |
| | 447 | goto exit; |
| | 448 | } |
| | 449 | |
| | 450 | err = vmaf_use_features_from_model_collection(s->vmaf, model_collection); |
| | 451 | if (err) { |
| | 452 | av_log(ctx, AV_LOG_ERROR, |
| | 453 | "problem loading feature extractors from model file: %s\n", |
| | 454 | s->model_path); |
| | 455 | goto exit; |
| | 456 | } |
| | 457 | } else { |
| | 458 | err = vmaf_model_load_from_path(&model, &model_cfg, s->model_path); |
| | 459 | if (err) { |
| | 460 | av_log(ctx, AV_LOG_ERROR, |
| | 461 | "problem loading model file: %s\n", s->model_path); |
| | 462 | goto exit; |
| | 463 | } |
| | 464 | err = vmaf_use_features_from_model(s->vmaf, model); |
| | 465 | if (err) { |
| | 466 | av_log(ctx, AV_LOG_ERROR, |
| | 467 | "problem loading feature extractors from model file: %s\n", |
| | 468 | s->model_path); |
| | 469 | goto exit; |
| | 470 | } |
| | 471 | } |
| | 472 | |
| | 473 | extra_metrics_only: |
| | 474 | if (s->psnr) { |
| | 475 | VmafFeatureDictionary *d = NULL; |
| | 476 | vmaf_feature_dictionary_set(&d, "enable_chroma", "false"); |
| | 477 | |
| | 478 | err = vmaf_use_feature(s->vmaf, "psnr", d); |
| | 479 | if (err) { |
| | 480 | av_log(ctx, AV_LOG_ERROR, |
| | 481 | "problem loading feature extractor: psnr\n"); |
| | 482 | goto exit; |
| | 483 | } |
| | 484 | } |
| | 485 | |
| | 486 | if (s->ssim) { |
| | 487 | err = vmaf_use_feature(s->vmaf, "float_ssim", NULL); |
| | 488 | if (err) { |
| | 489 | av_log(ctx, AV_LOG_ERROR, |
| | 490 | "problem loading feature extractor: ssim\n"); |
| | 491 | goto exit; |
| | 492 | } |
| | 493 | } |
| | 494 | |
| | 495 | if (s->ms_ssim) { |
| | 496 | err = vmaf_use_feature(s->vmaf, "float_ms_ssim", NULL); |
| | 497 | if (err) { |
| | 498 | av_log(ctx, AV_LOG_ERROR, |
| | 499 | "problem loading feature extractor: ms_ssim\n"); |
| | 500 | goto exit; |
| | 501 | } |
| | 502 | } |
| | 503 | |
| | 504 | exit: |
| | 505 | return err; |
| | 612 | static enum VmafOutputFormat log_fmt_map(const char *log_fmt) |
| | 613 | { |
| | 614 | if (log_fmt) { |
| | 615 | if (av_stristr(log_fmt, "xml")) |
| | 616 | return VMAF_OUTPUT_FORMAT_XML; |
| | 617 | if (av_stristr(log_fmt, "json")) |
| | 618 | return VMAF_OUTPUT_FORMAT_JSON; |
| | 619 | if (av_stristr(log_fmt, "csv")) |
| | 620 | return VMAF_OUTPUT_FORMAT_CSV; |
| | 621 | if (av_stristr(log_fmt, "sub")) |
| | 622 | return VMAF_OUTPUT_FORMAT_SUB; |
| | 623 | } |
| | 624 | |
| | 625 | return VMAF_OUTPUT_FORMAT_XML; |
| | 626 | } |
| | 627 | |
| | 628 | static enum VmafPoolingMethod pool_method_map(const char *pool_method) |
| | 629 | { |
| | 630 | if (pool_method) { |
| | 631 | if (av_stristr(pool_method, "min")) |
| | 632 | return VMAF_POOL_METHOD_MIN; |
| | 633 | if (av_stristr(pool_method, "mean")) |
| | 634 | return VMAF_POOL_METHOD_MEAN; |
| | 635 | if (av_stristr(pool_method, "harmonic_mean")) |
| | 636 | return VMAF_POOL_METHOD_HARMONIC_MEAN; |
| | 637 | } |
| | 638 | |
| | 639 | return VMAF_POOL_METHOD_MEAN; |
| | 640 | } |
| | 641 | |
| 329 | | pthread_mutex_lock(&s->lock); |
| 330 | | s->eof = 1; |
| 331 | | pthread_cond_signal(&s->cond); |
| 332 | | pthread_mutex_unlock(&s->lock); |
| 333 | | |
| 334 | | if (s->vmaf_thread_created) |
| 335 | | { |
| 336 | | pthread_join(s->vmaf_thread, NULL); |
| 337 | | s->vmaf_thread_created = 0; |
| | 649 | if (!s->frame_cnt) |
| | 650 | goto clean_up; |
| | 651 | |
| | 652 | err = vmaf_read_pictures(s->vmaf, NULL, NULL, 0); |
| | 653 | if (err) { |
| | 654 | av_log(ctx, AV_LOG_ERROR, |
| | 655 | "problem flushing libvmaf context.\n"); |
| | 656 | } |
| | 657 | |
| | 658 | for (unsigned i = 0; i < s->model_cnt; i++) { |
| | 659 | double vmaf_score; |
| | 660 | err = vmaf_score_pooled(s->vmaf, s->model[i], pool_method_map(s->pool), |
| | 661 | &vmaf_score, 0, s->frame_cnt - 1); |
| | 662 | if (err) { |
| | 663 | av_log(ctx, AV_LOG_ERROR, |
| | 664 | "problem getting pooled vmaf score.\n"); |
| | 665 | } |
| | 666 | |
| | 667 | av_log(ctx, AV_LOG_INFO, "VMAF score: %f\n", vmaf_score); |