From 8b97a422217f93c98ceec97acd25dccd729ed71b Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 25 Jun 2024 00:48:34 +0800 Subject: [PATCH 1/2] avfilter/colorspace: fix dovi peak calculation The max PQ to max mastering display luminance calculation is wrong and not within the scale of ffmpeg. This will overflow the pixels during tone mapping unless the user supplies a peak value to overwrite this. - No need to multiply by reference white for PQ to luminance - The ffmpeg brightness scale for SMPTE ST.2084 is 100 not 10000 Before: 811943.437500 After: 399.9721366995 (4000 nit master display) --- debian/patches/0005-add-cuda-tonemap-impl.patch | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/debian/patches/0005-add-cuda-tonemap-impl.patch b/debian/patches/0005-add-cuda-tonemap-impl.patch index 251e50219c2..3d2b25c527c 100644 --- a/debian/patches/0005-add-cuda-tonemap-impl.patch +++ b/debian/patches/0005-add-cuda-tonemap-impl.patch @@ -98,7 +98,7 @@ Index: jellyfin-ffmpeg/libavfilter/colorspace.c void ff_matrix_mul_3x3(double dst[3][3], const double src1[3][3], const double src2[3][3]) { -@@ -191,3 +203,155 @@ void ff_update_hdr_metadata(AVFrame *in, +@@ -191,3 +202,155 @@ void ff_update_hdr_metadata(AVFrame *in, metadata->max_luminance = av_d2q(peak * REFERENCE_WHITE, 10000); } } @@ -120,8 +120,7 @@ Index: jellyfin-ffmpeg/libavfilter/colorspace.c + peak = powf(peak, 1.0f / ST2084_M2); + peak = fmaxf(peak - ST2084_C1, 0.0f) / (ST2084_C2 - ST2084_C3 * peak); + peak = powf(peak, 1.0f / ST2084_M1); -+ peak *= 10000.0f; -+ peak *= REFERENCE_WHITE_ALT; ++ peak *= 100.0f; + + return peak; +} From 4ce00f102d63d41e3e8b4947443fcff5148da991 Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 25 Jun 2024 01:19:01 +0800 Subject: [PATCH 2/2] fix build --- debian/patches/0005-add-cuda-tonemap-impl.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/patches/0005-add-cuda-tonemap-impl.patch b/debian/patches/0005-add-cuda-tonemap-impl.patch index 3d2b25c527c..a0a56afb533 100644 --- a/debian/patches/0005-add-cuda-tonemap-impl.patch +++ b/debian/patches/0005-add-cuda-tonemap-impl.patch @@ -98,7 +98,7 @@ Index: jellyfin-ffmpeg/libavfilter/colorspace.c void ff_matrix_mul_3x3(double dst[3][3], const double src1[3][3], const double src2[3][3]) { -@@ -191,3 +202,155 @@ void ff_update_hdr_metadata(AVFrame *in, +@@ -191,3 +203,154 @@ void ff_update_hdr_metadata(AVFrame *in, metadata->max_luminance = av_d2q(peak * REFERENCE_WHITE, 10000); } }