From: ichlubna@fit.vutbr.cz To: ffmpeg-devel@ffmpeg.org Cc: ichlubna <ichlubna@fit.vutbr.cz> Subject: [FFmpeg-devel] [PATCH] VMAF is now propagated to the AVFrame coming from the graph Date: Sat, 14 Oct 2023 08:00:42 +0200 Message-ID: <20231014060041.2252-2-ichlubna@fit.vutbr.cz> (raw) From: ichlubna <ichlubna@fit.vutbr.cz> Related to my ticket here: https://trac.ffmpeg.org/ticket/10586 VMAF score was not propagated to AVFormat like SSIM or PSNR in the result of the filter graph. I have fixed this to make the usage consistent and possible to get VMAF score per-frame in libavfilter. The only dirty thing here is the added for loop to compute the score twice. This is done to get the score in real time. Otherwise the score is delayed by one frame. Computing the score twice should not affect the final averaged result as each frame is added twice so the average does not change. --- libavfilter/vf_libvmaf.c | 76 +++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c index 2726b061ac..4c84877812 100644 --- a/libavfilter/vf_libvmaf.c +++ b/libavfilter/vf_libvmaf.c @@ -139,12 +139,40 @@ static int copy_picture_data(AVFrame *src, VmafPicture *dst, unsigned bpc) return 0; } +static enum VmafPoolingMethod pool_method_map(const char *pool_method) +{ + if (pool_method) { + if (av_stristr(pool_method, "min")) + return VMAF_POOL_METHOD_MIN; + if (av_stristr(pool_method, "mean")) + return VMAF_POOL_METHOD_MEAN; + if (av_stristr(pool_method, "harmonic_mean")) + return VMAF_POOL_METHOD_HARMONIC_MEAN; + } + + return VMAF_POOL_METHOD_MEAN; +} + +static void set_meta(AVDictionary **metadata, const char *key, char comp, float d) +{ + char value[128]; + snprintf(value, sizeof(value), "%f", 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 int do_vmaf(FFFrameSync *fs) { AVFilterContext *ctx = fs->parent; LIBVMAFContext *s = ctx->priv; VmafPicture pic_ref, pic_dist; AVFrame *ref, *dist; + double vmaf_score; int err = 0; int ret = ff_framesync_dualinput_get(fs, &dist, &ref); @@ -160,25 +188,29 @@ static int do_vmaf(FFFrameSync *fs) av_color_range_name(ref->color_range)); } - err = copy_picture_data(ref, &pic_ref, s->bpc); - if (err) { - av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n"); - return AVERROR(ENOMEM); - } + for(int i=0; i<2; i++){ + err = copy_picture_data(ref, &pic_ref, s->bpc); + if (err) { + av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n"); + return AVERROR(ENOMEM); + } - err = copy_picture_data(dist, &pic_dist, s->bpc); - if (err) { - av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n"); - vmaf_picture_unref(&pic_ref); - return AVERROR(ENOMEM); - } + err = copy_picture_data(dist, &pic_dist, s->bpc); + if (err) { + av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n"); + vmaf_picture_unref(&pic_ref); + return AVERROR(ENOMEM); + } - err = vmaf_read_pictures(s->vmaf, &pic_ref, &pic_dist, s->frame_cnt++); - if (err) { - av_log(s, AV_LOG_ERROR, "problem during vmaf_read_pictures.\n"); - return AVERROR(EINVAL); + err = vmaf_read_pictures(s->vmaf, &pic_ref, &pic_dist, s->frame_cnt++); + if (err) { + av_log(s, AV_LOG_ERROR, "problem during vmaf_read_pictures.\n"); + return AVERROR(EINVAL); + } } + vmaf_score_at_index(s->vmaf, s->model[0], &vmaf_score, s->frame_cnt - 2); + set_meta(&dist->metadata, "lavfi.vmaf", 0, vmaf_score); return ff_filter_frame(ctx->outputs[0], dist); } @@ -637,20 +669,6 @@ static enum VmafOutputFormat log_fmt_map(const char *log_fmt) return VMAF_OUTPUT_FORMAT_XML; } -static enum VmafPoolingMethod pool_method_map(const char *pool_method) -{ - if (pool_method) { - if (av_stristr(pool_method, "min")) - return VMAF_POOL_METHOD_MIN; - if (av_stristr(pool_method, "mean")) - return VMAF_POOL_METHOD_MEAN; - if (av_stristr(pool_method, "harmonic_mean")) - return VMAF_POOL_METHOD_HARMONIC_MEAN; - } - - return VMAF_POOL_METHOD_MEAN; -} - static av_cold void uninit(AVFilterContext *ctx) { LIBVMAFContext *s = ctx->priv; -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-10-14 6:01 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-14 6:00 ichlubna [this message] 2023-10-16 17:18 ` Kyle Swanson
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231014060041.2252-2-ichlubna@fit.vutbr.cz \ --to=ichlubna@fit.vutbr.cz \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git