* [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV
@ 2023-02-03 15:53 Tomas Härdin
2023-02-03 15:54 ` [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support Tomas Härdin
2023-02-13 10:14 ` [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV Tomas Härdin
0 siblings, 2 replies; 7+ messages in thread
From: Tomas Härdin @ 2023-02-03 15:53 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0001-lavfi-vf_colorspace-Add-support-for-14-and-16-bit-YU.patch --]
[-- Type: text/x-patch, Size: 6298 bytes --]
From 33c0ff957b5a37c1d59069ee414282bb45d21298 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Fri, 3 Feb 2023 15:00:05 +0100
Subject: [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV
---
libavfilter/colorspacedsp.c | 36 +++++++++++++++++++++++++++-
libavfilter/colorspacedsp.h | 2 ++
libavfilter/colorspacedsp_template.c | 8 +++++++
libavfilter/vf_colorspace.c | 10 +++++++-
4 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/libavfilter/colorspacedsp.c b/libavfilter/colorspacedsp.c
index 72207ffaf3..75a442fb66 100644
--- a/libavfilter/colorspacedsp.c
+++ b/libavfilter/colorspacedsp.c
@@ -39,6 +39,14 @@
#define BIT_DEPTH 12
#include "colorspacedsp_template.c"
+#undef BIT_DEPTH
+#define BIT_DEPTH 14
+#include "colorspacedsp_template.c"
+
+#undef BIT_DEPTH
+#define BIT_DEPTH 16
+#include "colorspacedsp_template.c"
+
#undef SS_W
#undef SS_H
@@ -57,6 +65,14 @@
#define BIT_DEPTH 12
#include "colorspacedsp_template.c"
+#undef BIT_DEPTH
+#define BIT_DEPTH 14
+#include "colorspacedsp_template.c"
+
+#undef BIT_DEPTH
+#define BIT_DEPTH 16
+#include "colorspacedsp_template.c"
+
#undef SS_W
#undef SS_H
@@ -75,6 +91,14 @@
#define BIT_DEPTH 12
#include "colorspacedsp_template.c"
+#undef BIT_DEPTH
+#define BIT_DEPTH 14
+#include "colorspacedsp_template.c"
+
+#undef BIT_DEPTH
+#define BIT_DEPTH 16
+#include "colorspacedsp_template.c"
+
static void multiply3x3_c(int16_t *buf[3], ptrdiff_t stride,
int w, int h, const int16_t m[3][3][8])
{
@@ -109,6 +133,8 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
init_yuv2rgb_fn( 8);
init_yuv2rgb_fn(10);
init_yuv2rgb_fn(12);
+ init_yuv2rgb_fn(14);
+ init_yuv2rgb_fn(16);
#define init_rgb2yuv_fn(bit) \
dsp->rgb2yuv[BPP_##bit][SS_444] = rgb2yuv_444p##bit##_c; \
@@ -118,6 +144,8 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
init_rgb2yuv_fn( 8);
init_rgb2yuv_fn(10);
init_rgb2yuv_fn(12);
+ init_rgb2yuv_fn(14);
+ init_rgb2yuv_fn(16);
#define init_rgb2yuv_fsb_fn(bit) \
dsp->rgb2yuv_fsb[BPP_##bit][SS_444] = rgb2yuv_fsb_444p##bit##_c; \
@@ -127,6 +155,8 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
init_rgb2yuv_fsb_fn( 8);
init_rgb2yuv_fsb_fn(10);
init_rgb2yuv_fsb_fn(12);
+ init_rgb2yuv_fsb_fn(14);
+ init_rgb2yuv_fsb_fn(16);
#define init_yuv2yuv_fn(idx1, bit1, bit2) \
dsp->yuv2yuv[idx1][BPP_##bit2][SS_444] = yuv2yuv_444p##bit1##to##bit2##_c; \
@@ -135,11 +165,15 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
#define init_yuv2yuv_fns(bit1) \
init_yuv2yuv_fn(BPP_##bit1, bit1, 8); \
init_yuv2yuv_fn(BPP_##bit1, bit1, 10); \
- init_yuv2yuv_fn(BPP_##bit1, bit1, 12)
+ init_yuv2yuv_fn(BPP_##bit1, bit1, 12); \
+ init_yuv2yuv_fn(BPP_##bit1, bit1, 14); \
+ init_yuv2yuv_fn(BPP_##bit1, bit1, 16)
init_yuv2yuv_fns( 8);
init_yuv2yuv_fns(10);
init_yuv2yuv_fns(12);
+ init_yuv2yuv_fns(14);
+ init_yuv2yuv_fns(16);
dsp->multiply3x3 = multiply3x3_c;
diff --git a/libavfilter/colorspacedsp.h b/libavfilter/colorspacedsp.h
index a81e4f0a52..c994bcfe67 100644
--- a/libavfilter/colorspacedsp.h
+++ b/libavfilter/colorspacedsp.h
@@ -46,6 +46,8 @@ enum BitDepthIndex {
BPP_8,
BPP_10,
BPP_12,
+ BPP_14,
+ BPP_16,
NB_BPP,
};
diff --git a/libavfilter/colorspacedsp_template.c b/libavfilter/colorspacedsp_template.c
index 53ac0d7224..08d809979f 100644
--- a/libavfilter/colorspacedsp_template.c
+++ b/libavfilter/colorspacedsp_template.c
@@ -340,3 +340,11 @@ static void fn(rgb2yuv_fsb)(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3],
#undef IN_BIT_DEPTH
#define IN_BIT_DEPTH 12
#include "colorspacedsp_yuv2yuv_template.c"
+
+#undef IN_BIT_DEPTH
+#define IN_BIT_DEPTH 14
+#include "colorspacedsp_yuv2yuv_template.c"
+
+#undef IN_BIT_DEPTH
+#define IN_BIT_DEPTH 16
+#include "colorspacedsp_yuv2yuv_template.c"
diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
index 21916b7b7a..1e1ab5fb34 100644
--- a/libavfilter/vf_colorspace.c
+++ b/libavfilter/vf_colorspace.c
@@ -402,7 +402,7 @@ static int create_filtergraph(AVFilterContext *ctx,
const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(out->format);
int emms = 0, m, n, o, res, fmt_identical, redo_yuv2rgb = 0, redo_rgb2yuv = 0;
-#define supported_depth(d) ((d) == 8 || (d) == 10 || (d) == 12)
+#define supported_depth(d) ((d) == 8 || (d) == 10 || (d) == 12 || (d) == 14 || (d) == 16)
#define supported_subsampling(lcw, lch) \
(((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))
#define supported_format(d) \
@@ -842,6 +842,8 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
+ AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
+ AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
AV_PIX_FMT_NONE
};
@@ -961,12 +963,18 @@ static const AVOption colorspace_options[] = {
ENUM("yuv420p", AV_PIX_FMT_YUV420P, "fmt"),
ENUM("yuv420p10", AV_PIX_FMT_YUV420P10, "fmt"),
ENUM("yuv420p12", AV_PIX_FMT_YUV420P12, "fmt"),
+ ENUM("yuv420p14", AV_PIX_FMT_YUV420P14, "fmt"),
+ ENUM("yuv420p16", AV_PIX_FMT_YUV420P16, "fmt"),
ENUM("yuv422p", AV_PIX_FMT_YUV422P, "fmt"),
ENUM("yuv422p10", AV_PIX_FMT_YUV422P10, "fmt"),
ENUM("yuv422p12", AV_PIX_FMT_YUV422P12, "fmt"),
+ ENUM("yuv422p14", AV_PIX_FMT_YUV422P14, "fmt"),
+ ENUM("yuv422p16", AV_PIX_FMT_YUV422P16, "fmt"),
ENUM("yuv444p", AV_PIX_FMT_YUV444P, "fmt"),
ENUM("yuv444p10", AV_PIX_FMT_YUV444P10, "fmt"),
ENUM("yuv444p12", AV_PIX_FMT_YUV444P12, "fmt"),
+ ENUM("yuv444p14", AV_PIX_FMT_YUV444P14, "fmt"),
+ ENUM("yuv444p16", AV_PIX_FMT_YUV444P16, "fmt"),
{ "fast", "Ignore primary chromaticity and gamma correction",
OFFSET(fast_mode), AV_OPT_TYPE_BOOL, { .i64 = 0 },
--
2.30.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
2023-02-03 15:53 [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV Tomas Härdin
@ 2023-02-03 15:54 ` Tomas Härdin
2023-02-03 16:29 ` Pierre-Anthony Lemieux
2023-02-06 14:53 ` [FFmpeg-devel] [PATCH 2/2 v2] " Tomas Härdin
2023-02-13 10:14 ` [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV Tomas Härdin
1 sibling, 2 replies; 7+ messages in thread
From: Tomas Härdin @ 2023-02-03 15:54 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 127 bytes --]
We need something better for proper tonemap support, but this is at
least useful for getting the HDR discussion going.
/Tomas
[-- Attachment #2: 0002-lavfi-vf_colorspace-Add-SMPTE-ST-2084-support.patch --]
[-- Type: text/x-patch, Size: 3419 bytes --]
From fd7a789fbffdd0f7e41b77a9d70ae0696142c6db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Fri, 3 Feb 2023 14:00:38 +0100
Subject: [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
This makes 10000 nits == 65535 in 16-bit,
meaning SDR white is 65535*203/10000 = 1330.
---
libavfilter/vf_colorspace.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
index 1e1ab5fb34..081c1c9d0e 100644
--- a/libavfilter/vf_colorspace.c
+++ b/libavfilter/vf_colorspace.c
@@ -173,6 +173,7 @@ static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_N
[AVCOL_TRC_IEC61966_2_4] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
+ [AVCOL_TRC_SMPTE2084] = { 1.0, 0, 0, 0 }, // fake entry, actual TRC uses entirely separate formula
};
static const struct TransferCharacteristics *
@@ -197,6 +198,8 @@ static int fill_gamma_table(ColorSpaceContext *s)
double in_ialpha = 1.0 / in_alpha, in_igamma = 1.0 / in_gamma, in_idelta = 1.0 / in_delta;
double out_alpha = s->out_txchr->alpha, out_beta = s->out_txchr->beta;
double out_gamma = s->out_txchr->gamma, out_delta = s->out_txchr->delta;
+ double m1 = 1305.0/8192, m2 = 2523.0/32, c2 = 2413.0/128, c3 = 2392.0/128, c1 = c3 - c2 + 1;
+ double im1 = 1.0 / m1, im2 = 1.0 / m2;
s->lin_lut = av_malloc(sizeof(*s->lin_lut) * 32768 * 2);
if (!s->lin_lut)
@@ -206,7 +209,15 @@ static int fill_gamma_table(ColorSpaceContext *s)
double v = (n - 2048.0) / 28672.0, d, l;
// delinearize
- if (v <= -out_beta) {
+ if (s->out_trc == AVCOL_TRC_SMPTE2084) {
+ // see BT.2100-2
+ if (v >= 0) {
+ double vm1 = pow(v, m1);
+ d = pow((c1 + c2 * vm1)/(1 + c3 * vm1), m2);
+ } else {
+ d = 0;
+ }
+ } else if (v <= -out_beta) {
d = -out_alpha * pow(-v, out_gamma) + (out_alpha - 1.0);
} else if (v < out_beta) {
d = out_delta * v;
@@ -216,7 +227,16 @@ static int fill_gamma_table(ColorSpaceContext *s)
s->delin_lut[n] = av_clip_int16(lrint(d * 28672.0));
// linearize
- if (v <= -in_beta * in_delta) {
+ if (s->in_trc == AVCOL_TRC_SMPTE2084) {
+ // see BT.2100-2
+ if (v >= 0) {
+ double vim2 = pow(v, im2);
+ // note that [0,1] here corresponds to [0,100] in SDR
+ l = pow((vim2 - c1 > 0 ? vim2 - c1 : 0) / (c2 - c3 * vim2), im1);
+ } else {
+ l = 0;
+ }
+ } else if (v <= -in_beta * in_delta) {
l = -pow((1.0 - in_alpha - v) * in_ialpha, in_igamma);
} else if (v < in_beta * in_delta) {
l = v * in_idelta;
@@ -956,6 +976,7 @@ static const AVOption colorspace_options[] = {
ENUM("iec61966-2-4", AVCOL_TRC_IEC61966_2_4, "trc"),
ENUM("bt2020-10", AVCOL_TRC_BT2020_10, "trc"),
ENUM("bt2020-12", AVCOL_TRC_BT2020_12, "trc"),
+ ENUM("smpte2084", AVCOL_TRC_SMPTE2084, "trc"),
{ "format", "Output pixel format",
OFFSET(user_format), AV_OPT_TYPE_INT, { .i64 = AV_PIX_FMT_NONE },
--
2.30.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
2023-02-03 15:54 ` [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support Tomas Härdin
@ 2023-02-03 16:29 ` Pierre-Anthony Lemieux
2023-02-06 9:35 ` Tomas Härdin
2023-02-06 14:53 ` [FFmpeg-devel] [PATCH 2/2 v2] " Tomas Härdin
1 sibling, 1 reply; 7+ messages in thread
From: Pierre-Anthony Lemieux @ 2023-02-03 16:29 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, Feb 3, 2023 at 7:54 AM Tomas Härdin <git@haerdin.se> wrote:
>
> We need something better for proper tonemap support, but this is at
> least useful for getting the HDR discussion going.
Below is a demonstration of two tonemap methods:
https://www.sandflow.com/public/tone-mapping/index.html
>
> /Tomas
> _______________________________________________
> 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".
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
2023-02-03 16:29 ` Pierre-Anthony Lemieux
@ 2023-02-06 9:35 ` Tomas Härdin
2023-02-06 9:51 ` Tomas Härdin
0 siblings, 1 reply; 7+ messages in thread
From: Tomas Härdin @ 2023-02-06 9:35 UTC (permalink / raw)
To: FFmpeg development discussions and patches
fre 2023-02-03 klockan 08:29 -0800 skrev Pierre-Anthony Lemieux:
> On Fri, Feb 3, 2023 at 7:54 AM Tomas Härdin <git@haerdin.se> wrote:
> >
> > We need something better for proper tonemap support, but this is at
> > least useful for getting the HDR discussion going.
>
> Below is a demonstration of two tonemap methods:
>
> https://www.sandflow.com/public/tone-mapping/index.html
Does not work in Firefox. But it does work in Chromium. Looks like it
could be static images only.
Anyway what I feel bears discussion is whether we should add a field to
AVCodecContext like "nits" that says how many nits the max values of
integer pixel formats correspond to, and similarly for float formats
what 1.0 corresponds to. The latter is usually 203 cd/m² but is it
always? The link you posted appears to use 100 cd/m²:
> l_sdr = 100;
/Tomas
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
2023-02-06 9:35 ` Tomas Härdin
@ 2023-02-06 9:51 ` Tomas Härdin
0 siblings, 0 replies; 7+ messages in thread
From: Tomas Härdin @ 2023-02-06 9:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches
mån 2023-02-06 klockan 10:35 +0100 skrev Tomas Härdin:
> fre 2023-02-03 klockan 08:29 -0800 skrev Pierre-Anthony Lemieux:
> > On Fri, Feb 3, 2023 at 7:54 AM Tomas Härdin <git@haerdin.se> wrote:
> > >
> > > We need something better for proper tonemap support, but this is
> > > at
> > > least useful for getting the HDR discussion going.
> >
> > Below is a demonstration of two tonemap methods:
> >
> > https://www.sandflow.com/public/tone-mapping/index.html
>
> Does not work in Firefox. But it does work in Chromium. Looks like it
> could be static images only.
>
> Anyway what I feel bears discussion is whether we should add a field
> to
> AVCodecContext like "nits" that says how many nits the max values of
> integer pixel formats correspond to, and similarly for float formats
> what 1.0 corresponds to. The latter is usually 203 cd/m² but is it
> always? The link you posted appears to use 100 cd/m²:
>
> > l_sdr = 100;
Another thing: we probably need a float YUV format
/Tomas
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 2/2 v2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
2023-02-03 15:54 ` [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support Tomas Härdin
2023-02-03 16:29 ` Pierre-Anthony Lemieux
@ 2023-02-06 14:53 ` Tomas Härdin
1 sibling, 0 replies; 7+ messages in thread
From: Tomas Härdin @ 2023-02-06 14:53 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1: Type: text/plain, Size: 297 bytes --]
Here's a version of this patch with options for specifying input and
output nits. 32-bit LUTs would make this situation better if
vf_colorspace tracked nits internally. 32-bit would only be necessary
when dealing with HDR. That way SDR colorspace conversion can still use
the 16-bit SIMD.
/Tomas
[-- Attachment #2: 0002-lavfi-vf_colorspace-Add-SMPTE-ST-2084-support.patch --]
[-- Type: text/x-patch, Size: 7234 bytes --]
From c63beb4581bcd3140e122b7a7c5b4a53ae35ec29 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Fri, 3 Feb 2023 14:00:38 +0100
Subject: [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Also adds inits and onits options for specifying what 28672
means in terms of nits (cd/m²).
---
doc/filters.texi | 30 ++++++++++++++++++++++++++++
libavfilter/vf_colorspace.c | 39 +++++++++++++++++++++++++++++++++++--
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 3a54c68f3e..26d9dfe54b 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9839,6 +9839,10 @@ BT.2020 for 10-bits content
@item bt2020-12
BT.2020 for 12-bits content
+@anchor{smpte2084}
+@item smpte2084
+SMPTE ST 2084 (perceptual quantizer) used by BT.2100. See @ref{inits} and @ref{onits}.
+
@end table
@anchor{primaries}
@@ -9980,6 +9984,32 @@ Override input transfer characteristics. Same accepted values as @ref{trc}.
@item irange
Override input color range. Same accepted values as @ref{range}.
+@anchor{inits}
+@item inits
+Required when input trc is @ref{smpte2084}.
+Specifies what the peak intermediate level should correspond to in nits (cd/m²).
+Perceptually dequantized values get scaled and clipped so that the range [0,inits] fits in the filter's internal psuedo-restricted 15-bit format.
+For inits < 10000 this corresponds to clipping of values outside the [0,inits]³ RGB cube.
+For inits = 10000 values are not clipped, but values in the lower range will get truncated to zero due to the internal format's limited range.
+
+With BT.2100 input basic usage is:
+@example
+colorspace=bt709:inits=100
+@end example
+which clips HDR to SDR in BT.709 colorspace.
+
+A more advanced use case is as follows:
+@example
+colorspace=bt709:inits=10000:trc=linear:format=yuv444p16,tonemap=hable:peak=0.01
+@end example
+which with BT.2100 input performs very basic tonemapping.
+
+@anchor{onits}
+@item onits
+Used in combination with @ref{smpte2084}, defaults to 10000.
+Similar to @ref{inits} but in reverse.
+Specifies how to treat the peak intermediate level in nits (cd/m²) prior to perceptual quantization (PQ) as per SMPTE ST 2084.
+
@end table
The filter converts the transfer characteristics, color space and color
diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c
index 1e1ab5fb34..996c5f4e25 100644
--- a/libavfilter/vf_colorspace.c
+++ b/libavfilter/vf_colorspace.c
@@ -118,6 +118,7 @@ typedef struct ColorSpaceContext {
enum AVColorTransferCharacteristic in_trc, out_trc, user_trc, user_itrc;
enum AVColorPrimaries in_prm, out_prm, user_prm, user_iprm;
enum AVPixelFormat in_format, user_format;
+ double user_inits, user_onits;
int fast_mode;
enum DitherMode dither;
enum WhitepointAdaptation wp_adapt;
@@ -173,6 +174,7 @@ static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_N
[AVCOL_TRC_IEC61966_2_4] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_10] = { 1.099, 0.018, 0.45, 4.5 },
[AVCOL_TRC_BT2020_12] = { 1.0993, 0.0181, 0.45, 4.5 },
+ [AVCOL_TRC_SMPTE2084] = { 1.0, 0, 0, 0 }, // fake entry, actual TRC uses entirely separate formula
};
static const struct TransferCharacteristics *
@@ -197,6 +199,9 @@ static int fill_gamma_table(ColorSpaceContext *s)
double in_ialpha = 1.0 / in_alpha, in_igamma = 1.0 / in_gamma, in_idelta = 1.0 / in_delta;
double out_alpha = s->out_txchr->alpha, out_beta = s->out_txchr->beta;
double out_gamma = s->out_txchr->gamma, out_delta = s->out_txchr->delta;
+ double m1 = 1305.0/8192, m2 = 2523.0/32, c2 = 2413.0/128, c3 = 2392.0/128, c1 = c3 - c2 + 1;
+ double im1 = 1.0 / m1, im2 = 1.0 / m2;
+ double iscale = 10000.0 / s->user_inits, ioscale = s->user_onits / 10000.0;
s->lin_lut = av_malloc(sizeof(*s->lin_lut) * 32768 * 2);
if (!s->lin_lut)
@@ -206,7 +211,15 @@ static int fill_gamma_table(ColorSpaceContext *s)
double v = (n - 2048.0) / 28672.0, d, l;
// delinearize
- if (v <= -out_beta) {
+ if (s->out_trc == AVCOL_TRC_SMPTE2084) {
+ // see BT.2100-2
+ if (v >= 0) {
+ double vm1 = pow(v * ioscale, m1);
+ d = pow((c1 + c2 * vm1)/(1 + c3 * vm1), m2);
+ } else {
+ d = 0;
+ }
+ } else if (v <= -out_beta) {
d = -out_alpha * pow(-v, out_gamma) + (out_alpha - 1.0);
} else if (v < out_beta) {
d = out_delta * v;
@@ -216,7 +229,19 @@ static int fill_gamma_table(ColorSpaceContext *s)
s->delin_lut[n] = av_clip_int16(lrint(d * 28672.0));
// linearize
- if (v <= -in_beta * in_delta) {
+ if (s->in_trc == AVCOL_TRC_SMPTE2084) {
+ // see BT.2100-2
+ if (v >= 0) {
+ double vim2 = pow(v, im2);
+ // for inits < 10000 this will tonemap by clipping in RGB
+ // for inits = 10000 this makes unclipped linear values accessible when trc=linear
+ // note that precision will be lost in the lower end of PQ values, for example with
+ // 12-bit PQ and 16-bit output the first 422 values all get truncated to zero
+ l = iscale * pow((vim2 - c1 > 0 ? vim2 - c1 : 0) / (c2 - c3 * vim2), im1);
+ } else {
+ l = 0;
+ }
+ } else if (v <= -in_beta * in_delta) {
l = -pow((1.0 - in_alpha - v) * in_ialpha, in_igamma);
} else if (v < in_beta * in_delta) {
l = v * in_idelta;
@@ -514,6 +539,11 @@ static int create_filtergraph(AVFilterContext *ctx,
}
}
+ if (s->in_trc == AVCOL_TRC_SMPTE2084 && s->user_inits <= 0) {
+ av_log(ctx, AV_LOG_ERROR, "smpte2084 requires inits\n");
+ return AVERROR(EINVAL);
+ }
+
if (!s->out_txchr) {
av_freep(&s->lin_lut);
s->out_trc = out->color_trc;
@@ -956,6 +986,7 @@ static const AVOption colorspace_options[] = {
ENUM("iec61966-2-4", AVCOL_TRC_IEC61966_2_4, "trc"),
ENUM("bt2020-10", AVCOL_TRC_BT2020_10, "trc"),
ENUM("bt2020-12", AVCOL_TRC_BT2020_12, "trc"),
+ ENUM("smpte2084", AVCOL_TRC_SMPTE2084, "trc"),
{ "format", "Output pixel format",
OFFSET(user_format), AV_OPT_TYPE_INT, { .i64 = AV_PIX_FMT_NONE },
@@ -1008,6 +1039,10 @@ static const AVOption colorspace_options[] = {
{ "itrc", "Input transfer characteristics",
OFFSET(user_itrc), AV_OPT_TYPE_INT, { .i64 = AVCOL_TRC_UNSPECIFIED },
AVCOL_TRC_RESERVED0, AVCOL_TRC_NB - 1, FLAGS, "trc" },
+ { "inits", "Input nits. Specifies how PQ (SMPTE ST 2084) values are to be mapped to intermediate/output linear RGB",
+ OFFSET(user_inits), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, 10000, FLAGS },
+ { "onits", "Output nits. Specifies how input/intermediate linear RGB is scaled for output PQ (SMPTE ST 2084) values",
+ OFFSET(user_onits), AV_OPT_TYPE_DOUBLE, {.dbl = 10000}, 1, 10000, FLAGS },
{ NULL }
};
--
2.30.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV
2023-02-03 15:53 [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV Tomas Härdin
2023-02-03 15:54 ` [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support Tomas Härdin
@ 2023-02-13 10:14 ` Tomas Härdin
1 sibling, 0 replies; 7+ messages in thread
From: Tomas Härdin @ 2023-02-13 10:14 UTC (permalink / raw)
To: FFmpeg development discussions and patches
We've had some discussion on IRC about how to get tonemap support into
vf_colorspace and converting from/to PQ (and maybe HLG) and 31-bit
intermediate values. If that is done then the second patch in this set
becomes superfluous. But I'd still like to see this patch (1/2) pushed
if no one objects since it just adds more pixel formats. SIMD can come
later.
/Tomas
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-02-13 10:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-03 15:53 [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV Tomas Härdin
2023-02-03 15:54 ` [FFmpeg-devel] [PATCH 2/2] lavfi/vf_colorspace: Add SMPTE ST 2084 support Tomas Härdin
2023-02-03 16:29 ` Pierre-Anthony Lemieux
2023-02-06 9:35 ` Tomas Härdin
2023-02-06 9:51 ` Tomas Härdin
2023-02-06 14:53 ` [FFmpeg-devel] [PATCH 2/2 v2] " Tomas Härdin
2023-02-13 10:14 ` [FFmpeg-devel] [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV Tomas Härdin
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