From patchwork Sun Jul 2 06:04:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashish Singh X-Patchwork-Id: 4187 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp7786709vsb; Sat, 1 Jul 2017 23:06:49 -0700 (PDT) X-Received: by 10.28.93.197 with SMTP id r188mr19616625wmb.44.1498975609437; Sat, 01 Jul 2017 23:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498975609; cv=none; d=google.com; s=arc-20160816; b=Xiu8/UVC08P0AfjbeZhIg1w3eX/BpIjK7Zr5GX+ryhVsmRvUqC/q/8cl9YrXkp1q45 9+NUCih26xGAPsTfpHr8okgJtRykprDIcPiJQDQ7dJ7OHWWtWKM78nioSwnqNIm3kymp Etjoxifu9wHnvRF5oglpQFJf9Hei5IZuii9BQf67mpWrn1True7bPocFSwyr+dul+RK/ asGqIO0w+RwD3eaC2qC1Ch1eX6UMJ+mpI+91CZW5pw2RNRg4+w51X+lOjq9XtAhodgYR w+gnnO4yZ8Qx3sCQV5jC6u9T0eG7ymVGNl4a5TCvuMkxJr+DVwZ9tb9Y/C9DiIhscMQD 9TrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=GK/ToRiYXJHhbzAcKNVd8t8Z+NIudwixgxB74rH4XbI=; b=r1YAzeUyGS1ZJMZrnBvfjwqtOwh6VBzIUyXrodHX5oWz9HMSJfT0TItafx4ptxHkwp Px54YzUEGXS04X83zeRwpt0sd5DQlBlzyEgP0aqvm1fDh6y5NQGEBNm+cDXNPYWmTnl4 a/2DTSU2HdQamrnIY/A7Zk44w1fQmW3OyAjrMakvmqiGUxAddGuxTQMJ0L0Ei3SXjVr4 v+W6qQhP2ymyDpD1+lrd240T/v6KtKJm30UuM+HQ80XabzuetLxhJodxZWwg/b6+gy+A XQWE/iTiMrKEEmUci3x/PSBtX6+gS1saed6Ntt2SvWk8XeH5M+Ln+xIv/S3+cbAKEWLN vbZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=JtyB2MY/; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j25si9122798wre.322.2017.07.01.23.06.48; Sat, 01 Jul 2017 23:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.b=JtyB2MY/; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B143E6882AA; Sun, 2 Jul 2017 09:06:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B6B2A680A6A for ; Sun, 2 Jul 2017 09:06:37 +0300 (EEST) Received: by mail-pg0-f68.google.com with SMTP id u62so19711127pgb.0 for ; Sat, 01 Jul 2017 23:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QxHtDBecFpvW9F1mzH/x4V/HddEnY3KERsXam5/hAZo=; b=JtyB2MY/wCW3L973YoqNCPoZkofb3v6AtT0KsoEHoRdzsu8AMD7SmVMyDs0yeFDy1a YHj6YS5k2pB1yY1BzGjdTFoTZfKoAEql4iouFeBPmCASsuTXgwLW5b71H9AyRVq0XMp+ gzrQa+qvRHN7Mk3YRYvuDknX+ZzD7oYsRg9b+6pkmzmGoWRPO28SGXp0/23pWhw21jRQ 7D8og8IGB09d6rLVVxg/9KOkfXp13DA0vcQtGxk4eXEp8wIJc/F2lzx6pct/B+zL8BmU o0QiBucDYb3cIj0A0ZdvLKcpA9bnU9nTNf3P7Mgpp7Q6K8KxBfH0VH3OcCTG3LcLg4O0 PHLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QxHtDBecFpvW9F1mzH/x4V/HddEnY3KERsXam5/hAZo=; b=jxRjNd4CQKUzZ9F8Uy6ZOxm3tTGFzP6qYmQmmgKgMVjwvtGArCXSR1S4LDF9I25M7B 13bR7bj+51vrEjP194geshWhU/hYLv8K7XCoomvuKfHP8P9xM5/hL3CMiqsUsrjuOF5v YSQFleGRz+ArWGRCPgjClbSs8xYi2neoK7XKkQ7yTHemTLWYTPbhn0V8XfiCXOM7+8+F skuSJuzSY+wbA44x6rIAmiyfnJ3cdJow2RuZBwKLK1PM2n8BwrkWfEAMaCPQ9U3nj0J7 qrdDFO4v4Bm0Yh7m2l0HV2KIMQcZcBjamowXwZw8iY+P1rZ6LUkjsnX0XjcxHuOIEce+ P9Vg== X-Gm-Message-State: AIVw113hDRccSj8C2eAZCQuUDceQ9QSD0MwBCnn6dh6B9A8geubZlEBT v/DcaWWi70uuuipj X-Received: by 10.84.224.11 with SMTP id r11mr3941151plj.267.1498975596517; Sat, 01 Jul 2017 23:06:36 -0700 (PDT) Received: from localhost.localdomain ([117.244.43.168]) by smtp.gmail.com with ESMTPSA id d24sm29703509pfk.43.2017.07.01.23.06.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 01 Jul 2017 23:06:35 -0700 (PDT) From: Ashish Singh To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Jul 2017 11:34:11 +0530 Message-Id: <1498975451-18151-1-git-send-email-ashk43712@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498331269-8623-1-git-send-email-ashk43712@gmail.com> References: <1498331269-8623-1-git-send-email-ashk43712@gmail.com> Subject: [FFmpeg-devel] [PATCH] avfilter: add VMAF filter X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Ashish Singh MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This patch fixes most of the styling and coding issues of the previous VMAF patches. --- configure | 5 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_vmaf.c | 400 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 407 insertions(+) create mode 100644 libavfilter/vf_vmaf.c diff --git a/configure b/configure index 5ae5227..faaf236 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,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 && { check_lib libvmaf "libvmaf.h" "compute_vmaf" -lvmaf -lstdc++ -lpthread -lm || + 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/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); diff --git a/libavfilter/vf_vmaf.c b/libavfilter/vf_vmaf.c new file mode 100644 index 0000000..f787e83 --- /dev/null +++ b/libavfilter/vf_vmaf.c @@ -0,0 +1,400 @@ +/* + * Copyright (c) 2017 Ronald S. Bultje + * Copyright (c) 2017 Ashish Pratap Singh + * + * 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 + * Calculate the VMAF between two input videos. + */ + +#include +#include +#include +#include +#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 "video.h" + +typedef struct VMAFContext { + const AVClass *class; + FFDualInputContext dinput; + char *format; + int width; + int height; + double vmaf_score; + pthread_t vmaf_thread; + pthread_mutex_t lock; + pthread_cond_t cond; + int eof; + AVFrame *gmain; + AVFrame *gref; + int frame_set; + char *model_path; + char *log_path; + char *log_fmt; + int disable_clip; + int disable_avx; + int enable_transform; + int phone_model; + int psnr; + int ssim; + int ms_ssim; + char *pool; +} VMAFContext; + +#define OFFSET(x) offsetof(VMAFContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM + +static const AVOption vmaf_options[] = { + {"model_path", "Set the model to be used for computing vmaf.", OFFSET(model_path), AV_OPT_TYPE_STRING, {.str="/usr/local/share/model/vmaf_v0.6.1.pkl"}, 0, 1, FLAGS}, + {"log_path", "Set the file path to be used to store logs.", OFFSET(log_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, + {"log_fmt", "Set the format of the log (xml or json).", OFFSET(log_fmt), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, + {"disable_clip", "Disables clip for computing vmaf.", OFFSET(disable_clip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"disable avx", "Disables avx for computing vmaf.", OFFSET(disable_avx), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"enable_transform", "Enables transform for computing vmaf.", OFFSET(enable_transform), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"phone_model", "Invokes the phone model that will generate higher VMAF scores.", OFFSET(phone_model), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"psnr", "Enables computing psnr along with vmaf.", OFFSET(psnr), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"ssim", "Enables computing ssim along with vmaf.", OFFSET(ssim), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"ms_ssim", "Enables computing ms-ssim along with vmaf.", OFFSET(ms_ssim), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, + {"pool", "Set the pool method to be used for computing vmaf.", OFFSET(pool), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 1, FLAGS}, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(vmaf); + +static int read_frame_8bit(float *ref_data, float *main_data, float *temp_data, + int stride, double *score, void *ctx) +{ + VMAFContext *s = (VMAFContext *) ctx; + int ret; + + pthread_mutex_lock(&s->lock); + + while (!s->frame_set && !s->eof) { + pthread_cond_wait(&s->cond, &s->lock); + } + + if (s->frame_set) { + int ref_stride = s->gref->linesize[0]; + int main_stride = s->gmain->linesize[0]; + + uint8_t *ptr = s->gref->data[0]; + float *ptr1 = ref_data; + + int h = s->height; + int w = s->width; + + int i,j; + + for (i = 0; i < h; i++) { + for ( j = 0; j < w; j++) { + ptr1[j] = (float)ptr[j]; + } + ptr += ref_stride/sizeof(*ptr); + ptr1 += stride/sizeof(*ptr1); + } + + ptr = s->gmain->data[0]; + ptr1 = main_data; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + ptr1[j] = (float)ptr[j]; + } + ptr += main_stride/sizeof(*ptr); + ptr1 += stride/sizeof(*ptr1); + } + } + + ret = !s->frame_set; + + s->frame_set = 0; + + pthread_cond_signal(&s->cond); + pthread_mutex_unlock(&s->lock); + + if (ret) { + return 2; + } + + return 0; +} + +static int read_frame_10bit(float *ref_data, float *main_data, float *temp_data, + int stride, double *score, void *ctx) +{ + VMAFContext *s = (VMAFContext *) ctx; + int ret; + + pthread_mutex_lock(&s->lock); + + while (!s->frame_set && !s->eof) { + pthread_cond_wait(&s->cond, &s->lock); + } + + if (s->frame_set) { + int ref_stride = s->gref->linesize[0]; + int main_stride = s->gmain->linesize[0]; + + uint16_t *ptr = (uint16_t *) s->gref->data[0]; + float *ptr1 = ref_data; + + int h = s->height; + int w = s->width; + + int i,j; + + for (i = 0; i < h; i++) { + for ( j = 0; j < w; j++) { + ptr1[j] = (float)ptr[j]; + } + ptr += ref_stride/sizeof(*ptr); + ptr1 += stride/sizeof(*ptr1); + } + + ptr = (uint16_t *) s->gmain->data[0]; + ptr1 = main_data; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + ptr1[j] = (float)ptr[j]; + } + ptr += main_stride/sizeof(*ptr); + ptr1 += stride/sizeof(*ptr1); + } + } + + ret = !s->frame_set; + + s->frame_set = 0; + + pthread_cond_signal(&s->cond); + pthread_mutex_unlock(&s->lock); + + if (ret) { + return 2; + } + + return 0; +} + +static void compute_vmaf_score(VMAFContext *s) +{ + int (*read_frame)(float *ref_data, float *main_data, float *temp_data, + int stride, double *score, void *ctx); + + if (!strcmp(s->format, "yuv420p") || !strcmp(s->format, "yuv422p") || + !strcmp(s->format, "yuv444p")) { + read_frame = read_frame_8bit; + } else { + read_frame = read_frame_10bit; + } + + s->vmaf_score = compute_vmaf(s->format, s->width, s->height, read_frame, s, + s->model_path, s->log_path, s->log_fmt, + s->disable_clip, s->disable_avx, + s->enable_transform, s->phone_model, + s->psnr, s->ssim, s->ms_ssim, s->pool); +} + +static void *call_vmaf(void *ctx) +{ + VMAFContext *s = (VMAFContext *) ctx; + compute_vmaf_score(s); + pthread_exit(NULL); +} + +static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref) +{ + VMAFContext *s = ctx->priv; + + pthread_mutex_lock(&s->lock); + + while (s->frame_set != 0) { + pthread_cond_wait(&s->cond, &s->lock); + } + + av_frame_ref(s->gref, ref); + av_frame_ref(s->gmain, main); + + s->frame_set = 1; + + pthread_cond_signal(&s->cond); + pthread_mutex_unlock(&s->lock); + + return main; +} + +static av_cold int init(AVFilterContext *ctx) +{ + VMAFContext *s = ctx->priv; + + s->gref = av_frame_alloc(); + s->gmain = av_frame_alloc(); + + pthread_mutex_init(&s->lock, NULL); + pthread_cond_init (&s->cond, NULL); + + s->dinput.process = do_vmaf; + return 0; +} + +static int query_formats(AVFilterContext *ctx) +{ + static const enum AVPixelFormat pix_fmts[] = { + 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 + }; + + 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) +{ + AVFilterContext *ctx = inlink->dst; + VMAFContext *s = ctx->priv; + int th; + + 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); + } + if (!(s->model_path)) { + av_log(ctx, AV_LOG_ERROR, "No model specified.\n"); + return AVERROR(EINVAL); + } + + s->format = av_get_pix_fmt_name(ctx->inputs[0]->format); + s->width = ctx->inputs[0]->w; + s->height = ctx->inputs[0]->h; + + th = pthread_create(&s->vmaf_thread, NULL, call_vmaf, (void *)s); + if (th) { + av_log(ctx, AV_LOG_ERROR, "Thread creation failed.\n"); + return AVERROR(EINVAL); + } + + 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; + + ff_dualinput_uninit(&s->dinput); + + pthread_mutex_lock(&s->lock); + s->eof = 1; + pthread_cond_signal(&s->cond); + pthread_mutex_unlock(&s->lock); + + pthread_join(s->vmaf_thread, NULL); + + av_frame_free(&s->gref); + av_frame_free(&s->gmain); + + pthread_mutex_destroy(&s->lock); + pthread_cond_destroy(&s->cond); + + av_log(ctx, AV_LOG_INFO, "VMAF score: %f\n",s->vmaf_score); +} + +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, +};