From 16ab9b0d4d8cd08c0a8810f570ca2e8ecf6207ef Mon Sep 17 00:00:00 2001 From: Johnson Ding Date: Fri, 20 Dec 2024 15:40:21 +0800 Subject: [PATCH] feat[test]: Add PSNR info for video encoder Note that the PSNR derived from SSE may not equals to PSNR from video analyser. Because SSE returned from hardware is consist of both luma and chroma samples. And SSE of chroma samples multiplied by some weight. But the difference is within 1db, usually no more than 0.5db. Change-Id: I294d473c656f39ce98dd0768cd6945ee38e89b14 Signed-off-by: Johnson Ding --- test/mpi_enc_test.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index a2d9fcc2..e1196616 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -21,6 +21,7 @@ #define MODULE_TAG "mpi_enc_test" #include +#include #include "rk_mpi.h" #include "mpp_env.h" @@ -658,6 +659,8 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info) RK_U32 cap_num = 0; DataCrc checkcrc; MPP_RET ret = MPP_OK; + RK_FLOAT psnr_const = 0; + RK_U32 sse_unit_in_pixel = 0; memset(&checkcrc, 0, sizeof(checkcrc)); checkcrc.sum = mpp_malloc(RK_ULONG, 512); @@ -689,6 +692,10 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info) } mpp_packet_deinit(&packet); + + sse_unit_in_pixel = p->type == MPP_VIDEO_CodingAVC ? 16 : 8; + psnr_const = (16 + log2(MPP_ALIGN(p->width, sse_unit_in_pixel) * + MPP_ALIGN(p->height, sse_unit_in_pixel))); } while (!p->pkt_eos) { MppMeta meta = NULL; @@ -919,6 +926,8 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info) RK_S32 lt_idx = -1; RK_S32 avg_qp = -1, bps_rt = -1; RK_S32 use_lt_idx = -1; + RK_S64 sse = 0; + RK_FLOAT psnr = 0; if (MPP_OK == mpp_meta_get_s32(meta, KEY_TEMPORAL_ID, &temporal_id)) log_len += snprintf(log_buf + log_len, log_size - log_len, @@ -938,6 +947,12 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info) if (MPP_OK == mpp_meta_get_s32(meta, KEY_ENC_USE_LTR, &use_lt_idx)) log_len += snprintf(log_buf + log_len, log_size - log_len, " vi"); + + if (MPP_OK == mpp_meta_get_s64(meta, KEY_ENC_SSE, &sse)) { + psnr = 3.01029996 * (psnr_const - log2(sse)); + log_len += snprintf(log_buf + log_len, log_size - log_len, + " psnr %.4f", psnr); + } } mpp_log_q(quiet, "chn %d %s\n", chn, log_buf);