[FFmpeg-devel] [PATCH] Added VMAF filter linking to Netflix's vmaf library

James Almer jamrial at gmail.com
Wed Jun 21 18:42:41 EEST 2017


On 6/21/2017 9:16 AM, Ashish Singh wrote:
> This is VMAF filter which requires Netflix's vmaf library installed but currently there is no library implementation in the Netflix's vmaf. I will open a pull request soon to Netflix's vmaf for the library integration code and provide a link in this thread.
> This uses pthreads (mutex/cond) where this filter runs in the main thread and Netflix's vmaf runs in a separate thread and it pulls the frames from libavfilter through mutex/cond(wait/signal) pairs. Library header is "libvmaf.h" which contains an API, compute_vmaf(..). There is a callback function inside this patch called read_frame() (passed as a parameter in compute_vmaf(..)) which gets called from inside Netflix's library to repeatedly update the frame data.
> After installing the Netflix's vmaf library, do --enable-libvmaf at the time of configure. It can be run using "ffmpeg -i main -i ref -lavfi vmaf -f null -"
> 
> ---
>  configure                |   6 +
>  libavfilter/Makefile     |   1 +
>  libavfilter/allfilters.c |   1 +
>  libavfilter/vf_vmaf.c    | 353 +++++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/vmaf.h       |  33 +++++
>  5 files changed, 394 insertions(+)
>  create mode 100644 libavfilter/vf_vmaf.c
>  create mode 100644 libavfilter/vmaf.h
> 
> diff --git a/configure b/configure
> index 5ae5227..8487f06 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

No tabs outside of Make files.

>      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,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           && { use_pkg_config libvmaf "libvmaf.h" compute_vmaf ||
> +                               { check_lib libvmaf "libvmaf.h" "compute_vmaf" -lvmaf -lstdc++ -lpthread -lm &&
> +                                 warn "using libvmaf without pkg-config"; } }

Remove the fallback. We only keep those for old libraries that at some
point didn't use pkg-config for the sake of preventing "regressions".
New additions should use exclusively pkg-config if a .pc file is
installed by the project.

Also, if pthreads is needed, you should add a check for it, maybe
something like how the jni check does.

>  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..a9c6e4d
> --- /dev/null
> +++ b/libavfilter/vf_vmaf.c
> @@ -0,0 +1,353 @@
> +/*
> + * Copyright (c) 2017 Ronald S. Bultje <rsbultje at gmail.com>
> + * Copyright (c) 2017 Ashish Pratap Singh <ashk43712 at 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
> + */
> +
> +/**
> + * @file
> + * Caculate the VMAF between two input videos.
> + */
> +
> +#include <inttypes.h>
> +#include <pthread.h>
> +#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"
> +#include "vmaf.h"
> +#include "libvmaf.h"

This is a system header, so use <> and include it before libav* headers.


More information about the ffmpeg-devel mailing list