[x265] [PATCH] Add: Fix for VMAF Exceptions

Dakshinya T R S dakshinya at multicorewareinc.com
Fri Apr 9 07:05:27 UTC 2021


>From bf71142a6b22d33b2b2b8ebc8d80a019dbdf0a1d Mon Sep 17 00:00:00 2001
From: Dakshinya T R S <dakshinya at multicorewareinc.com>
Date: Wed, 7 Apr 2021 23:32:15 -0700
Subject: [PATCH] Fix VMAF exceptions

---
 source/encoder/api.cpp          | 38 ++++++++++++++++++++++++++++++---
 source/encoder/frameencoder.cpp |  1 +
 source/x265.h                   | 10 +++++----
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp
index a986355e0..9374bbc38 100644
--- a/source/encoder/api.cpp
+++ b/source/encoder/api.cpp
@@ -1903,22 +1903,34 @@ double x265_calculate_vmafscore(x265_param *param,
x265_vmaf_data *data)
     data->width = param->sourceWidth;
     data->height = param->sourceHeight;
     data->internalBitDepth = param->internalBitDepth;
+    data->format = (char *)malloc(11 * sizeof(char));

     if (param->internalCsp == X265_CSP_I420)
     {
         if ((param->sourceWidth * param->sourceHeight) % 2 != 0)
             x265_log(NULL, X265_LOG_ERROR, "Invalid file size\n");
         data->offset = param->sourceWidth * param->sourceHeight / 2;
+        memcpy(data->format, "yuv420p", 7);
     }
     else if (param->internalCsp == X265_CSP_I422)
+    {
         data->offset = param->sourceWidth * param->sourceHeight;
+        memcpy(data->format, "yuv422p", 7);
+    }
     else if (param->internalCsp == X265_CSP_I444)
+    {
         data->offset = param->sourceWidth * param->sourceHeight * 2;
+        memcpy(data->format, "yuv444p", 7);
+    }
     else
         x265_log(NULL, X265_LOG_ERROR, "Invalid format\n");
+    if (param->internalBitDepth == 10)
+        strcat(data->format, "10le");
+    else if (param->internalBitDepth == 12)
+        strcat(data->format, "12le");

-    compute_vmaf(&score, vcd->format, data->width, data->height,
read_frame, data, vcd->model_path, vcd->log_path, vcd->log_fmt,
vcd->disable_clip, vcd->disable_avx, vcd->enable_transform,
vcd->phone_model, vcd->psnr, vcd->ssim, vcd->ms_ssim, vcd->pool,
vcd->thread, vcd->subsample, vcd->enable_conf_interval);
-
+    compute_vmaf(&score, data->format, data->width, data->height,
read_frame, data, vcd->model_path, vcd->log_path, vcd->log_fmt,
vcd->disable_clip, vcd->disable_avx, vcd->enable_transform,
vcd->phone_model, vcd->psnr, vcd->ssim, vcd->ms_ssim, vcd->pool,
vcd->thread, vcd->subsample, vcd->enable_conf_interval);
+    free(data->format);
     return score;
 }

@@ -2019,8 +2031,28 @@ double
x265_calculate_vmaf_framelevelscore(x265_vmaf_framedata *vmafframedata)
         read_frame = read_frame_8bit;
     else
         read_frame = read_frame_10bit;
-    compute_vmaf(&score, vcd->format, vmafframedata->width,
vmafframedata->height, read_frame, vmafframedata, vcd->model_path,
vcd->log_path, vcd->log_fmt, vcd->disable_clip, vcd->disable_avx,
vcd->enable_transform, vcd->phone_model, vcd->psnr, vcd->ssim,
vcd->ms_ssim, vcd->pool, vcd->thread, vcd->subsample,
vcd->enable_conf_interval);
+    vmafframedata->format = (char *)malloc(11 * sizeof(char));

+    if (vmafframedata->internalCsp == X265_CSP_I420)
+    {
+        memcpy(vmafframedata->format, "yuv420p", 7);
+    }
+    else if (vmafframedata->internalCsp == X265_CSP_I422)
+    {
+        memcpy(vmafframedata->format, "yuv422p", 7);
+    }
+    else if (vmafframedata->internalCsp == X265_CSP_I444)
+    {
+        memcpy(vmafframedata->format, "yuv444p", 7);
+    }
+    else
+        x265_log(NULL, X265_LOG_ERROR, "Invalid format\n");
+    if (vmafframedata->internalBitDepth == 10)
+        strcat(vmafframedata->format, "10le");
+    else if (vmafframedata->internalBitDepth == 12)
+        strcat(vmafframedata->format, "12le");
+    compute_vmaf(&score, vmafframedata->format, vmafframedata->width,
vmafframedata->height, read_frame, vmafframedata, vcd->model_path,
vcd->log_path, vcd->log_fmt, vcd->disable_clip, vcd->disable_avx,
vcd->enable_transform, vcd->phone_model, vcd->psnr, vcd->ssim,
vcd->ms_ssim, vcd->pool, vcd->thread, vcd->subsample,
vcd->enable_conf_interval);
+    free(vmafframedata->format);
     return score;
 }
 #endif
diff --git a/source/encoder/frameencoder.cpp
b/source/encoder/frameencoder.cpp
index 2086a15a5..05c1d93a5 100644
--- a/source/encoder/frameencoder.cpp
+++ b/source/encoder/frameencoder.cpp
@@ -2143,6 +2143,7 @@ void FrameEncoder::vmafFrameLevelScore()
     vmafframedata->internalBitDepth = m_param->internalBitDepth;
     vmafframedata->reference_frame = fenc;
     vmafframedata->distorted_frame = recon;
+    vmafframedata->internalCsp = m_param->internalCsp;

     fenc->m_vmafScore = x265_calculate_vmaf_framelevelscore(vmafframedata);

diff --git a/source/x265.h b/source/x265.h
index f44040ba7..0e572e468 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -709,6 +709,7 @@ typedef struct x265_vmaf_data
     int internalBitDepth;
     FILE *reference_file; /* FILE pointer for input file */
     FILE *distorted_file; /* FILE pointer for recon file generated*/
+    char *format;
 }x265_vmaf_data;

 /* data to calculate frame level VMAF score */
@@ -716,16 +717,17 @@ typedef struct x265_vmaf_framedata
 {
     int width;
     int height;
-    int frame_set;
-    int internalBitDepth;
+    int frame_set;
+    int internalBitDepth;
     void *reference_frame; /* points to fenc of particular frame */
     void *distorted_frame; /* points to recon of particular frame */
+    char *format;
+    int internalCsp;
 }x265_vmaf_framedata;

 /* common data needed to calculate both frame level and video level VMAF
scores */
 typedef struct x265_vmaf_commondata
 {
-    char *format;
     char *model_path;
     char *log_path;
     char *log_fmt;
@@ -742,7 +744,7 @@ typedef struct x265_vmaf_commondata
     int enable_conf_interval;
 }x265_vmaf_commondata;

-static const x265_vmaf_commondata vcd[] = { { NULL, (char
*)"/usr/local/share/model/vmaf_v0.6.1.pkl", NULL, NULL, 0, 0, 0, 0, 0, 0,
0, NULL, 0, 1, 0 } };
+static const x265_vmaf_commondata vcd[] = { { (char
*)"/usr/local/share/model/vmaf_v0.6.1.json", NULL, NULL, 0, 0, 0, 0, 0, 0,
0, NULL, 0, 1, 0 } };

 /* x265 input parameters
  *
-- 
2.17.1


Thanks & Regards,
Dakshinya T R S,
Intern at Multicoreware,
Bannari Amman Institute of Technology,
Sathyamangalam.
______________________________________

x265-devel mailing list
x265-devel at videolan.org
https://mailman.videolan.org/listinfo/x265-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20210409/079f6292/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-VMAF-exceptions.patch
Type: application/octet-stream
Size: 6108 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20210409/079f6292/attachment.obj>


More information about the x265-devel mailing list