>From e4401e650d05cb86aadcc4d22716b5ce6b6e1e84 Mon Sep 17 00:00:00 2001 From: Dakshinya T R S <dakshi...@multicorewareinc.com> Date: Fri, 16 Apr 2021 10:40:00 +0530 Subject: [PATCH] Fix VMAF exceptions
--- doc/reST/api.rst | 2 ++ source/CMakeLists.txt | 2 +- source/encoder/api.cpp | 8 +++++--- source/encoder/encoder.cpp | 20 ++++++++++++++++++++ source/encoder/encoder.h | 4 ++++ source/encoder/frameencoder.cpp | 1 + source/x265.h | 5 +++-- 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/doc/reST/api.rst b/doc/reST/api.rst index 7444f35af..96a62c40f 100644 --- a/doc/reST/api.rst +++ b/doc/reST/api.rst @@ -424,6 +424,8 @@ VMAF (Video Multi-Method Assessment Fusion) If you set the ENABLE_LIBVMAF cmake option to ON, then x265 will report per frame and aggregate VMAF score for the given input and dump the scores in csv file. The user also need to specify the :option:`--recon` in command line to get the VMAF scores. + +VMAF version support >= 2.0.0 /* x265_calculate_vmafScore: * returns VMAF score for the input video. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index b4e57b592..f4a9cb793 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CPU" OFF) option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF) mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD) # X265_BUILD must be incremented each time the public API is changed -set(X265_BUILD 200) +set(X265_BUILD 201) configure_file("${PROJECT_SOURCE_DIR}/x265.def.in" "${PROJECT_BINARY_DIR}/x265.def") configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in" diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp index 66f26e37e..5096e52ab 100644 --- a/source/encoder/api.cpp +++ b/source/encoder/api.cpp @@ -633,7 +633,9 @@ void x265_vmaf_encoder_log(x265_encoder* enc, int argc, char **argv, x265_param if (enc) { Encoder *encoder = static_cast<Encoder*>(enc); - x265_stats stats; + x265_stats stats; + + vmafdata->format = encoder->m_vmafInputFormat; stats.aggregateVmafScore = x265_calculate_vmafscore(param, vmafdata); if(vmafdata->reference_file) fclose(vmafdata->reference_file); @@ -1925,7 +1927,7 @@ double x265_calculate_vmafscore(x265_param *param, x265_vmaf_data *data) else x265_log(NULL, X265_LOG_ERROR, "Invalid format\n"); - 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); return score; } @@ -2027,7 +2029,7 @@ 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); + 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); return score; } diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp index c1e1cb46d..3d4742299 100644 --- a/source/encoder/encoder.cpp +++ b/source/encoder/encoder.cpp @@ -586,6 +586,22 @@ void Encoder::create() fail: m_aborted = true; } +#ifdef ENABLE_LIBVMAF + m_vmafInputFormat = X265_MALLOC(char, 11); + if (m_param->internalCsp == X265_CSP_I420) + memcpy(m_vmafInputFormat, "yuv420p", 7); + else if (m_param->internalCsp == X265_CSP_I422) + memcpy(m_vmafInputFormat, "yuv422p", 7); + else if (m_param->internalCsp == X265_CSP_I444) + memcpy(m_vmafInputFormat, "yuv444p", 7); + else + x265_log(NULL, X265_LOG_ERROR, "Invalid format\n"); + + if (m_param->internalBitDepth == 10) + strcat(m_vmafInputFormat, "10le"); + else if (m_param->internalBitDepth == 12) + strcat(m_vmafInputFormat, "12le"); +#endif } void Encoder::stopJobs() @@ -999,6 +1015,10 @@ void Encoder::destroy() #ifdef SVT_HEVC X265_FREE(m_svtAppData); #endif + +#ifdef ENABLE_LIBVMAF + X265_FREE(m_vmafInputFormat); +#endif if (m_param) { if (m_param->csvfpt) diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h index 2ee5bdaee..d0b74db70 100644 --- a/source/encoder/encoder.h +++ b/source/encoder/encoder.h @@ -296,6 +296,10 @@ public: ThreadSafeInteger* zoneReadCount; ThreadSafeInteger* zoneWriteCount; +#ifdef ENABLE_LIBVMAF + char* m_vmafInputFormat; +#endif + Encoder(); ~Encoder() { diff --git a/source/encoder/frameencoder.cpp b/source/encoder/frameencoder.cpp index 1b3875a25..11221078d 100644 --- a/source/encoder/frameencoder.cpp +++ b/source/encoder/frameencoder.cpp @@ -2151,6 +2151,7 @@ void FrameEncoder::vmafFrameLevelScore() vmafframedata->internalBitDepth = m_param->internalBitDepth; vmafframedata->reference_frame = fenc; vmafframedata->distorted_frame = recon; + vmafframedata->format = m_top->m_vmafInputFormat; fenc->m_vmafScore = x265_calculate_vmaf_framelevelscore(vmafframedata); diff --git a/source/x265.h b/source/x265.h index 324f3163f..a37741f53 100644 --- a/source/x265.h +++ b/source/x265.h @@ -712,6 +712,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 */ @@ -723,12 +724,12 @@ typedef struct x265_vmaf_framedata int internalBitDepth; void *reference_frame; /* points to fenc of particular frame */ void *distorted_frame; /* points to recon of particular frame */ + char *format; }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; @@ -745,7 +746,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@videolan.org https://mailman.videolan.org/listinfo/x265-devel On Thu, Apr 15, 2021 at 6:08 PM Dakshinya T R S < dakshi...@multicorewareinc.com> wrote: > Sure. I have noted it and I am working on the changes. > > Thanks & Regards, > Dakshinya T R S, > Intern at Multicoreware, > Bannari Amman Institute of Technology, > Sathyamangalam. > > > > > On Mon, Apr 12, 2021 at 4:44 PM Pooja Venkatesan < > po...@multicorewareinc.com> wrote: > >> FYI >> Regards, >> *Pooja Venkatesan*, >> Video Codec Engineer, >> Media & AI analytics BU >> >> >> >> ---------- Forwarded message --------- >> From: Aruna Matheswaran <ar...@multicorewareinc.com> >> Date: Mon, Apr 12, 2021 at 3:54 PM >> Subject: Re: [x265] [PATCH] Add: Fix for VMAF Exceptions >> To: Development for x265 <x265-devel@videolan.org> >> >> >> >> >> On Fri, Apr 9, 2021 at 12:35 PM Dakshinya T R S < >> dakshi...@multicorewareinc.com> wrote: >> >>> From bf71142a6b22d33b2b2b8ebc8d80a019dbdf0a1d Mon Sep 17 00:00:00 2001 >>> From: Dakshinya T R S <dakshi...@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)); >>> [AM] Repeated malloc shall be avoided if the format is captured in >>> encoder handle or in m_cliopt.vmafData after input file info parsing. >>> 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"); >>> >> [AM] Same comment as above. >> >>> + 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; >>> [AM] Update X265_BUILD. >>> /* 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 >>> >> [AM] Please mention the VMAF version with the integration works fine in >> VMAF documentation. >> >>> * >>> -- >>> 2.17.1 >>> >>> >>> Thanks & Regards, >>> Dakshinya T R S, >>> Intern at Multicoreware, >>> Bannari Amman Institute of Technology, >>> Sathyamangalam. >>> ______________________________________ >>> >>> x265-devel mailing list >>> x265-devel@videolan.org >>> https://mailman.videolan.org/listinfo/x265-devel >>> _______________________________________________ >>> x265-devel mailing list >>> x265-devel@videolan.org >>> https://mailman.videolan.org/listinfo/x265-devel >>> >> >> >> -- >> Regards, >> *Aruna Matheswaran,* >> Video Codec Engineer, >> Media & AI analytics BU, >> >> >> >> _______________________________________________ >> x265-devel mailing list >> x265-devel@videolan.org >> https://mailman.videolan.org/listinfo/x265-devel >> > -- *Dakshinya T R S,* *Intern at Multicoreware,* *Bannari Amman Institute of Technology,* *Sathyamangalam.*
Fix-VMAF-exceptions.patch
Description: Binary data
_______________________________________________ x265-devel mailing list x265-devel@videolan.org https://mailman.videolan.org/listinfo/x265-devel