Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From c6221675fce8057905439b80166535002e9f1431 Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Tue, 30 May 2017 05:03:20 +0000
- Subject: [PATCH 01/18] Added vf_vmaf.c and vmaf.h files
- ---
- libavfilter/vf_vmaf.c | 418 ++++++++++++++++++++++++++++++++++++++++++++++++++
- libavfilter/vmaf.h | 33 ++++
- 2 files changed, 451 insertions(+)
- create mode 100644 libavfilter/vf_vmaf.c
- create mode 100644 libavfilter/vmaf.h
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- new file mode 100644
- index 0000000..53bb8a4
- --- /dev/null
- +++ b/libavfilter/vf_vmaf.c
- @@ -0,0 +1,418 @@
- +/*
- + * Copyright (c) 2011 Roger Pau Monné <roger.pau@entel.upc.edu>
- + * Copyright (c) 2011 Stefano Sabatini
- + * Copyright (c) 2013 Paul B Mahol
- + *
- + * This file is part of FFmpeg.
- + *
- + * FFmpeg is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2.1 of the License, or (at your option) any later version.
- + *
- + * FFmpeg is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with FFmpeg; if not, write to the Free Software
- + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- + */
- +
- +/**
- + * @file
- + * Caculate the VMAF between two input videos.
- + */
- +
- +#include "libavutil/avstring.h"
- +#include "libavutil/opt.h"
- +#include "libavutil/pixdesc.h"
- +#include "avfilter.h"
- +#include "dualinput.h"
- +#include "drawutils.h"
- +#include "formats.h"
- +#include "internal.h"
- +#include "vmaf.h"
- +#include "video.h"
- +
- +typedef struct VMAFContext {
- + const AVClass *class;
- + FFDualInputContext dinput;
- + double mse, min_mse, max_mse, mse_comp[4];
- + uint64_t nb_frames;
- + FILE *stats_file;
- + char *stats_file_str;
- + int stats_version;
- + int stats_header_written;
- + int stats_add_max;
- + int max[4], average_max;
- + int is_rgb;
- + uint8_t rgba_map[4];
- + char comps[4];
- + int nb_components;
- + int planewidth[4];
- + int planeheight[4];
- + double planeweight[4];
- + VMAFDSPContext dsp;
- +} VMAFContext;
- +
- +#define OFFSET(x) offsetof(VMAFContext, x)
- +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
- +
- +static const AVOption vmaf_options[] = {
- + {"stats_file", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
- + {"f", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
- + {"stats_version", "Set the format version for the stats file.", OFFSET(stats_version), AV_OPT_TYPE_INT, {.i64=1}, 1, 2, FLAGS },
- + {"output_max", "Add raw stats (max values) to the output log.", OFFSET(stats_add_max), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
- + { NULL }
- +};
- +
- +AVFILTER_DEFINE_CLASS(vmaf);
- +
- +static inline unsigned pow_2(unsigned base)
- +{
- + return base*base;
- +}
- +
- +static inline double get_vmaf(double mse, uint64_t nb_frames, int max)
- +{
- + return 10.0 * log10(pow_2(max) / (mse / nb_frames));
- +}
- +
- +static uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
- +{
- + int j;
- + unsigned m2 = 0;
- +
- + for (j = 0; j < outw; j++)
- + m2 += pow_2(main_line[j] - ref_line[j]);
- +
- + return m2;
- +}
- +
- +static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t *_ref_line, int outw)
- +{
- + int j;
- + uint64_t m2 = 0;
- + const uint16_t *main_line = (const uint16_t *) _main_line;
- + const uint16_t *ref_line = (const uint16_t *) _ref_line;
- +
- + for (j = 0; j < outw; j++)
- + m2 += pow_2(main_line[j] - ref_line[j]);
- +
- + return m2;
- +}
- +
- +static inline
- +void compute_images_mse(VMAFContext *s,
- + const uint8_t *main_data[4], const int main_linesizes[4],
- + const uint8_t *ref_data[4], const int ref_linesizes[4],
- + int w, int h, double mse[4])
- +{
- + int i, c;
- +
- + for (c = 0; c < s->nb_components; c++) {
- + const int outw = s->planewidth[c];
- + const int outh = s->planeheight[c];
- + const uint8_t *main_line = main_data[c];
- + const uint8_t *ref_line = ref_data[c];
- + const int ref_linesize = ref_linesizes[c];
- + const int main_linesize = main_linesizes[c];
- + uint64_t m = 0;
- + for (i = 0; i < outh; i++) {
- + m += s->dsp.sse_line(main_line, ref_line, outw);
- + ref_line += ref_linesize;
- + main_line += main_linesize;
- + }
- + mse[c] = m / (double)(outw * outh);
- + }
- +}
- +
- +static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
- +{
- + char value[128];
- + snprintf(value, sizeof(value), "%0.2f", d);
- + if (comp) {
- + char key2[128];
- + snprintf(key2, sizeof(key2), "%s%c", key, comp);
- + av_dict_set(metadata, key2, value, 0);
- + } else {
- + av_dict_set(metadata, key, value, 0);
- + }
- +}
- +
- +static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main,
- + const AVFrame *ref)
- +{
- + VMAFContext *s = ctx->priv;
- + double comp_mse[4], mse = 0;
- + int j, c;
- + AVDictionary **metadata = &main->metadata;
- +
- + compute_images_mse(s, (const uint8_t **)main->data, main->linesize,
- + (const uint8_t **)ref->data, ref->linesize,
- + main->width, main->height, comp_mse);
- +
- + for (j = 0; j < s->nb_components; j++)
- + mse += comp_mse[j] * s->planeweight[j];
- +
- + s->min_mse = FFMIN(s->min_mse, mse);
- + s->max_mse = FFMAX(s->max_mse, mse);
- +
- + s->mse += mse;
- + for (j = 0; j < s->nb_components; j++)
- + s->mse_comp[j] += comp_mse[j];
- + s->nb_frames++;
- +
- + for (j = 0; j < s->nb_components; j++) {
- + c = s->is_rgb ? s->rgba_map[j] : j;
- + set_meta(metadata, "lavfi.vmaf.mse.", s->comps[j], comp_mse[c]);
- + set_meta(metadata, "lavfi.vmaf.vmaf.", s->comps[j], get_vmaf(comp_mse[c], 1, s->max[c]));
- + }
- + set_meta(metadata, "lavfi.vmaf.mse_avg", 0, mse);
- + set_meta(metadata, "lavfi.vmaf.vmaf_avg", 0, get_vmaf(mse, 1, s->average_max));
- +
- + if (s->stats_file) {
- + if (s->stats_version == 2 && !s->stats_header_written) {
- + fprintf(s->stats_file, "vmaf_log_version:2 fields:n");
- + fprintf(s->stats_file, ",mse_avg");
- + for (j = 0; j < s->nb_components; j++) {
- + fprintf(s->stats_file, ",mse_%c", s->comps[j]);
- + }
- + fprintf(s->stats_file, ",vmaf_avg");
- + for (j = 0; j < s->nb_components; j++) {
- + fprintf(s->stats_file, ",vmaf_%c", s->comps[j]);
- + }
- + if (s->stats_add_max) {
- + fprintf(s->stats_file, ",max_avg");
- + for (j = 0; j < s->nb_components; j++) {
- + fprintf(s->stats_file, ",max_%c", s->comps[j]);
- + }
- + }
- + fprintf(s->stats_file, "\n");
- + s->stats_header_written = 1;
- + }
- + fprintf(s->stats_file, "n:%"PRId64" mse_avg:%0.2f ", s->nb_frames, mse);
- + for (j = 0; j < s->nb_components; j++) {
- + c = s->is_rgb ? s->rgba_map[j] : j;
- + fprintf(s->stats_file, "mse_%c:%0.2f ", s->comps[j], comp_mse[c]);
- + }
- + fprintf(s->stats_file, "vmaf_avg:%0.2f ", get_vmaf(mse, 1, s->average_max));
- + for (j = 0; j < s->nb_components; j++) {
- + c = s->is_rgb ? s->rgba_map[j] : j;
- + fprintf(s->stats_file, "vmaf_%c:%0.2f ", s->comps[j],
- + get_vmaf(comp_mse[c], 1, s->max[c]));
- + }
- + if (s->stats_version == 2 && s->stats_add_max) {
- + fprintf(s->stats_file, "max_avg:%d ", s->average_max);
- + for (j = 0; j < s->nb_components; j++) {
- + c = s->is_rgb ? s->rgba_map[j] : j;
- + fprintf(s->stats_file, "max_%c:%d ", s->comps[j], s->max[c]);
- + }
- + }
- + fprintf(s->stats_file, "\n");
- + }
- +
- + return main;
- +}
- +
- +static av_cold int init(AVFilterContext *ctx)
- +{
- + VMAFContext *s = ctx->priv;
- +
- + s->min_mse = +INFINITY;
- + s->max_mse = -INFINITY;
- +
- + if (s->stats_file_str) {
- + if (s->stats_version < 2 && s->stats_add_max) {
- + av_log(ctx, AV_LOG_ERROR,
- + "stats_add_max was specified but stats_version < 2.\n" );
- + return AVERROR(EINVAL);
- + }
- + if (!strcmp(s->stats_file_str, "-")) {
- + s->stats_file = stdout;
- + } else {
- + s->stats_file = fopen(s->stats_file_str, "w");
- + if (!s->stats_file) {
- + int err = AVERROR(errno);
- + char buf[128];
- + av_strerror(err, buf, sizeof(buf));
- + av_log(ctx, AV_LOG_ERROR, "Could not open stats file %s: %s\n",
- + s->stats_file_str, buf);
- + return err;
- + }
- + }
- + }
- +
- + s->dinput.process = do_vmaf;
- + return 0;
- +}
- +
- +static int query_formats(AVFilterContext *ctx)
- +{
- + static const enum AVPixelFormat pix_fmts[] = {
- + AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16,
- +#define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
- +#define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
- +#define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
- + PF(P), PF(P9), PF(P10), PF_NOALPHA(P12), PF_NOALPHA(P14), PF(P16),
- + AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
- + AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
- + AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
- + AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
- + AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
- + AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP16,
- + AV_PIX_FMT_NONE
- + };
- +
- + AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
- + if (!fmts_list)
- + return AVERROR(ENOMEM);
- + return ff_set_common_formats(ctx, fmts_list);
- +}
- +
- +static int config_input_ref(AVFilterLink *inlink)
- +{
- + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
- + AVFilterContext *ctx = inlink->dst;
- + VMAFContext *s = ctx->priv;
- + double average_max;
- + unsigned sum;
- + int j;
- +
- + s->nb_components = desc->nb_components;
- + if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
- + ctx->inputs[0]->h != ctx->inputs[1]->h) {
- + av_log(ctx, AV_LOG_ERROR, "Width and height of input videos must be same.\n");
- + return AVERROR(EINVAL);
- + }
- + if (ctx->inputs[0]->format != ctx->inputs[1]->format) {
- + av_log(ctx, AV_LOG_ERROR, "Inputs must be of same pixel format.\n");
- + return AVERROR(EINVAL);
- + }
- +
- + s->max[0] = (1 << desc->comp[0].depth) - 1;
- + s->max[1] = (1 << desc->comp[1].depth) - 1;
- + s->max[2] = (1 << desc->comp[2].depth) - 1;
- + s->max[3] = (1 << desc->comp[3].depth) - 1;
- +
- + s->is_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0;
- + s->comps[0] = s->is_rgb ? 'r' : 'y' ;
- + s->comps[1] = s->is_rgb ? 'g' : 'u' ;
- + s->comps[2] = s->is_rgb ? 'b' : 'v' ;
- + s->comps[3] = 'a';
- +
- + s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
- + s->planeheight[0] = s->planeheight[3] = inlink->h;
- + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
- + s->planewidth[0] = s->planewidth[3] = inlink->w;
- + sum = 0;
- + for (j = 0; j < s->nb_components; j++)
- + sum += s->planeheight[j] * s->planewidth[j];
- + average_max = 0;
- + for (j = 0; j < s->nb_components; j++) {
- + s->planeweight[j] = (double) s->planeheight[j] * s->planewidth[j] / sum;
- + average_max += s->max[j] * s->planeweight[j];
- + }
- + s->average_max = lrint(average_max);
- +
- + s->dsp.sse_line = desc->comp[0].depth > 8 ? sse_line_16bit : sse_line_8bit;
- + if (ARCH_X86)
- + ff_vmaf_init_x86(&s->dsp, desc->comp[0].depth);
- +
- + return 0;
- +}
- +
- +static int config_output(AVFilterLink *outlink)
- +{
- + AVFilterContext *ctx = outlink->src;
- + VMAFContext *s = ctx->priv;
- + AVFilterLink *mainlink = ctx->inputs[0];
- + int ret;
- +
- + outlink->w = mainlink->w;
- + outlink->h = mainlink->h;
- + outlink->time_base = mainlink->time_base;
- + outlink->sample_aspect_ratio = mainlink->sample_aspect_ratio;
- + outlink->frame_rate = mainlink->frame_rate;
- + if ((ret = ff_dualinput_init(ctx, &s->dinput)) < 0)
- + return ret;
- +
- + return 0;
- +}
- +
- +static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
- +{
- + VMAFContext *s = inlink->dst->priv;
- + return ff_dualinput_filter_frame(&s->dinput, inlink, inpicref);
- +}
- +
- +static int request_frame(AVFilterLink *outlink)
- +{
- + VMAFContext *s = outlink->src->priv;
- + return ff_dualinput_request_frame(&s->dinput, outlink);
- +}
- +
- +static av_cold void uninit(AVFilterContext *ctx)
- +{
- + VMAFContext *s = ctx->priv;
- +
- + if (s->nb_frames > 0) {
- + int j;
- + char buf[256];
- +
- + buf[0] = 0;
- + for (j = 0; j < s->nb_components; j++) {
- + int c = s->is_rgb ? s->rgba_map[j] : j;
- + av_strlcatf(buf, sizeof(buf), " %c:%f", s->comps[j],
- + get_vmaf(s->mse_comp[c], s->nb_frames, s->max[c]));
- + }
- + av_log(ctx, AV_LOG_INFO, "VMAF%s average:%f min:%f max:%f\n",
- + buf,
- + get_vmaf(s->mse, s->nb_frames, s->average_max),
- + get_vmaf(s->max_mse, 1, s->average_max),
- + get_vmaf(s->min_mse, 1, s->average_max));
- + }
- +
- + ff_dualinput_uninit(&s->dinput);
- +
- + if (s->stats_file && s->stats_file != stdout)
- + fclose(s->stats_file);
- +}
- +
- +static const AVFilterPad vmaf_inputs[] = {
- + {
- + .name = "main",
- + .type = AVMEDIA_TYPE_VIDEO,
- + .filter_frame = filter_frame,
- + },{
- + .name = "reference",
- + .type = AVMEDIA_TYPE_VIDEO,
- + .filter_frame = filter_frame,
- + .config_props = config_input_ref,
- + },
- + { NULL }
- +};
- +
- +static const AVFilterPad vmaf_outputs[] = {
- + {
- + .name = "default",
- + .type = AVMEDIA_TYPE_VIDEO,
- + .config_props = config_output,
- + .request_frame = request_frame,
- + },
- + { NULL }
- +};
- +
- +AVFilter ff_vf_vmaf = {
- + .name = "vmaf",
- + .description = NULL_IF_CONFIG_SMALL("Calculate the VMAF between two video streams."),
- + .init = init,
- + .uninit = uninit,
- + .query_formats = query_formats,
- + .priv_size = sizeof(VMAFContext),
- + .priv_class = &vmaf_class,
- + .inputs = vmaf_inputs,
- + .outputs = vmaf_outputs,
- +};
- diff --git a/libavfilter/vmaf.h b/libavfilter/vmaf.h
- new file mode 100644
- index 0000000..ebfc38a
- --- /dev/null
- +++ b/libavfilter/vmaf.h
- @@ -0,0 +1,33 @@
- +/*
- + * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
- + *
- + * This file is part of FFmpeg.
- + *
- + * FFmpeg is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2.1 of the License, or (at your option) any later version.
- + *
- + * FFmpeg is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with FFmpeg; if not, write to the Free Software
- + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- + */
- +
- +#ifndef AVFILTER_VMAF_H
- +#define AVFILTER_VMAF_H
- +
- +#include <stddef.h>
- +#include <stdint.h>
- +
- +typedef struct VMAFDSPContext {
- + uint64_t (*sse_line)(const uint8_t *buf, const uint8_t *ref, int w);
- +} VMAFDSPContext;
- +
- +void ff_vmaf_init_x86(VMAFDSPContext *dsp, int bpp);
- +
- +#endif /* AVFILTER_VMAF_H */
- --
- 2.7.4
- From 5e508cbc321109cd17fdb00385f94b11d31e2e62 Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Tue, 30 May 2017 05:17:10 +0000
- Subject: [PATCH 02/18] made changes in makefile and allfilters.c
- ---
- libavfilter/Makefile | 1 +
- libavfilter/allfilters.c | 1 +
- 2 files changed, 2 insertions(+)
- diff --git a/libavfilter/Makefile b/libavfilter/Makefile
- index f7dfe8a..1c4bd56 100644
- --- a/libavfilter/Makefile
- +++ b/libavfilter/Makefile
- @@ -314,6 +314,7 @@ OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o
- OBJS-$(CONFIG_VIDSTABDETECT_FILTER) += vidstabutils.o vf_vidstabdetect.o
- OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER) += vidstabutils.o vf_vidstabtransform.o
- OBJS-$(CONFIG_VIGNETTE_FILTER) += vf_vignette.o
- +OBJS-$(CONFIG_VMAF_FILTER) += vf_vmaf.o dualinput.o framesync.o
- OBJS-$(CONFIG_VSTACK_FILTER) += vf_stack.o framesync.o
- OBJS-$(CONFIG_W3FDIF_FILTER) += vf_w3fdif.o
- OBJS-$(CONFIG_WAVEFORM_FILTER) += vf_waveform.o
- diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
- index cd35ae4..6894a6f 100644
- --- a/libavfilter/allfilters.c
- +++ b/libavfilter/allfilters.c
- @@ -325,6 +325,7 @@ static void register_all(void)
- REGISTER_FILTER(VIDSTABDETECT, vidstabdetect, vf);
- REGISTER_FILTER(VIDSTABTRANSFORM, vidstabtransform, vf);
- REGISTER_FILTER(VIGNETTE, vignette, vf);
- + REGISTER_FILTER(VMAF, vmaf, vf);
- REGISTER_FILTER(VSTACK, vstack, vf);
- REGISTER_FILTER(W3FDIF, w3fdif, vf);
- REGISTER_FILTER(WAVEFORM, waveform, vf);
- --
- 2.7.4
- From 18dc8e5d18eff4641b49a454bb1b761573658aad Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Tue, 30 May 2017 05:47:38 +0000
- Subject: [PATCH 03/18] removed unnecesarry content and modified query formats
- ---
- libavfilter/vf_vmaf.c | 134 +-------------------------------------------------
- 1 file changed, 2 insertions(+), 132 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 53bb8a4..a1ef6b7 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -111,22 +111,6 @@ void compute_images_mse(VMAFContext *s,
- int w, int h, double mse[4])
- {
- int i, c;
- -
- - for (c = 0; c < s->nb_components; c++) {
- - const int outw = s->planewidth[c];
- - const int outh = s->planeheight[c];
- - const uint8_t *main_line = main_data[c];
- - const uint8_t *ref_line = ref_data[c];
- - const int ref_linesize = ref_linesizes[c];
- - const int main_linesize = main_linesizes[c];
- - uint64_t m = 0;
- - for (i = 0; i < outh; i++) {
- - m += s->dsp.sse_line(main_line, ref_line, outw);
- - ref_line += ref_linesize;
- - main_line += main_linesize;
- - }
- - mse[c] = m / (double)(outw * outh);
- - }
- }
- static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
- @@ -154,66 +138,6 @@ static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main,
- (const uint8_t **)ref->data, ref->linesize,
- main->width, main->height, comp_mse);
- - for (j = 0; j < s->nb_components; j++)
- - mse += comp_mse[j] * s->planeweight[j];
- -
- - s->min_mse = FFMIN(s->min_mse, mse);
- - s->max_mse = FFMAX(s->max_mse, mse);
- -
- - s->mse += mse;
- - for (j = 0; j < s->nb_components; j++)
- - s->mse_comp[j] += comp_mse[j];
- - s->nb_frames++;
- -
- - for (j = 0; j < s->nb_components; j++) {
- - c = s->is_rgb ? s->rgba_map[j] : j;
- - set_meta(metadata, "lavfi.vmaf.mse.", s->comps[j], comp_mse[c]);
- - set_meta(metadata, "lavfi.vmaf.vmaf.", s->comps[j], get_vmaf(comp_mse[c], 1, s->max[c]));
- - }
- - set_meta(metadata, "lavfi.vmaf.mse_avg", 0, mse);
- - set_meta(metadata, "lavfi.vmaf.vmaf_avg", 0, get_vmaf(mse, 1, s->average_max));
- -
- - if (s->stats_file) {
- - if (s->stats_version == 2 && !s->stats_header_written) {
- - fprintf(s->stats_file, "vmaf_log_version:2 fields:n");
- - fprintf(s->stats_file, ",mse_avg");
- - for (j = 0; j < s->nb_components; j++) {
- - fprintf(s->stats_file, ",mse_%c", s->comps[j]);
- - }
- - fprintf(s->stats_file, ",vmaf_avg");
- - for (j = 0; j < s->nb_components; j++) {
- - fprintf(s->stats_file, ",vmaf_%c", s->comps[j]);
- - }
- - if (s->stats_add_max) {
- - fprintf(s->stats_file, ",max_avg");
- - for (j = 0; j < s->nb_components; j++) {
- - fprintf(s->stats_file, ",max_%c", s->comps[j]);
- - }
- - }
- - fprintf(s->stats_file, "\n");
- - s->stats_header_written = 1;
- - }
- - fprintf(s->stats_file, "n:%"PRId64" mse_avg:%0.2f ", s->nb_frames, mse);
- - for (j = 0; j < s->nb_components; j++) {
- - c = s->is_rgb ? s->rgba_map[j] : j;
- - fprintf(s->stats_file, "mse_%c:%0.2f ", s->comps[j], comp_mse[c]);
- - }
- - fprintf(s->stats_file, "vmaf_avg:%0.2f ", get_vmaf(mse, 1, s->average_max));
- - for (j = 0; j < s->nb_components; j++) {
- - c = s->is_rgb ? s->rgba_map[j] : j;
- - fprintf(s->stats_file, "vmaf_%c:%0.2f ", s->comps[j],
- - get_vmaf(comp_mse[c], 1, s->max[c]));
- - }
- - if (s->stats_version == 2 && s->stats_add_max) {
- - fprintf(s->stats_file, "max_avg:%d ", s->average_max);
- - for (j = 0; j < s->nb_components; j++) {
- - c = s->is_rgb ? s->rgba_map[j] : j;
- - fprintf(s->stats_file, "max_%c:%d ", s->comps[j], s->max[c]);
- - }
- - }
- - fprintf(s->stats_file, "\n");
- - }
- -
- return main;
- }
- @@ -252,17 +176,8 @@ static av_cold int init(AVFilterContext *ctx)
- static int query_formats(AVFilterContext *ctx)
- {
- static const enum AVPixelFormat pix_fmts[] = {
- - AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16,
- -#define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
- -#define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
- -#define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
- - PF(P), PF(P9), PF(P10), PF_NOALPHA(P12), PF_NOALPHA(P14), PF(P16),
- - AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
- - AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P,
- - AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
- - AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
- - AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
- - AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP16,
- + AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
- + AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV420P10LE,
- AV_PIX_FMT_NONE
- };
- @@ -292,34 +207,6 @@ static int config_input_ref(AVFilterLink *inlink)
- return AVERROR(EINVAL);
- }
- - s->max[0] = (1 << desc->comp[0].depth) - 1;
- - s->max[1] = (1 << desc->comp[1].depth) - 1;
- - s->max[2] = (1 << desc->comp[2].depth) - 1;
- - s->max[3] = (1 << desc->comp[3].depth) - 1;
- -
- - s->is_rgb = ff_fill_rgba_map(s->rgba_map, inlink->format) >= 0;
- - s->comps[0] = s->is_rgb ? 'r' : 'y' ;
- - s->comps[1] = s->is_rgb ? 'g' : 'u' ;
- - s->comps[2] = s->is_rgb ? 'b' : 'v' ;
- - s->comps[3] = 'a';
- -
- - s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
- - s->planeheight[0] = s->planeheight[3] = inlink->h;
- - s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
- - s->planewidth[0] = s->planewidth[3] = inlink->w;
- - sum = 0;
- - for (j = 0; j < s->nb_components; j++)
- - sum += s->planeheight[j] * s->planewidth[j];
- - average_max = 0;
- - for (j = 0; j < s->nb_components; j++) {
- - s->planeweight[j] = (double) s->planeheight[j] * s->planewidth[j] / sum;
- - average_max += s->max[j] * s->planeweight[j];
- - }
- - s->average_max = lrint(average_max);
- -
- - s->dsp.sse_line = desc->comp[0].depth > 8 ? sse_line_16bit : sse_line_8bit;
- - if (ARCH_X86)
- - ff_vmaf_init_x86(&s->dsp, desc->comp[0].depth);
- return 0;
- }
- @@ -358,23 +245,6 @@ static av_cold void uninit(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- - if (s->nb_frames > 0) {
- - int j;
- - char buf[256];
- -
- - buf[0] = 0;
- - for (j = 0; j < s->nb_components; j++) {
- - int c = s->is_rgb ? s->rgba_map[j] : j;
- - av_strlcatf(buf, sizeof(buf), " %c:%f", s->comps[j],
- - get_vmaf(s->mse_comp[c], s->nb_frames, s->max[c]));
- - }
- - av_log(ctx, AV_LOG_INFO, "VMAF%s average:%f min:%f max:%f\n",
- - buf,
- - get_vmaf(s->mse, s->nb_frames, s->average_max),
- - get_vmaf(s->max_mse, 1, s->average_max),
- - get_vmaf(s->min_mse, 1, s->average_max));
- - }
- -
- ff_dualinput_uninit(&s->dinput);
- if (s->stats_file && s->stats_file != stdout)
- --
- 2.7.4
- From 7482bfaa0fecd167c464c621da44c168ee093acb Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Fri, 2 Jun 2017 13:02:13 +0000
- Subject: [PATCH 04/18] Indent properly and minor changes
- ---
- libavfilter/vf_vmaf.c | 145 ++++++++++++++++++++++++++++++++------------------
- libavfilter/vmaf.h | 5 +-
- 2 files changed, 96 insertions(+), 54 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index a1ef6b7..be8a508 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -1,7 +1,6 @@
- /*
- - * Copyright (c) 2011 Roger Pau Monné <roger.pau@entel.upc.edu>
- - * Copyright (c) 2011 Stefano Sabatini
- - * Copyright (c) 2013 Paul B Mahol
- + * Copyright (c) 2017 Ronald S. Bultje <rsbultje@gmail.com>
- + * Copyright (c) 2017 Ashish Pratap Singh <ashk43712@gmail.com>
- *
- * This file is part of FFmpeg.
- *
- @@ -70,73 +69,113 @@ static const AVOption vmaf_options[] = {
- AVFILTER_DEFINE_CLASS(vmaf);
- -static inline unsigned pow_2(unsigned base)
- + static inline
- +double compute_vmaf(VMAFContext *s,
- + const uint8_t *main_data[4], const int main_linesizes[4],
- + const uint8_t *ref_data[4], const int ref_linesizes[4],
- + int w, int h, double mse[4])
- {
- - return base*base;
- + int i, c;
- + return 0;
- }
- -static inline double get_vmaf(double mse, uint64_t nb_frames, int max)
- +static void set_meta(AVDictionary **metadata, const char *key, float d)
- {
- - return 10.0 * log10(pow_2(max) / (mse / nb_frames));
- + char value[128];
- + snprintf(value, sizeof(value), "%0.7f", d);
- + av_dict_set(metadata,key,value,0);
- }
- -static uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
- +static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- {
- - int j;
- - unsigned m2 = 0;
- - for (j = 0; j < outw; j++)
- - m2 += pow_2(main_line[j] - ref_line[j]);
- + VMAFContext *s = ctx->priv;
- - return m2;
- -}
- + AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- -static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t *_ref_line, int outw)
- -{
- - int j;
- - uint64_t m2 = 0;
- - const uint16_t *main_line = (const uint16_t *) _main_line;
- - const uint16_t *ref_line = (const uint16_t *) _ref_line;
- + int pipefd[2];
- + char buf[1001];
- + char str[20];
- + int w = main->width;
- + int h = main->height;
- - for (j = 0; j < outw; j++)
- - m2 += pow_2(main_line[j] - ref_line[j]);
- + char *format = av_get_pix_fmt_name(main->format);
- - return m2;
- -}
- + char *fifo1 = "t1.yuv";
- + char *fifo2 = "t2.yuv";
- -static inline
- -void compute_images_mse(VMAFContext *s,
- - const uint8_t *main_data[4], const int main_linesizes[4],
- - const uint8_t *ref_data[4], const int ref_linesizes[4],
- - int w, int h, double mse[4])
- -{
- - int i, c;
- -}
- + char width[5],height[5];
- + sprintf(width, "%d", main->width);
- + sprintf(height, "%d", main->height);
- -static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
- -{
- - char value[128];
- - snprintf(value, sizeof(value), "%0.2f", d);
- - if (comp) {
- - char key2[128];
- - snprintf(key2, sizeof(key2), "%s%c", key, comp);
- - av_dict_set(metadata, key2, value, 0);
- +
- + if(pipe(pipefd)==-1){
- + av_log(ctx, AV_LOG_ERROR, "Pipe creation failed.\n");
- + AVERROR(EINVAL);
- + }
- +
- + int pid = fork();
- +
- + if(pid == -1){
- + av_log(ctx, AV_LOG_ERROR, "Process creation failed.\n");
- + AVERROR(EINVAL);
- + }
- + else if ( pid == 0 ) {
- + close(pipefd[0]);
- + dup2(pipefd[1], 1);
- +
- + int ret = execlp(s->vmaf_dir,"python",format,width,height,fifo1,fifo2,"--out-fmt","text",(char*)NULL);
- + av_log(ctx, AV_LOG_ERROR, "No such file or directory.\n");
- + exit(0);
- } else {
- - av_dict_set(metadata, key, value, 0);
- +
- + FILE *fd1,*fd2;
- +
- + fd1 = fopen(fifo1, "wb");
- + uint8_t *ptr=main->data[0];
- + int y;
- + for (y=0; y<h; y) {
- + fwrite(ptr,w,1,fd1);
- + ptr = main->linesize[0];
- + }
- + fclose(fd1);
- +
- + fd2 = fopen(fifo2, "wb");
- + ptr=ref->data[0];
- + for (y=0; y<h; y) {
- + fwrite(ptr,w,1,fd2);
- + ptr = ref->linesize[0];
- + }
- + fclose(fd2);
- +
- + wait(NULL);
- + close(pipefd[1]);
- + read(pipefd[0], &buf, sizeof(buf));
- +
- + close(pipefd[0]);
- +
- + int len= strlen(buf);
- + char *ned = "VMAF_score";
- + char *find = strstr(buf,ned);
- + int i=0;
- + find = 11;
- + while(*find!=' '&&*find!='\n'){
- + str[i]=*find;
- + find;
- + }
- + str[i]='\0';
- +
- }
- -}
- + double d;
- -static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main,
- - const AVFrame *ref)
- -{
- - VMAFContext *s = ctx->priv;
- - double comp_mse[4], mse = 0;
- - int j, c;
- - AVDictionary **metadata = &main->metadata;
- + sscanf(str, "%lf", &d);
- +
- + set_meta(metadata, "lavfi.vmaf.score.",d);
- + av_log(ctx, AV_LOG_INFO, "vmaf score for frame %d is %lf.\n",s->nb_frames,d);
- +
- + s->vmaf_sum = d;
- - compute_images_mse(s, (const uint8_t **)main->data, main->linesize,
- - (const uint8_t **)ref->data, ref->linesize,
- - main->width, main->height, comp_mse);
- + s->nb_frames;
- return main;
- }
- @@ -151,7 +190,7 @@ static av_cold int init(AVFilterContext *ctx)
- if (s->stats_file_str) {
- if (s->stats_version < 2 && s->stats_add_max) {
- av_log(ctx, AV_LOG_ERROR,
- - "stats_add_max was specified but stats_version < 2.\n" );
- + "stats_add_max was specified but stats_version < 2.\n" );
- return AVERROR(EINVAL);
- }
- if (!strcmp(s->stats_file_str, "-")) {
- diff --git a/libavfilter/vmaf.h b/libavfilter/vmaf.h
- index ebfc38a..4d1c722 100644
- --- a/libavfilter/vmaf.h
- +++ b/libavfilter/vmaf.h
- @@ -1,5 +1,6 @@
- /*
- - * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
- + * Copyright (c) 2017 Ronald S. Bultje <rsbultje@gmail.com>
- + * Copyright (c) 2017 Ashishh Pratap Singh <ashk43712@gmail.com>
- *
- * This file is part of FFmpeg.
- *
- @@ -30,4 +31,6 @@ typedef struct VMAFDSPContext {
- void ff_vmaf_init_x86(VMAFDSPContext *dsp, int bpp);
- +double calculate_vmaf();
- +
- #endif /* AVFILTER_VMAF_H */
- --
- 2.7.4
- From 897b9db211be0f96a4b08f1da2c1bd3418361af2 Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Sat, 3 Jun 2017 09:07:05 +0000
- Subject: [PATCH 05/18] Added vmaf compute method
- ---
- libavfilter/vf_vmaf.c | 128 +++++++++++++++-----------------------------------
- libavfilter/vmaf.h | 2 +-
- 2 files changed, 39 insertions(+), 91 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index be8a508..b011561 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -38,20 +38,19 @@
- typedef struct VMAFContext {
- const AVClass *class;
- FFDualInputContext dinput;
- - double mse, min_mse, max_mse, mse_comp[4];
- uint64_t nb_frames;
- FILE *stats_file;
- char *stats_file_str;
- int stats_version;
- int stats_header_written;
- int stats_add_max;
- - int max[4], average_max;
- int is_rgb;
- uint8_t rgba_map[4];
- char comps[4];
- int nb_components;
- int planewidth[4];
- int planeheight[4];
- + double vmaf_sum;
- double planeweight[4];
- VMAFDSPContext dsp;
- } VMAFContext;
- @@ -69,14 +68,9 @@ static const AVOption vmaf_options[] = {
- AVFILTER_DEFINE_CLASS(vmaf);
- - static inline
- -double compute_vmaf(VMAFContext *s,
- - const uint8_t *main_data[4], const int main_linesizes[4],
- - const uint8_t *ref_data[4], const int ref_linesizes[4],
- - int w, int h, double mse[4])
- +static inline double get_vmaf(double vmaf_sum, uint64_t nb_frames)
- {
- - int i, c;
- - return 0;
- + return vmaf_sum/nb_frames;
- }
- static void set_meta(AVDictionary **metadata, const char *key, float d)
- @@ -86,96 +80,53 @@ static void set_meta(AVDictionary **metadata, const char *key, float d)
- av_dict_set(metadata,key,value,0);
- }
- -static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- +double compute_vmaf_score(char *format, int width, int height, const uint8_t *main_data, const uint8_t *ref_data, int main_linesize, int ref_linesize)
- {
- -
- - VMAFContext *s = ctx->priv;
- -
- - AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- -
- - int pipefd[2];
- - char buf[1001];
- - char str[20];
- - int w = main->width;
- - int h = main->height;
- -
- - char *format = av_get_pix_fmt_name(main->format);
- + int i, c;
- char *fifo1 = "t1.yuv";
- char *fifo2 = "t2.yuv";
- - char width[5],height[5];
- - sprintf(width, "%d", main->width);
- - sprintf(height, "%d", main->height);
- + FILE *fd1,*fd2;
- + fd1 = fopen(fifo1, "wb");
- + uint8_t *ptr = main_data;
- + int y;
- + for (y=0; y<height; y++) {
- + fwrite(ptr,width,1,fd1);
- + ptr += main_linesize;
- + }
- + fclose(fd1);
- - if(pipe(pipefd)==-1){
- - av_log(ctx, AV_LOG_ERROR, "Pipe creation failed.\n");
- - AVERROR(EINVAL);
- + fd2 = fopen(fifo2, "wb");
- + ptr = ref_data;
- + for (y=0; y<height; y++) {
- + fwrite(ptr,width,1,fd2);
- + ptr += ref_linesize;
- }
- + fclose(fd2);
- - int pid = fork();
- + return 0;
- +}
- - if(pid == -1){
- - av_log(ctx, AV_LOG_ERROR, "Process creation failed.\n");
- - AVERROR(EINVAL);
- - }
- - else if ( pid == 0 ) {
- - close(pipefd[0]);
- - dup2(pipefd[1], 1);
- -
- - int ret = execlp(s->vmaf_dir,"python",format,width,height,fifo1,fifo2,"--out-fmt","text",(char*)NULL);
- - av_log(ctx, AV_LOG_ERROR, "No such file or directory.\n");
- - exit(0);
- - } else {
- -
- - FILE *fd1,*fd2;
- -
- - fd1 = fopen(fifo1, "wb");
- - uint8_t *ptr=main->data[0];
- - int y;
- - for (y=0; y<h; y) {
- - fwrite(ptr,w,1,fd1);
- - ptr = main->linesize[0];
- - }
- - fclose(fd1);
- +static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- +{
- - fd2 = fopen(fifo2, "wb");
- - ptr=ref->data[0];
- - for (y=0; y<h; y) {
- - fwrite(ptr,w,1,fd2);
- - ptr = ref->linesize[0];
- - }
- - fclose(fd2);
- -
- - wait(NULL);
- - close(pipefd[1]);
- - read(pipefd[0], &buf, sizeof(buf));
- -
- - close(pipefd[0]);
- -
- - int len= strlen(buf);
- - char *ned = "VMAF_score";
- - char *find = strstr(buf,ned);
- - int i=0;
- - find = 11;
- - while(*find!=' '&&*find!='\n'){
- - str[i]=*find;
- - find;
- - }
- - str[i]='\0';
- + VMAFContext *s = ctx->priv;
- - }
- - double d;
- + AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- +
- + char *format = av_get_pix_fmt_name(main->format);
- +
- + double score = compute_vmaf_score(format,main->width,main->height,main->data[0],ref->data[0],main->linesize[0],ref->linesize[0]);
- - sscanf(str, "%lf", &d);
- - set_meta(metadata, "lavfi.vmaf.score.",d);
- - av_log(ctx, AV_LOG_INFO, "vmaf score for frame %d is %lf.\n",s->nb_frames,d);
- + set_meta(metadata, "lavfi.vmaf.score.",score);
- + av_log(ctx, AV_LOG_INFO, "vmaf score for frame %lu is %lf.\n",s->nb_frames,score);
- - s->vmaf_sum = d;
- + s->vmaf_sum += score;
- - s->nb_frames;
- + s->nb_frames++;
- return main;
- }
- @@ -184,9 +135,6 @@ static av_cold int init(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- - s->min_mse = +INFINITY;
- - s->max_mse = -INFINITY;
- -
- if (s->stats_file_str) {
- if (s->stats_version < 2 && s->stats_add_max) {
- av_log(ctx, AV_LOG_ERROR,
- @@ -231,9 +179,6 @@ static int config_input_ref(AVFilterLink *inlink)
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
- AVFilterContext *ctx = inlink->dst;
- VMAFContext *s = ctx->priv;
- - double average_max;
- - unsigned sum;
- - int j;
- s->nb_components = desc->nb_components;
- if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
- @@ -283,7 +228,10 @@ static int request_frame(AVFilterLink *outlink)
- static av_cold void uninit(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- -
- + if (s->nb_frames > 0) {
- + av_log(ctx, AV_LOG_INFO, "VMAF average:%f\n",
- + get_vmaf(s->vmaf_sum, s->nb_frames));
- + }
- ff_dualinput_uninit(&s->dinput);
- if (s->stats_file && s->stats_file != stdout)
- diff --git a/libavfilter/vmaf.h b/libavfilter/vmaf.h
- index 4d1c722..61e381d 100644
- --- a/libavfilter/vmaf.h
- +++ b/libavfilter/vmaf.h
- @@ -31,6 +31,6 @@ typedef struct VMAFDSPContext {
- void ff_vmaf_init_x86(VMAFDSPContext *dsp, int bpp);
- -double calculate_vmaf();
- +double compute_vmaf_score(char *format, int width, int height, const uint8_t *main_data, const uint8_t *ref_data, int main_linesize, int ref_linesize);
- #endif /* AVFILTER_VMAF_H */
- --
- 2.7.4
- From cfdaaf032ee288ba61bebaf0268a2fb2201a5b88 Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Sun, 4 Jun 2017 08:54:14 +0000
- Subject: [PATCH 06/18] Some minor changes
- ---
- libavfilter/vf_vmaf.c | 60 ++++++++++++++++++++++++++++++++++++++++-----------
- libavfilter/vmaf.h | 11 ++++------
- 2 files changed, 51 insertions(+), 20 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index b011561..9fab982 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -24,6 +24,10 @@
- * Caculate the VMAF between two input videos.
- */
- +#include <unistd.h>
- +#include <stdio.h>
- +#include <errno.h>
- +#include <string.h>
- #include "libavutil/avstring.h"
- #include "libavutil/opt.h"
- #include "libavutil/pixdesc.h"
- @@ -32,13 +36,15 @@
- #include "drawutils.h"
- #include "formats.h"
- #include "internal.h"
- -#include "vmaf.h"
- +#include "libvmaf.h"
- #include "video.h"
- +#include "vmaf.h"
- typedef struct VMAFContext {
- const AVClass *class;
- FFDualInputContext dinput;
- uint64_t nb_frames;
- + char cwd[200],main_path[200],ref_path[200];
- FILE *stats_file;
- char *stats_file_str;
- int stats_version;
- @@ -80,33 +86,38 @@ static void set_meta(AVDictionary **metadata, const char *key, float d)
- av_dict_set(metadata,key,value,0);
- }
- -double compute_vmaf_score(char *format, int width, int height, const uint8_t *main_data, const uint8_t *ref_data, int main_linesize, int ref_linesize)
- +static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *ref)
- {
- int i, c;
- + char *format = av_get_pix_fmt_name(main->format);
- + int w = main->width, h = main->height;
- +
- char *fifo1 = "t1.yuv";
- char *fifo2 = "t2.yuv";
- FILE *fd1,*fd2;
- fd1 = fopen(fifo1, "wb");
- - uint8_t *ptr = main_data;
- + uint8_t *ptr = main->data[0];
- int y;
- - for (y=0; y<height; y++) {
- - fwrite(ptr,width,1,fd1);
- - ptr += main_linesize;
- + for (y=0; y<h; y++) {
- + fwrite(ptr,w,1,fd1);
- + ptr += main->linesize[0];
- }
- fclose(fd1);
- fd2 = fopen(fifo2, "wb");
- - ptr = ref_data;
- - for (y=0; y<height; y++) {
- - fwrite(ptr,width,1,fd2);
- - ptr += ref_linesize;
- + ptr = ref->data[0];
- + for (y=0; y<h; y++) {
- + fwrite(ptr,w,1,fd2);
- + ptr += ref->linesize[0];
- }
- fclose(fd2);
- - return 0;
- + //double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path);
- + return 0.0;
- +
- }
- static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- @@ -116,9 +127,8 @@ static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- - char *format = av_get_pix_fmt_name(main->format);
- - double score = compute_vmaf_score(format,main->width,main->height,main->data[0],ref->data[0],main->linesize[0],ref->linesize[0]);
- + double score = compute_vmaf_score(s,main,ref);
- set_meta(metadata, "lavfi.vmaf.score.",score);
- @@ -192,6 +202,30 @@ static int config_input_ref(AVFilterLink *inlink)
- }
- + getcwd(s->main_path, sizeof(s->main_path));
- + // printf("%s\n",s->cwd);
- + getcwd(s->ref_path, sizeof(s->ref_path));
- + int len = strlen(s->main_path);
- + s->main_path[len++] = 't';
- + s->main_path[len++] = '1';
- + s->main_path[len++] = '.';
- + s->main_path[len++] = 'y';
- + s->main_path[len++] = 'u';
- + s->main_path[len++] = 'v';
- + s->main_path[len] = '\0';
- +
- + len = strlen(s->ref_path);
- +
- + s->ref_path[len++] = 't';
- + s->ref_path[len++] = '2';
- + s->ref_path[len++] = '.';
- + s->ref_path[len++] = 'y';
- + s->ref_path[len++] = 'u';
- + s->ref_path[len++] = 'v';
- + s->ref_path[len] = '\0';
- +
- + av_log(ctx, AV_LOG_INFO, "directory is %s.\n",s->cwd);
- +
- return 0;
- }
- diff --git a/libavfilter/vmaf.h b/libavfilter/vmaf.h
- index 61e381d..2e7cd8a 100644
- --- a/libavfilter/vmaf.h
- +++ b/libavfilter/vmaf.h
- @@ -1,6 +1,5 @@
- /*
- - * Copyright (c) 2017 Ronald S. Bultje <rsbultje@gmail.com>
- - * Copyright (c) 2017 Ashishh Pratap Singh <ashk43712@gmail.com>
- + * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
- *
- * This file is part of FFmpeg.
- *
- @@ -19,8 +18,8 @@
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- -#ifndef AVFILTER_VMAF_H
- -#define AVFILTER_VMAF_H
- +#ifndef AVFILTER_PSNR_H
- +#define AVFILTER_PSNR_H
- #include <stddef.h>
- #include <stdint.h>
- @@ -29,8 +28,6 @@ typedef struct VMAFDSPContext {
- uint64_t (*sse_line)(const uint8_t *buf, const uint8_t *ref, int w);
- } VMAFDSPContext;
- -void ff_vmaf_init_x86(VMAFDSPContext *dsp, int bpp);
- -
- -double compute_vmaf_score(char *format, int width, int height, const uint8_t *main_data, const uint8_t *ref_data, int main_linesize, int ref_linesize);
- +void ff_psnr_init_x86(VMAFDSPContext *dsp, int bpp);
- #endif /* AVFILTER_VMAF_H */
- --
- 2.7.4
- From baf61f238d02dd3d85ab1e77b74a858c560c9396 Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Sun, 4 Jun 2017 17:17:37 +0530
- Subject: [PATCH 07/18] Made changes to configure
- ---
- configure | 4 ++++
- 1 file changed, 4 insertions(+)
- diff --git a/configure b/configure
- index 5ae5227..4ea4db8 100755
- --- a/configure
- +++ b/configure
- @@ -259,6 +259,7 @@ External library support:
- --enable-libtwolame enable MP2 encoding via libtwolame [no]
- --enable-libv4l2 enable libv4l2/v4l-utils [no]
- --enable-libvidstab enable video stabilization using vid.stab [no]
- + --enable-libvmaf enable vmaf filter via libvmaf [no]
- --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no]
- --enable-libvorbis enable Vorbis en/decoding via libvorbis,
- native implementation exists [no]
- @@ -1569,6 +1570,7 @@ EXTERNAL_LIBRARY_LIST="
- libtheora
- libtwolame
- libv4l2
- + libvmaf
- libvorbis
- libvpx
- libwavpack
- @@ -2878,6 +2880,7 @@ libspeex_encoder_deps="libspeex"
- libspeex_encoder_select="audio_frame_queue"
- libtheora_encoder_deps="libtheora"
- libtwolame_encoder_deps="libtwolame"
- +libvmaf_filter_deps="libvmaf"
- libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
- libvorbis_decoder_deps="libvorbis"
- libvorbis_encoder_deps="libvorbis"
- @@ -5845,6 +5848,7 @@ enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame
- die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
- enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
- enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
- +enabled libvmaf && require libvmaf libvmaf.h
- enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
- enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
- --
- 2.7.4
- From 8effb6d454c2ed45e3e625a461bcbcc70b843e9b Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Sun, 4 Jun 2017 19:35:27 +0530
- Subject: [PATCH 08/18] libvmaf detected successfully
- ---
- configure | 3 ++-
- 1 file changed, 2 insertions(+), 1 deletion(-)
- diff --git a/configure b/configure
- index 4ea4db8..5c995c7 100755
- --- a/configure
- +++ b/configure
- @@ -5848,7 +5848,8 @@ enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame
- die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
- enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
- enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
- -enabled libvmaf && require libvmaf libvmaf.h
- +enabled libvmaf { check_lib libvmaf libvmaf.h ||
- + die "ERROR: libvmaf must be installed"; }
- enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
- enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
- --
- 2.7.4
- From c536ec913efe0e1ff731fcb8455c9b307255d7d0 Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Sun, 4 Jun 2017 15:19:52 +0000
- Subject: [PATCH 09/18] Uncommented the compute_vmaf function
- ---
- configure | 2 +-
- libavfilter/vf_vmaf.c | 4 ++--
- 2 files changed, 3 insertions(+), 3 deletions(-)
- diff --git a/configure b/configure
- index 5c995c7..23f7321 100755
- --- a/configure
- +++ b/configure
- @@ -5848,7 +5848,7 @@ enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame
- die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
- enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
- enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
- -enabled libvmaf { check_lib libvmaf libvmaf.h ||
- +enabled libvmaf { check_lib libvmaf "libvmaf.h" "compute_vmaf" ||
- die "ERROR: libvmaf must be installed"; }
- enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
- enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 9fab982..f45d052 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -115,8 +115,8 @@ static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *r
- }
- fclose(fd2);
- - //double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path);
- - return 0.0;
- + double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path);
- + return vmaf_score;
- }
- --
- 2.7.4
- From 26ea8fffef7a485dba4ae5f4ce6705b541ecd7b8 Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Mon, 5 Jun 2017 02:13:03 +0530
- Subject: [PATCH 10/18] modified configure and vmaf.c
- ---
- configure | 5 +++--
- libavfilter/vf_vmaf.c | 5 ++---
- 2 files changed, 5 insertions(+), 5 deletions(-)
- diff --git a/configure b/configure
- index 23f7321..de04274 100755
- --- a/configure
- +++ b/configure
- @@ -5848,8 +5848,9 @@ enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame
- die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
- enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
- enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
- -enabled libvmaf { check_lib libvmaf "libvmaf.h" "compute_vmaf" ||
- - die "ERROR: libvmaf must be installed"; }
- +enabled libvmaf && { use_pkg_config libvmaf "libvmaf.h" compute_vmaf ||
- + { check_lib libvmaf "libvmaf.h" "compute_vmaf" -lvmaf &&
- + warn "using libvmaf without pkg-config"; } }
- enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
- enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index f45d052..a2dda5d 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -23,7 +23,7 @@
- * @file
- * Caculate the VMAF between two input videos.
- */
- -
- +#include "libvmaf.h"
- #include <unistd.h>
- #include <stdio.h>
- #include <errno.h>
- @@ -36,7 +36,6 @@
- #include "drawutils.h"
- #include "formats.h"
- #include "internal.h"
- -#include "libvmaf.h"
- #include "video.h"
- #include "vmaf.h"
- @@ -114,7 +113,7 @@ static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *r
- ptr += ref->linesize[0];
- }
- fclose(fd2);
- -
- +
- double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path);
- return vmaf_score;
- --
- 2.7.4
- From 284c6e70bdc194b75a91b347f1336a280cf10073 Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Tue, 6 Jun 2017 02:53:15 +0530
- Subject: [PATCH 11/18] library integration and detection working
- ---
- configure | 2 +-
- libavfilter/vf_vmaf.c | 4 +++-
- 2 files changed, 4 insertions(+), 2 deletions(-)
- diff --git a/configure b/configure
- index de04274..8487f06 100755
- --- a/configure
- +++ b/configure
- @@ -5849,7 +5849,7 @@ enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame
- enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
- enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
- enabled libvmaf && { use_pkg_config libvmaf "libvmaf.h" compute_vmaf ||
- - { check_lib libvmaf "libvmaf.h" "compute_vmaf" -lvmaf &&
- + { check_lib libvmaf "libvmaf.h" "compute_vmaf" -lvmaf -lstdc++ -lpthread -lm &&
- warn "using libvmaf without pkg-config"; } }
- enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
- enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index a2dda5d..fc1a1c0 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -113,8 +113,10 @@ static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *r
- ptr += ref->linesize[0];
- }
- fclose(fd2);
- +
- + char *model_path = "model/vmaf_v0.6.1.pkl";
- - double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path);
- + double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path,model_path);
- return vmaf_score;
- }
- --
- 2.7.4
- From 31a413aa365d80dd0839bfd3b0a71a82058ee56c Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Tue, 6 Jun 2017 18:45:36 +0000
- Subject: [PATCH 12/18] Added correct path for models
- ---
- libavfilter/vf_vmaf.c | 8 ++++++--
- 1 file changed, 6 insertions(+), 2 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index fc1a1c0..84ce64d 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -114,8 +114,8 @@ static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *r
- }
- fclose(fd2);
- - char *model_path = "model/vmaf_v0.6.1.pkl";
- -
- + char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- +
- double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path,model_path);
- return vmaf_score;
- @@ -207,6 +207,7 @@ static int config_input_ref(AVFilterLink *inlink)
- // printf("%s\n",s->cwd);
- getcwd(s->ref_path, sizeof(s->ref_path));
- int len = strlen(s->main_path);
- + s->main_path[len++] = '/';
- s->main_path[len++] = 't';
- s->main_path[len++] = '1';
- s->main_path[len++] = '.';
- @@ -217,6 +218,7 @@ static int config_input_ref(AVFilterLink *inlink)
- len = strlen(s->ref_path);
- + s->ref_path[len++] = '/';
- s->ref_path[len++] = 't';
- s->ref_path[len++] = '2';
- s->ref_path[len++] = '.';
- @@ -267,6 +269,8 @@ static av_cold void uninit(AVFilterContext *ctx)
- av_log(ctx, AV_LOG_INFO, "VMAF average:%f\n",
- get_vmaf(s->vmaf_sum, s->nb_frames));
- }
- + remove("t1.yuv");
- + remove("t2.yuv");
- ff_dualinput_uninit(&s->dinput);
- if (s->stats_file && s->stats_file != stdout)
- --
- 2.7.4
- From c6c853833e0bfe182bda1c156aedb1f859045035 Mon Sep 17 00:00:00 2001
- From: Ubuntu <ubuntu@ip-172-31-11-196.us-west-2.compute.internal>
- Date: Wed, 7 Jun 2017 16:36:38 +0000
- Subject: [PATCH 13/18] remove file lines
- ---
- libavfilter/vf_vmaf.c | 54 +--------------------------------------------------
- 1 file changed, 1 insertion(+), 53 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 84ce64d..4b986c7 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -43,7 +43,6 @@ typedef struct VMAFContext {
- const AVClass *class;
- FFDualInputContext dinput;
- uint64_t nb_frames;
- - char cwd[200],main_path[200],ref_path[200];
- FILE *stats_file;
- char *stats_file_str;
- int stats_version;
- @@ -92,31 +91,9 @@ static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *r
- char *format = av_get_pix_fmt_name(main->format);
- int w = main->width, h = main->height;
- - char *fifo1 = "t1.yuv";
- - char *fifo2 = "t2.yuv";
- -
- - FILE *fd1,*fd2;
- -
- - fd1 = fopen(fifo1, "wb");
- - uint8_t *ptr = main->data[0];
- - int y;
- - for (y=0; y<h; y++) {
- - fwrite(ptr,w,1,fd1);
- - ptr += main->linesize[0];
- - }
- - fclose(fd1);
- -
- - fd2 = fopen(fifo2, "wb");
- - ptr = ref->data[0];
- - for (y=0; y<h; y++) {
- - fwrite(ptr,w,1,fd2);
- - ptr += ref->linesize[0];
- - }
- - fclose(fd2);
- -
- char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- - double vmaf_score = compute_vmaf(format,w,h,s->ref_path,s->main_path,model_path);
- + double vmaf_score = compute_vmaf(format,w,h,ref->data[0],main->data[0],model_path);
- return vmaf_score;
- }
- @@ -202,33 +179,6 @@ static int config_input_ref(AVFilterLink *inlink)
- return AVERROR(EINVAL);
- }
- -
- - getcwd(s->main_path, sizeof(s->main_path));
- - // printf("%s\n",s->cwd);
- - getcwd(s->ref_path, sizeof(s->ref_path));
- - int len = strlen(s->main_path);
- - s->main_path[len++] = '/';
- - s->main_path[len++] = 't';
- - s->main_path[len++] = '1';
- - s->main_path[len++] = '.';
- - s->main_path[len++] = 'y';
- - s->main_path[len++] = 'u';
- - s->main_path[len++] = 'v';
- - s->main_path[len] = '\0';
- -
- - len = strlen(s->ref_path);
- -
- - s->ref_path[len++] = '/';
- - s->ref_path[len++] = 't';
- - s->ref_path[len++] = '2';
- - s->ref_path[len++] = '.';
- - s->ref_path[len++] = 'y';
- - s->ref_path[len++] = 'u';
- - s->ref_path[len++] = 'v';
- - s->ref_path[len] = '\0';
- -
- - av_log(ctx, AV_LOG_INFO, "directory is %s.\n",s->cwd);
- -
- return 0;
- }
- @@ -269,8 +219,6 @@ static av_cold void uninit(AVFilterContext *ctx)
- av_log(ctx, AV_LOG_INFO, "VMAF average:%f\n",
- get_vmaf(s->vmaf_sum, s->nb_frames));
- }
- - remove("t1.yuv");
- - remove("t2.yuv");
- ff_dualinput_uninit(&s->dinput);
- if (s->stats_file && s->stats_file != stdout)
- --
- 2.7.4
- From 63232da6c6871489592d517f6a3b4ebeffe31d8c Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Sat, 10 Jun 2017 20:27:51 +0530
- Subject: [PATCH 14/18] Added linked list of frames
- ---
- libavfilter/vf_vmaf.c | 84 +++++++++++++++++++++++++++++++++++++++++++++------
- 1 file changed, 74 insertions(+), 10 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 4b986c7..26a310f 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -59,6 +59,18 @@ typedef struct VMAFContext {
- VMAFDSPContext dsp;
- } VMAFContext;
- +struct VMAFFrame{
- + uint8_t *ref_data, *main_data;
- + int ref_stride, main_stride;
- + struct VMAFFrame* next_frame;
- +} VFrame;
- +
- +struct VMAFFrame* head = NULL;
- +struct VMAFFrame* curr = NULL;
- +
- +char *format;
- +int width, height;
- +
- #define OFFSET(x) offsetof(VMAFContext, x)
- #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
- @@ -84,16 +96,36 @@ static void set_meta(AVDictionary **metadata, const char *key, float d)
- av_dict_set(metadata,key,value,0);
- }
- -static double compute_vmaf_score(VMAFContext *s, AVFrame *main, const AVFrame *ref)
- -{
- - int i, c;
- +static int read_frame(uint8_t *ref_buf, int *ref_stride, uint8_t *main_buf, int *main_stride){
- + if(curr == NULL){
- + printf("All frame read\n");
- + return -1;
- + }
- + printf("read frame started\n");
- + ref_buf = curr->ref_data;
- + ref_buf = curr->main_data;
- + *ref_stride = curr->ref_stride;
- + *main_stride = curr->main_stride;
- + printf("%d\n",*ref_stride);
- +
- +
- + curr == curr->next_frame;
- + printf("read frame finished luckily\n");
- + return 0;
- +}
- +
- - char *format = av_get_pix_fmt_name(main->format);
- - int w = main->width, h = main->height;
- +static double compute_vmaf_score()
- +{
- + printf("inside compute vmaf1\n");
- +
- + printf("width=%d,height=%d,format=%s\n",width,height,format);
- char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- - double vmaf_score = compute_vmaf(format,w,h,ref->data[0],main->data[0],model_path);
- + double vmaf_score;
- + vmaf_score = compute_vmaf(format,width,height,read_frame,model_path);
- + printf("compute vmaf competed\n");
- return vmaf_score;
- }
- @@ -106,11 +138,32 @@ static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- - double score = compute_vmaf_score(s,main,ref);
- + //double score = compute_vmaf_score(s,main,ref);
- -
- - set_meta(metadata, "lavfi.vmaf.score.",score);
- + double score = 0;
- + //set_meta(metadata, "lavfi.vmaf.score.",score);
- av_log(ctx, AV_LOG_INFO, "vmaf score for frame %lu is %lf.\n",s->nb_frames,score);
- + static int p = 0;
- +
- + if(p == 0){
- + head = (struct VMAFFrame*)malloc(sizeof(struct VMAFFrame));
- + head->ref_data = ref->data[0];
- + head->main_data = main->data[0];
- + head->ref_stride = ref->linesize[0];
- + head->main_data = main->linesize[0];
- + curr = head;
- + }
- + else{
- + struct VMAFFrame* new_node = (struct VMAFFrame*)malloc(sizeof(struct VMAFFrame));
- + new_node->ref_data = ref->data[0];
- + new_node->main_data = main->data[0];
- + new_node->ref_stride = ref->linesize[0];
- + new_node->main_data = main->linesize[0];
- + curr->next_frame = new_node;
- + curr = new_node;
- + }
- + p++;
- +
- s->vmaf_sum += score;
- @@ -167,7 +220,6 @@ static int config_input_ref(AVFilterLink *inlink)
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
- AVFilterContext *ctx = inlink->dst;
- VMAFContext *s = ctx->priv;
- -
- s->nb_components = desc->nb_components;
- if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
- ctx->inputs[0]->h != ctx->inputs[1]->h) {
- @@ -179,6 +231,10 @@ static int config_input_ref(AVFilterLink *inlink)
- return AVERROR(EINVAL);
- }
- + format = av_get_pix_fmt_name(ctx->inputs[0]->format);
- + width = ctx->inputs[0]->w;
- + height = ctx->inputs[0]->h;
- +
- return 0;
- }
- @@ -212,9 +268,11 @@ static int request_frame(AVFilterLink *outlink)
- return ff_dualinput_request_frame(&s->dinput, outlink);
- }
- +
- static av_cold void uninit(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- +
- if (s->nb_frames > 0) {
- av_log(ctx, AV_LOG_INFO, "VMAF average:%f\n",
- get_vmaf(s->vmaf_sum, s->nb_frames));
- @@ -223,6 +281,12 @@ static av_cold void uninit(AVFilterContext *ctx)
- if (s->stats_file && s->stats_file != stdout)
- fclose(s->stats_file);
- +
- + double vmaf_score = compute_vmaf_score();
- + printf("compute vmaf competed\n");
- + printf("%d\n",vmaf_score);
- +
- + return 0;
- }
- static const AVFilterPad vmaf_inputs[] = {
- --
- 2.7.4
- From 67cbf5e52d0c31552500c03daac03a6b5950aa24 Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Wed, 14 Jun 2017 22:37:03 +0530
- Subject: [PATCH 15/18] Added multi-threading, mutex and cond to filter
- ---
- libavfilter/vf_vmaf.c | 166 +++++++++++++++++++++++++++++---------------------
- 1 file changed, 96 insertions(+), 70 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 26a310f..50390b5 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -23,11 +23,13 @@
- * @file
- * Caculate the VMAF between two input videos.
- */
- -#include "libvmaf.h"
- +
- #include <unistd.h>
- #include <stdio.h>
- #include <errno.h>
- #include <string.h>
- +#include <inttypes.h>
- +#include <pthread.h>
- #include "libavutil/avstring.h"
- #include "libavutil/opt.h"
- #include "libavutil/pixdesc.h"
- @@ -38,6 +40,7 @@
- #include "internal.h"
- #include "video.h"
- #include "vmaf.h"
- +#include "libvmaf.h"
- typedef struct VMAFContext {
- const AVClass *class;
- @@ -49,6 +52,10 @@ typedef struct VMAFContext {
- int stats_header_written;
- int stats_add_max;
- int is_rgb;
- + pthread_t thread;
- + pthread_t main_thread_id;
- + pthread_t vmaf_thread_id;
- + pthread_attr_t attr;
- uint8_t rgba_map[4];
- char comps[4];
- int nb_components;
- @@ -59,17 +66,15 @@ typedef struct VMAFContext {
- VMAFDSPContext dsp;
- } VMAFContext;
- -struct VMAFFrame{
- - uint8_t *ref_data, *main_data;
- - int ref_stride, main_stride;
- - struct VMAFFrame* next_frame;
- -} VFrame;
- -
- -struct VMAFFrame* head = NULL;
- -struct VMAFFrame* curr = NULL;
- -char *format;
- -int width, height;
- +static char *format;
- +static int width, height;
- +pthread_mutex_t lock;
- +pthread_cond_t cond;
- +int get_next = 0;
- +int data_yes = 0;
- +AVFrame *gmain;
- +AVFrame *gref;
- #define OFFSET(x) offsetof(VMAFContext, x)
- #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
- @@ -96,86 +101,94 @@ static void set_meta(AVDictionary **metadata, const char *key, float d)
- av_dict_set(metadata,key,value,0);
- }
- -static int read_frame(uint8_t *ref_buf, int *ref_stride, uint8_t *main_buf, int *main_stride){
- - if(curr == NULL){
- - printf("All frame read\n");
- - return -1;
- +static void read_frame(uint8_t *ref_buf, int *ref_stride, uint8_t *main_buf, int *main_stride){
- + pthread_mutex_lock(&lock);
- + while(gref == NULL){
- + pthread_cond_wait(&cond, &lock);
- }
- - printf("read frame started\n");
- - ref_buf = curr->ref_data;
- - ref_buf = curr->main_data;
- - *ref_stride = curr->ref_stride;
- - *main_stride = curr->main_stride;
- - printf("%d\n",*ref_stride);
- -
- -
- - curr == curr->next_frame;
- - printf("read frame finished luckily\n");
- - return 0;
- -}
- +
- + *ref_stride = gref->linesize[0];
- + *main_stride = gmain->linesize[0];
- + ref_buf = malloc(sizeof(uint8_t));
- + main_buf = malloc(sizeof(uint8_t));
- -static double compute_vmaf_score()
- -{
- - printf("inside compute vmaf1\n");
- -
- - printf("width=%d,height=%d,format=%s\n",width,height,format);
- -
- - char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- -
- - double vmaf_score;
- - vmaf_score = compute_vmaf(format,width,height,read_frame,model_path);
- - printf("compute vmaf competed\n");
- - return vmaf_score;
- + memcpy(ref_buf, gref->data[0], sizeof(uint8_t));
- + memcpy(main_buf, gmain->data[0], sizeof(uint8_t));
- +
- + gref = NULL;
- + gmain = NULL;
- + pthread_cond_signal(&cond);
- + pthread_mutex_unlock(&lock);
- }
- static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- {
- -
- VMAFContext *s = ctx->priv;
- AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- + pthread_mutex_lock(&lock);
- + while(gref != NULL){
- + pthread_cond_wait(&cond, &lock);
- + }
- +
- + gref = malloc(sizeof(AVFrame));
- + gmain = malloc(sizeof(AVFrame));
- - //double score = compute_vmaf_score(s,main,ref);
- + memcpy(gref, ref, sizeof(AVFrame));
- + memcpy(gmain, main, sizeof(AVFrame));
- + pthread_cond_signal(&cond);
- + pthread_mutex_unlock(&lock);
- +
- +/*
- double score = 0;
- //set_meta(metadata, "lavfi.vmaf.score.",score);
- - av_log(ctx, AV_LOG_INFO, "vmaf score for frame %lu is %lf.\n",s->nb_frames,score);
- + //av_log(ctx, AV_LOG_INFO, "vmaf score for frame %lu is %lf.\n",s->nb_frames,score);
- + //printf("v");
- static int p = 0;
- -
- - if(p == 0){
- - head = (struct VMAFFrame*)malloc(sizeof(struct VMAFFrame));
- - head->ref_data = ref->data[0];
- - head->main_data = main->data[0];
- - head->ref_stride = ref->linesize[0];
- - head->main_data = main->linesize[0];
- - curr = head;
- - }
- - else{
- - struct VMAFFrame* new_node = (struct VMAFFrame*)malloc(sizeof(struct VMAFFrame));
- - new_node->ref_data = ref->data[0];
- - new_node->main_data = main->data[0];
- - new_node->ref_stride = ref->linesize[0];
- - new_node->main_data = main->linesize[0];
- - curr->next_frame = new_node;
- - curr = new_node;
- - }
- - p++;
- -
- -
- + p = 1;
- s->vmaf_sum += score;
- s->nb_frames++;
- -
- +*/
- return main;
- }
- +static void compute_vmaf_score()
- +{
- + printf("inside compute vmaf6\n");
- +
- + printf("width=%d,height=%d,format=%s\n",width,height,format);
- +
- + char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- +
- + double vmaf_score;
- +
- + vmaf_score = compute_vmaf(format, width, height, read_frame, model_path);
- + //printf("compute vmaf completed\n");
- + return vmaf_score;
- +}
- +
- +
- +static void *BusyWork(void *t)
- + {
- + int i;
- + long tid;
- + double result=0.0;
- + tid = (long)t;
- + printf("busy\n");
- + compute_vmaf_score();
- + pthread_exit((void*) t);
- + }
- +
- +
- static av_cold int init(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- -
- +
- if (s->stats_file_str) {
- if (s->stats_version < 2 && s->stats_add_max) {
- av_log(ctx, AV_LOG_ERROR,
- @@ -208,6 +221,8 @@ static int query_formats(AVFilterContext *ctx)
- AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV420P10LE,
- AV_PIX_FMT_NONE
- };
- + printf("query formats\n");
- + VMAFContext *s = ctx->priv;
- AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
- if (!fmts_list)
- @@ -215,6 +230,7 @@ static int query_formats(AVFilterContext *ctx)
- return ff_set_common_formats(ctx, fmts_list);
- }
- +
- static int config_input_ref(AVFilterLink *inlink)
- {
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
- @@ -231,10 +247,25 @@ static int config_input_ref(AVFilterLink *inlink)
- return AVERROR(EINVAL);
- }
- + printf("inside config input ref\n");
- +
- format = av_get_pix_fmt_name(ctx->inputs[0]->format);
- width = ctx->inputs[0]->w;
- height = ctx->inputs[0]->h;
- + /* Initialize mutex and condition variable objects */
- + pthread_mutex_init(&lock, NULL);
- + pthread_cond_init (&cond, NULL);
- +
- + pthread_attr_init(&s->attr);
- + int d = 5;
- +
- + s->main_thread_id=pthread_self();
- +
- + int rc = pthread_create(&s->thread, &s->attr, BusyWork, (void *)d);
- + s->vmaf_thread_id = s->thread;
- +
- +
- return 0;
- }
- @@ -268,7 +299,6 @@ static int request_frame(AVFilterLink *outlink)
- return ff_dualinput_request_frame(&s->dinput, outlink);
- }
- -
- static av_cold void uninit(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- @@ -281,10 +311,6 @@ static av_cold void uninit(AVFilterContext *ctx)
- if (s->stats_file && s->stats_file != stdout)
- fclose(s->stats_file);
- -
- - double vmaf_score = compute_vmaf_score();
- - printf("compute vmaf competed\n");
- - printf("%d\n",vmaf_score);
- return 0;
- }
- --
- 2.7.4
- From 0912925b28b3d0ad1985091c677ab758dcb71b6d Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Fri, 16 Jun 2017 04:24:05 +0530
- Subject: [PATCH 16/18] added main/ref copy data from avframe
- ---
- libavfilter/vf_vmaf.c | 38 ++++++++++++++++++++++++++++----------
- 1 file changed, 28 insertions(+), 10 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 50390b5..4913c4c 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -72,7 +72,6 @@ static int width, height;
- pthread_mutex_t lock;
- pthread_cond_t cond;
- int get_next = 0;
- -int data_yes = 0;
- AVFrame *gmain;
- AVFrame *gref;
- @@ -101,7 +100,7 @@ static void set_meta(AVDictionary **metadata, const char *key, float d)
- av_dict_set(metadata,key,value,0);
- }
- -static void read_frame(uint8_t *ref_buf, int *ref_stride, uint8_t *main_buf, int *main_stride){
- +static void read_frame(float *ref_data, int *ref_stride, float *main_data, int *main_stride){
- pthread_mutex_lock(&lock);
- while(gref == NULL){
- pthread_cond_wait(&cond, &lock);
- @@ -109,13 +108,31 @@ static void read_frame(uint8_t *ref_buf, int *ref_stride, uint8_t *main_buf, int
- *ref_stride = gref->linesize[0];
- *main_stride = gmain->linesize[0];
- + printf("%d %d\n",*ref_stride,*main_stride);
- + uint8_t *ptr = gref->data[0];
- + float *ptr1 = ref_data;
- +
- + int i,j;
- +
- + for(i=0;i<height;i++){
- + for(j=0;j<width;j++){
- + ptr1[j] = (float)ptr[j];
- + }
- + ptr += *ref_stride;
- + ptr1 += *ref_stride;
- + }
- - ref_buf = malloc(sizeof(uint8_t));
- - main_buf = malloc(sizeof(uint8_t));
- -
- - memcpy(ref_buf, gref->data[0], sizeof(uint8_t));
- - memcpy(main_buf, gmain->data[0], sizeof(uint8_t));
- + ptr = gmain->data[0];
- + ptr1 = main_data;
- + for(i=0;i<height;i++){
- + for(j=0;j<width;j++){
- + ptr1[j] = (float)ptr[j];
- + }
- + ptr += *main_stride;
- + ptr1 += *main_stride;
- + }
- +
- gref = NULL;
- gmain = NULL;
- @@ -134,6 +151,8 @@ static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- pthread_cond_wait(&cond, &lock);
- }
- + int i,j;
- +
- gref = malloc(sizeof(AVFrame));
- gmain = malloc(sizeof(AVFrame));
- @@ -143,15 +162,13 @@ static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- pthread_cond_signal(&cond);
- pthread_mutex_unlock(&lock);
- -/*
- - double score = 0;
- +/* double score = 0;
- //set_meta(metadata, "lavfi.vmaf.score.",score);
- //av_log(ctx, AV_LOG_INFO, "vmaf score for frame %lu is %lf.\n",s->nb_frames,score);
- //printf("v");
- static int p = 0;
- p = 1;
- s->vmaf_sum += score;
- -
- s->nb_frames++;
- */
- return main;
- @@ -269,6 +286,7 @@ static int config_input_ref(AVFilterLink *inlink)
- return 0;
- }
- +
- static int config_output(AVFilterLink *outlink)
- {
- AVFilterContext *ctx = outlink->src;
- --
- 2.7.4
- From 811b3487c028ca7f7d491fbb6fcc1e80c5cb98c3 Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Sat, 17 Jun 2017 03:22:59 +0530
- Subject: [PATCH 17/18] all the frames read and vmaf score output successfully
- ---
- libavfilter/vf_vmaf.c | 169 +++++++++++++++++++++++---------------------------
- 1 file changed, 78 insertions(+), 91 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 4913c4c..8d3ca03 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -52,10 +52,8 @@ typedef struct VMAFContext {
- int stats_header_written;
- int stats_add_max;
- int is_rgb;
- - pthread_t thread;
- - pthread_t main_thread_id;
- - pthread_t vmaf_thread_id;
- - pthread_attr_t attr;
- + pthread_t thread;
- + pthread_attr_t attr;
- uint8_t rgba_map[4];
- char comps[4];
- int nb_components;
- @@ -71,7 +69,9 @@ static char *format;
- static int width, height;
- pthread_mutex_t lock;
- pthread_cond_t cond;
- -int get_next = 0;
- +pthread_t main_thread_id;
- +pthread_t vmaf_thread_id;
- +int eof = 0;
- AVFrame *gmain;
- AVFrame *gref;
- @@ -100,112 +100,98 @@ static void set_meta(AVDictionary **metadata, const char *key, float d)
- av_dict_set(metadata,key,value,0);
- }
- -static void read_frame(float *ref_data, int *ref_stride, float *main_data, int *main_stride){
- - pthread_mutex_lock(&lock);
- - while(gref == NULL){
- - pthread_cond_wait(&cond, &lock);
- - }
- -
- +static int read_frame(float *ref_data, int *ref_stride, float *main_data, int *main_stride, double *score){
- + if(eof == 1){
- + return 1;
- + }
- + pthread_mutex_lock(&lock);
- + while(gref == NULL){
- + pthread_cond_wait(&cond, &lock);
- + }
- +
- *ref_stride = gref->linesize[0];
- *main_stride = gmain->linesize[0];
- - printf("%d %d\n",*ref_stride,*main_stride);
- - uint8_t *ptr = gref->data[0];
- - float *ptr1 = ref_data;
- -
- - int i,j;
- -
- - for(i=0;i<height;i++){
- - for(j=0;j<width;j++){
- - ptr1[j] = (float)ptr[j];
- - }
- - ptr += *ref_stride;
- - ptr1 += *ref_stride;
- - }
- -
- - ptr = gmain->data[0];
- - ptr1 = main_data;
- -
- - for(i=0;i<height;i++){
- - for(j=0;j<width;j++){
- - ptr1[j] = (float)ptr[j];
- - }
- - ptr += *main_stride;
- - ptr1 += *main_stride;
- - }
- -
- - gref = NULL;
- - gmain = NULL;
- -
- - pthread_cond_signal(&cond);
- - pthread_mutex_unlock(&lock);
- +
- + uint8_t *ptr = gref->data[0];
- + float *ptr1 = ref_data;
- +
- + int i,j;
- + for(i=0;i<height;i++){
- + for(j=0;j<width;j++){
- + ptr1[j] = (float)ptr[j];
- + }
- + ptr += *ref_stride;
- + ptr1 += *ref_stride;
- + }
- +
- + ptr = gmain->data[0];
- + ptr1 = main_data;
- +
- + for(i=0;i<height;i++){
- + for(j=0;j<width;j++){
- + ptr1[j] = (float)ptr[j];
- + }
- + ptr += *main_stride;
- + ptr1 += *main_stride;
- + }
- +
- + gref = NULL;
- + gmain = NULL;
- +
- + pthread_cond_signal(&cond);
- + pthread_mutex_unlock(&lock);
- +
- + return eof;
- }
- +
- static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- {
- VMAFContext *s = ctx->priv;
- AVDictionary **metadata = avpriv_frame_get_metadatap(main);
- - pthread_mutex_lock(&lock);
- - while(gref != NULL){
- - pthread_cond_wait(&cond, &lock);
- - }
- -
- - int i,j;
- + pthread_mutex_lock(&lock);
- + while(gref != NULL){
- + pthread_cond_wait(&cond, &lock);
- + }
- - gref = malloc(sizeof(AVFrame));
- - gmain = malloc(sizeof(AVFrame));
- + gref = malloc(sizeof(AVFrame));
- + gmain = malloc(sizeof(AVFrame));
- - memcpy(gref, ref, sizeof(AVFrame));
- - memcpy(gmain, main, sizeof(AVFrame));
- + memcpy(gref, ref, sizeof(AVFrame));
- + memcpy(gmain, main, sizeof(AVFrame));
- - pthread_cond_signal(&cond);
- - pthread_mutex_unlock(&lock);
- + pthread_cond_signal(&cond);
- + pthread_mutex_unlock(&lock);
- -/* double score = 0;
- - //set_meta(metadata, "lavfi.vmaf.score.",score);
- - //av_log(ctx, AV_LOG_INFO, "vmaf score for frame %lu is %lf.\n",s->nb_frames,score);
- - //printf("v");
- - static int p = 0;
- - p = 1;
- - s->vmaf_sum += score;
- - s->nb_frames++;
- -*/
- return main;
- }
- static void compute_vmaf_score()
- {
- - printf("inside compute vmaf6\n");
- -
- - printf("width=%d,height=%d,format=%s\n",width,height,format);
- char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- double vmaf_score;
- - vmaf_score = compute_vmaf(format, width, height, read_frame, model_path);
- - //printf("compute vmaf completed\n");
- - return vmaf_score;
- + vmaf_score = compute_vmaf(format, width, height, read_frame, model_path);
- }
- -
- -static void *BusyWork(void *t)
- - {
- +static void *call_vmaf(void *t)
- +{
- int i;
- long tid;
- double result=0.0;
- tid = (long)t;
- - printf("busy\n");
- - compute_vmaf_score();
- + compute_vmaf_score();
- pthread_exit((void*) t);
- - }
- -
- +}
- static av_cold int init(AVFilterContext *ctx)
- {
- VMAFContext *s = ctx->priv;
- -
- +
- if (s->stats_file_str) {
- if (s->stats_version < 2 && s->stats_add_max) {
- av_log(ctx, AV_LOG_ERROR,
- @@ -238,7 +224,6 @@ static int query_formats(AVFilterContext *ctx)
- AV_PIX_FMT_YUV444P10LE, AV_PIX_FMT_YUV422P10LE, AV_PIX_FMT_YUV420P10LE,
- AV_PIX_FMT_NONE
- };
- - printf("query formats\n");
- VMAFContext *s = ctx->priv;
- AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
- @@ -264,24 +249,20 @@ static int config_input_ref(AVFilterLink *inlink)
- return AVERROR(EINVAL);
- }
- - printf("inside config input ref\n");
- -
- - format = av_get_pix_fmt_name(ctx->inputs[0]->format);
- - width = ctx->inputs[0]->w;
- - height = ctx->inputs[0]->h;
- + format = av_get_pix_fmt_name(ctx->inputs[0]->format);
- + width = ctx->inputs[0]->w;
- + height = ctx->inputs[0]->h;
- - /* Initialize mutex and condition variable objects */
- pthread_mutex_init(&lock, NULL);
- pthread_cond_init (&cond, NULL);
- - pthread_attr_init(&s->attr);
- - int d = 5;
- -
- - s->main_thread_id=pthread_self();
- -
- - int rc = pthread_create(&s->thread, &s->attr, BusyWork, (void *)d);
- - s->vmaf_thread_id = s->thread;
- + pthread_attr_init(&s->attr);
- + int d = 5;
- + main_thread_id=pthread_self();
- +
- + int rc = pthread_create(&s->thread, &s->attr, call_vmaf, (void *)d);
- + vmaf_thread_id = s->thread;
- return 0;
- }
- @@ -330,7 +311,13 @@ static av_cold void uninit(AVFilterContext *ctx)
- if (s->stats_file && s->stats_file != stdout)
- fclose(s->stats_file);
- - return 0;
- + static int ptr = 0;
- + if(ptr == 1){
- + eof = 1;
- + pthread_join(vmaf_thread_id, NULL);
- + }
- + ptr++;
- + return 0;
- }
- static const AVFilterPad vmaf_inputs[] = {
- --
- 2.7.4
- From 7254c6b820f299bcdb583b0487f30b6d40ffb51e Mon Sep 17 00:00:00 2001
- From: ashk43712 <ashk43712@gmail.com>
- Date: Mon, 19 Jun 2017 21:19:47 +0530
- Subject: [PATCH 18/18] Removed printf messages and some bug fixes
- ---
- libavfilter/vf_vmaf.c | 2 --
- 1 file changed, 2 deletions(-)
- diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c
- index 8d3ca03..f080e67 100644
- --- a/libavfilter/vf_vmaf.c
- +++ b/libavfilter/vf_vmaf.c
- @@ -144,7 +144,6 @@ static int read_frame(float *ref_data, int *ref_stride, float *main_data, int *m
- return eof;
- }
- -
- static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- {
- VMAFContext *s = ctx->priv;
- @@ -170,7 +169,6 @@ static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
- static void compute_vmaf_score()
- {
- -
- char *model_path = "/usr/local/share/model/vmaf_v0.6.1.pkl";
- double vmaf_score;
- --
- 2.7.4
Add Comment
Please, Sign In to add comment