* [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ
@ 2023-04-01 17:47 Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 2/3] lavfi/vf_ssim: " Chema Gonzalez
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Chema Gonzalez @ 2023-04-01 17:47 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chema Gonzalez
The PSNR filter uses the pixel values without considering
the color ranges. This is incorrect. Patch adds a warning
so at least the user knows it.
Let's see an example:
(1) Let's get a simple black pixel/white pixel image.
```
$ echo -n -e "\x00\x00\x00\xff\xff\xff" > /tmp/foo.rgb24
```
(2) From this image, let's distill full and limited range y4m
copies.
```
$ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=full" -pix_fmt yuv420p /tmp/foo.full.y4m
$ xxd /tmp/foo.full.y4m
00000000: 5955 5634 4d50 4547 3220 5732 2048 3120 YUV4MPEG2 W2 H1
00000010: 4632 353a 3120 4970 2041 303a 3020 4334 F25:1 Ip A0:0 C4
00000020: 3230 6a70 6567 2058 5953 4353 533d 3432 20jpeg XYSCSS=42
00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47 0JPEG XCOLORRANG
00000040: 453d 4655 4c4c 0a46 5241 4d45 0a00 ff80 E=FULL.FRAME....
00000050: 80 .
```
and
```
$ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/foo.limited.y4m
$ xxd /tmp/foo.limited.y4m
00000000: 5955 5634 4d50 4547 3220 5732 2048 3120 YUV4MPEG2 W2 H1
00000010: 4632 353a 3120 4970 2041 303a 3020 4334 F25:1 Ip A0:0 C4
00000020: 3230 6a70 6567 2058 5953 4353 533d 3432 20jpeg XYSCSS=42
00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47 0JPEG XCOLORRANG
00000040: 453d 4c49 4d49 5445 440a 4652 414d 450a E=LIMITED.FRAME.
00000050: 10eb 8080 ....
```
Note that the 2x images are the same (both have 1x pixel at the
darkest black, and one at the brightest white). Only difference
is the range.
(3) Let's calculate the PSNR score:
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null -
...
[Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365
```
As we are comparing an image with itself, we expect "y:inf" as the
luma PSNR. Issue here is that the PSNR filter just uses the pixel
values, ignoring the color ranges.
A possible solution would be to have the filter do the conversion.
Proposed solution is to add a warning.
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null -
...
[Parsed_psnr_0 @ 0x2f5dac0] master and reference frames use different color ranges (pc != tv)
...
[Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365
```
Tested:
Ran fate.
```
$ make fate -j
...
TEST seek-lavf-ppmpipe
TEST seek-lavf-pgmpipe
TEST seek-lavf-mxf_opatom
```
---
libavfilter/vf_psnr.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c
index 15cde7e8c8..058a8932f4 100644
--- a/libavfilter/vf_psnr.c
+++ b/libavfilter/vf_psnr.c
@@ -188,6 +188,13 @@ static int do_psnr(FFFrameSync *fs)
td.planeheight[c] = s->planeheight[c];
}
+ if (master->color_range != ref->color_range) {
+ av_log(ctx, AV_LOG_WARNING, "master and reference "
+ "frames use different color ranges (%s != %s)\n",
+ av_color_range_name(master->color_range),
+ av_color_range_name(ref->color_range));
+ }
+
ff_filter_execute(ctx, compute_images_mse, &td, NULL,
FFMIN(s->planeheight[1], s->nb_threads));
--
2.39.2
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 2/3] lavfi/vf_ssim: add warning when color ranges differ
2023-04-01 17:47 [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ Chema Gonzalez
@ 2023-04-01 17:47 ` Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: " Chema Gonzalez
2023-09-23 14:54 ` [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: " Niklas Haas
2 siblings, 0 replies; 8+ messages in thread
From: Chema Gonzalez @ 2023-04-01 17:47 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chema Gonzalez
The SSIM filter uses the pixel values without considering
the color ranges. This is incorrect. Patch adds a warning
so at least the user knows it.
Let's see an example.
(1) Let's get FR and LR versions of the same image.
```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=full" -pix_fmt yuv420p /tmp/lena.full.y4m
$ xxd /tmp/lena.full.y4m |head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4655 4c4c 0a46 5241 4d45 RANGE=FULL.FRAME
00000050: 0a72 7271 7070 706f 6f6e 6d6d 6c6d 6d6d .rrqpppoonmmlmmm
00000060: 6c6e 6e6d 6d6e 6e6e 6d6c 6d6d 6d6d 6d6d lnnmmnnnmlmmmmmm
00000070: 6d6e 6d6b 6c6d 6e6e 6d6c 6d6d 6e6e 6f6f mnmklmnnmlmmnnoo
00000080: 6f6f 6e6e 6e6e 6f70 7172 7375 7676 7370 oonnnnopqrsuvvsp
00000090: 6d69 6662 5e59 534d 4845 3d35 302e 2d2c mifb^YSMHE=50.-,
```
```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/lena.limited.y4m
$ xxd /tmp/lena.limited.y4m | head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4c49 4d49 5445 440a 4652 RANGE=LIMITED.FR
00000050: 414d 450a 7272 7170 7070 6f6f 6e6e 6e6d AME.rrqpppoonnnm
00000060: 6e6e 6e6d 6f6e 6e6e 6e6e 6e6e 6d6e 6e6e nnnmonnnnnnnmnnn
00000070: 6e6e 6e6e 6f6e 6c6d 6e6f 6e6e 6d6e 6e6f nnnnonlmnonnmnno
00000080: 6f6f 6f6f 6f6f 6f6f 6f6f 7071 7273 7576 oooooooooopqrsuv
00000090: 7673 706e 6a68 6461 5c57 524e 4b44 3d39 vspnjhda\WRNKD=9
```
Note that the 2x images are the same. Only difference is the range,
and the precision issues related to range conversion.
(2) Let's calculate the SSIM score:
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi "ssim" -f null -
...
[Parsed_ssim_0 @ 0x360ab00] SSIM Y:0.942347 (12.391801) U:0.995808 (23.776062) V:0.996104 (24.093747) All:0.960217 (14.003012)
```
As we are comparing an image with itself, we expect "Y: 1" as the
luma SSIM. Issue here is that the SSIM filter just uses the pixel
values, ignoring the color ranges.
Proposed solution is to add a warning.
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "ssim" -f null -
...
[Parsed_ssim_0 @ 0x3766280] master and reference frames use different color ranges (pc != tv)
...
[Parsed_ssim_0 @ 0x3766280] SSIM Y:0.000000 (0.000000) U:0.000000 (0.000000) V:0.000000 (0.000000) All:0.000000 (0.000000)
```
Tested:
Ran fate.
```
$ make fate -j
...
TEST seek-lavf-ppmpipe
TEST seek-lavf-pgmpipe
TEST seek-lavf-mxf_opatom
```
---
libavfilter/vf_ssim.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libavfilter/vf_ssim.c b/libavfilter/vf_ssim.c
index 1933b9b82d..53eb72fe6a 100644
--- a/libavfilter/vf_ssim.c
+++ b/libavfilter/vf_ssim.c
@@ -358,6 +358,13 @@ static int do_ssim(FFFrameSync *fs)
td.planeheight[n] = s->planeheight[n];
}
+ if (master->color_range != ref->color_range) {
+ av_log(ctx, AV_LOG_WARNING, "master and reference "
+ "frames use different color ranges (%s != %s)\n",
+ av_color_range_name(master->color_range),
+ av_color_range_name(ref->color_range));
+ }
+
ff_filter_execute(ctx, s->ssim_plane, &td, NULL,
FFMIN((s->planeheight[1] + 3) >> 2, s->nb_threads));
--
2.39.2
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ
2023-04-01 17:47 [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 2/3] lavfi/vf_ssim: " Chema Gonzalez
@ 2023-04-01 17:47 ` Chema Gonzalez
2023-04-17 19:09 ` Kyle Swanson
2023-09-23 14:54 ` [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: " Niklas Haas
2 siblings, 1 reply; 8+ messages in thread
From: Chema Gonzalez @ 2023-04-01 17:47 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chema Gonzalez
The VMAF filter uses the pixel values without considering
the color ranges. This is incorrect. Patch adds a warning
so at least the user knows it.
Let's see an example.
(1) Let's get FR and LR versions of the same image.
```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=full" -pix_fmt yuv420p /tmp/lena.full.y4m
$ xxd /tmp/lena.full.y4m |head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4655 4c4c 0a46 5241 4d45 RANGE=FULL.FRAME
00000050: 0a72 7271 7070 706f 6f6e 6d6d 6c6d 6d6d .rrqpppoonmmlmmm
00000060: 6c6e 6e6d 6d6e 6e6e 6d6c 6d6d 6d6d 6d6d lnnmmnnnmlmmmmmm
00000070: 6d6e 6d6b 6c6d 6e6e 6d6c 6d6d 6e6e 6f6f mnmklmnnmlmmnnoo
00000080: 6f6f 6e6e 6e6e 6f70 7172 7375 7676 7370 oonnnnopqrsuvvsp
00000090: 6d69 6662 5e59 534d 4845 3d35 302e 2d2c mifb^YSMHE=50.-,
```
```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/lena.limited.y4m
$ xxd /tmp/lena.limited.y4m | head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4c49 4d49 5445 440a 4652 RANGE=LIMITED.FR
00000050: 414d 450a 7272 7170 7070 6f6f 6e6e 6e6d AME.rrqpppoonnnm
00000060: 6e6e 6e6d 6f6e 6e6e 6e6e 6e6e 6d6e 6e6e nnnmonnnnnnnmnnn
00000070: 6e6e 6e6e 6f6e 6c6d 6e6f 6e6e 6d6e 6e6f nnnnonlmnonnmnno
00000080: 6f6f 6f6f 6f6f 6f6f 6f6f 7071 7273 7576 oooooooooopqrsuv
00000090: 7673 706e 6a68 6461 5c57 524e 4b44 3d39 vspnjhda\WRNKD=9
```
Note that the 2x images are the same. Only difference is the range,
and the precision issues related to range conversion.
(2) Let's calculate the VMAF score:
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/usr/share/model/vmaf_v0.6.1neg.json" -report -f null -
...
[Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109
```
As we are comparing an image with itself, we expect the score to
be close to 100. Issue here is that the VMAF filter just uses the
pixel values, ignoring the color ranges.
Proposed solution is to add a warning.
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/us
r/share/model/vmaf_v0.6.1neg.json" -report -f null -
...
[Parsed_libvmaf_0 @ 0x3cc9b40] distorted and reference frames use different color ranges (pc != tv)
...
[Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109
```
Tested:
Ran fate.
```
$ make fate -j
...
TEST seek-lavf-ppmpipe
TEST seek-lavf-pgmpipe
TEST seek-lavf-mxf_opatom
```
---
libavfilter/vf_libvmaf.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
index 2586f37d99..67f0d6a22f 100644
--- a/libavfilter/vf_libvmaf.c
+++ b/libavfilter/vf_libvmaf.c
@@ -141,6 +141,13 @@ static int do_vmaf(FFFrameSync *fs)
if (ctx->is_disabled || !ref)
return ff_filter_frame(ctx->outputs[0], dist);
+ if (dist->color_range != ref->color_range) {
+ av_log(ctx, AV_LOG_WARNING, "distorted and reference "
+ "frames use different color ranges (%s != %s)\n",
+ av_color_range_name(dist->color_range),
+ av_color_range_name(ref->color_range));
+ }
+
err = copy_picture_data(ref, &pic_ref, s->bpc);
if (err) {
av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n");
--
2.39.2
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: " Chema Gonzalez
@ 2023-04-17 19:09 ` Kyle Swanson
2023-04-17 21:14 ` Chema Gonzalez
0 siblings, 1 reply; 8+ messages in thread
From: Kyle Swanson @ 2023-04-17 19:09 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Chema Gonzalez
Hi,
I think the warning is probably OK, but maybe better to put it into
config_input_ref along with the other input checks.
On Sat, Apr 1, 2023 at 10:48 AM Chema Gonzalez <chemag@gmail.com> wrote:
> ---
> libavfilter/vf_libvmaf.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
> index 2586f37d99..67f0d6a22f 100644
> --- a/libavfilter/vf_libvmaf.c
> +++ b/libavfilter/vf_libvmaf.c
> @@ -141,6 +141,13 @@ static int do_vmaf(FFFrameSync *fs)
> if (ctx->is_disabled || !ref)
> return ff_filter_frame(ctx->outputs[0], dist);
>
> + if (dist->color_range != ref->color_range) {
> + av_log(ctx, AV_LOG_WARNING, "distorted and reference "
> + "frames use different color ranges (%s != %s)\n",
> + av_color_range_name(dist->color_range),
> + av_color_range_name(ref->color_range));
> + }
> +
> err = copy_picture_data(ref, &pic_ref, s->bpc);
> if (err) {
> av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n");
> --
> 2.39.2
>
Thanks,
Kyle
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ
2023-04-17 19:09 ` Kyle Swanson
@ 2023-04-17 21:14 ` Chema Gonzalez
2023-09-23 14:55 ` Kyle Swanson
0 siblings, 1 reply; 8+ messages in thread
From: Chema Gonzalez @ 2023-04-17 21:14 UTC (permalink / raw)
To: Kyle Swanson; +Cc: FFmpeg development discussions and patches
Hi Kyle,
Thanks for your answer.
I couldn't find how to access the color range from the filter_frame
function. I checked other filters that access `AVFrame.color_range`,
and all of them do it in the filter_frame function, not in the
config_props one. This includes vf_blackdetect.c, vf_iccgen.c,
vf_libplacebo.c, vf_premultiply.c, vf_scale.c, and vf_scale_vaapi.c.
Thanks again,
-Chema
On Mon, Apr 17, 2023 at 12:09 PM Kyle Swanson <k@ylo.ph> wrote:
>
> Hi,
>
> I think the warning is probably OK, but maybe better to put it into config_input_ref along with the other input checks.
>
> On Sat, Apr 1, 2023 at 10:48 AM Chema Gonzalez <chemag@gmail.com> wrote:
>>
>> ---
>> libavfilter/vf_libvmaf.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
>> index 2586f37d99..67f0d6a22f 100644
>> --- a/libavfilter/vf_libvmaf.c
>> +++ b/libavfilter/vf_libvmaf.c
>> @@ -141,6 +141,13 @@ static int do_vmaf(FFFrameSync *fs)
>> if (ctx->is_disabled || !ref)
>> return ff_filter_frame(ctx->outputs[0], dist);
>>
>> + if (dist->color_range != ref->color_range) {
>> + av_log(ctx, AV_LOG_WARNING, "distorted and reference "
>> + "frames use different color ranges (%s != %s)\n",
>> + av_color_range_name(dist->color_range),
>> + av_color_range_name(ref->color_range));
>> + }
>> +
>> err = copy_picture_data(ref, &pic_ref, s->bpc);
>> if (err) {
>> av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n");
>> --
>> 2.39.2
>
>
> Thanks,
> Kyle
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ
2023-04-17 21:14 ` Chema Gonzalez
@ 2023-09-23 14:55 ` Kyle Swanson
0 siblings, 0 replies; 8+ messages in thread
From: Kyle Swanson @ 2023-09-23 14:55 UTC (permalink / raw)
To: Chema Gonzalez; +Cc: FFmpeg development discussions and patches
Hi,
On Mon, Apr 17, 2023 at 10:14 PM Chema Gonzalez <chema@berkeley.edu> wrote:
> Hi Kyle,
>
> Thanks for your answer.
>
> I couldn't find how to access the color range from the filter_frame
> function. I checked other filters that access `AVFrame.color_range`,
> and all of them do it in the filter_frame function, not in the
> config_props one. This includes vf_blackdetect.c, vf_iccgen.c,
> vf_libplacebo.c, vf_premultiply.c, vf_scale.c, and vf_scale_vaapi.c.
>
> Thanks again,
> -Chema
>
Went over this at VDD, haasn will push the patch.
Thanks,
Kyle
_______________________________________________
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] 8+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ
2023-04-01 17:47 [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 2/3] lavfi/vf_ssim: " Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: " Chema Gonzalez
@ 2023-09-23 14:54 ` Niklas Haas
2 siblings, 0 replies; 8+ messages in thread
From: Niklas Haas @ 2023-09-23 14:54 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chema Gonzalez
On Sat, 01 Apr 2023 10:47:35 -0700 Chema Gonzalez <chemag@gmail.com> wrote:
> The PSNR filter uses the pixel values without considering
> the color ranges. This is incorrect. Patch adds a warning
> so at least the user knows it.
>
> Let's see an example:
>
> (1) Let's get a simple black pixel/white pixel image.
> ```
> $ echo -n -e "\x00\x00\x00\xff\xff\xff" > /tmp/foo.rgb24
> ```
>
> (2) From this image, let's distill full and limited range y4m
> copies.
>
> ```
> $ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=full" -pix_fmt yuv420p /tmp/foo.full.y4m
> $ xxd /tmp/foo.full.y4m
> 00000000: 5955 5634 4d50 4547 3220 5732 2048 3120 YUV4MPEG2 W2 H1
> 00000010: 4632 353a 3120 4970 2041 303a 3020 4334 F25:1 Ip A0:0 C4
> 00000020: 3230 6a70 6567 2058 5953 4353 533d 3432 20jpeg XYSCSS=42
> 00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47 0JPEG XCOLORRANG
> 00000040: 453d 4655 4c4c 0a46 5241 4d45 0a00 ff80 E=FULL.FRAME....
> 00000050: 80 .
> ```
>
> and
>
> ```
> $ ffmpeg -y -f rawvideo -video_size 2x1 -pix_fmt rgb24 -i /tmp/foo.rgb24 -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/foo.limited.y4m
> $ xxd /tmp/foo.limited.y4m
> 00000000: 5955 5634 4d50 4547 3220 5732 2048 3120 YUV4MPEG2 W2 H1
> 00000010: 4632 353a 3120 4970 2041 303a 3020 4334 F25:1 Ip A0:0 C4
> 00000020: 3230 6a70 6567 2058 5953 4353 533d 3432 20jpeg XYSCSS=42
> 00000030: 304a 5045 4720 5843 4f4c 4f52 5241 4e47 0JPEG XCOLORRANG
> 00000040: 453d 4c49 4d49 5445 440a 4652 414d 450a E=LIMITED.FRAME.
> 00000050: 10eb 8080 ....
> ```
>
> Note that the 2x images are the same (both have 1x pixel at the
> darkest black, and one at the brightest white). Only difference
> is the range.
>
> (3) Let's calculate the PSNR score:
> ```
> $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null -
> ...
> [Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365
> ```
>
> As we are comparing an image with itself, we expect "y:inf" as the
> luma PSNR. Issue here is that the PSNR filter just uses the pixel
> values, ignoring the color ranges.
>
> A possible solution would be to have the filter do the conversion.
>
> Proposed solution is to add a warning.
>
> ```
> $ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/foo.full.y4m -i /tmp/foo.limited.y4m -lavfi "psnr" -f null -
> ...
> [Parsed_psnr_0 @ 0x2f5dac0] master and reference frames use different color ranges (pc != tv)
> ...
> [Parsed_psnr_0 @ 0x2f5dac0] PSNR y:22.972065 u:inf v:inf average:25.982365 min:25.982365 max:25.982365
> ```
>
> Tested:
>
> Ran fate.
> ```
> $ make fate -j
> ...
> TEST seek-lavf-ppmpipe
> TEST seek-lavf-pgmpipe
> TEST seek-lavf-mxf_opatom
> ```
> ---
> libavfilter/vf_psnr.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c
> index 15cde7e8c8..058a8932f4 100644
> --- a/libavfilter/vf_psnr.c
> +++ b/libavfilter/vf_psnr.c
> @@ -188,6 +188,13 @@ static int do_psnr(FFFrameSync *fs)
> td.planeheight[c] = s->planeheight[c];
> }
>
> + if (master->color_range != ref->color_range) {
> + av_log(ctx, AV_LOG_WARNING, "master and reference "
> + "frames use different color ranges (%s != %s)\n",
> + av_color_range_name(master->color_range),
> + av_color_range_name(ref->color_range));
> + }
> +
> ff_filter_execute(ctx, compute_images_mse, &td, NULL,
> FFMIN(s->planeheight[1], s->nb_threads));
>
> --
> 2.39.2
>
> _______________________________________________
> 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".
LGTM.
The warning will probably be removed once filter graph color range negotiation
exists.
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 0/3] add warnings to quality metrics on color range mistmatch
@ 2023-03-31 16:49 Chema Gonzalez
2023-03-31 16:49 ` [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ Chema Gonzalez
0 siblings, 1 reply; 8+ messages in thread
From: Chema Gonzalez @ 2023-03-31 16:49 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chema Gonzalez
Quality metrics just use raw buffers, without considering
whether they are full-range or limited-range. This causes
scores to lower in a significative manner.
Chema Gonzalez (3):
lavfi/vf_psnr: add warning when color ranges differ
lavfi/vf_ssim: add warning when color ranges differ
lavfi/vf_libvmaf: add warning when color ranges differ
libavfilter/vf_libvmaf.c | 7 +++++++
libavfilter/vf_psnr.c | 7 +++++++
libavfilter/vf_ssim.c | 7 +++++++
3 files changed, 21 insertions(+)
--
2.39.2
_______________________________________________
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] 8+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ
2023-03-31 16:49 [FFmpeg-devel] [PATCH 0/3] add warnings to quality metrics on color range mistmatch Chema Gonzalez
@ 2023-03-31 16:49 ` Chema Gonzalez
0 siblings, 0 replies; 8+ messages in thread
From: Chema Gonzalez @ 2023-03-31 16:49 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Chema Gonzalez
The VMAF filter uses the pixel values without considering
the color ranges. This is incorrect. Patch adds a warning
so at least the user knows it.
Let's see an example.
(1) Let's get FR and LR versions of the same image.
```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=full" -pix_fmt yuv420p /tmp/lena.full.y4m
$ xxd /tmp/lena.full.y4m |head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4655 4c4c 0a46 5241 4d45 RANGE=FULL.FRAME
00000050: 0a72 7271 7070 706f 6f6e 6d6d 6c6d 6d6d .rrqpppoonmmlmmm
00000060: 6c6e 6e6d 6d6e 6e6e 6d6c 6d6d 6d6d 6d6d lnnmmnnnmlmmmmmm
00000070: 6d6e 6d6b 6c6d 6e6e 6d6c 6d6d 6e6e 6f6f mnmklmnnmlmmnnoo
00000080: 6f6f 6e6e 6e6e 6f70 7172 7375 7676 7370 oonnnnopqrsuvvsp
00000090: 6d69 6662 5e59 534d 4845 3d35 302e 2d2c mifb^YSMHE=50.-,
```
```
$ ffmpeg -y -i /tmp/lena.490x490.ppm -vf scale="out_range=limited" -pix_fmt yuv420p /tmp/lena.limited.y4m
$ xxd /tmp/lena.limited.y4m | head
00000000: 5955 5634 4d50 4547 3220 5734 3930 2048 YUV4MPEG2 W490 H
00000010: 3439 3020 4632 353a 3120 4970 2041 303a 490 F25:1 Ip A0:
00000020: 3020 4334 3230 6a70 6567 2058 5953 4353 0 C420jpeg XYSCS
00000030: 533d 3432 304a 5045 4720 5843 4f4c 4f52 S=420JPEG XCOLOR
00000040: 5241 4e47 453d 4c49 4d49 5445 440a 4652 RANGE=LIMITED.FR
00000050: 414d 450a 7272 7170 7070 6f6f 6e6e 6e6d AME.rrqpppoonnnm
00000060: 6e6e 6e6d 6f6e 6e6e 6e6e 6e6e 6d6e 6e6e nnnmonnnnnnnmnnn
00000070: 6e6e 6e6e 6f6e 6c6d 6e6f 6e6e 6d6e 6e6f nnnnonlmnonnmnno
00000080: 6f6f 6f6f 6f6f 6f6f 6f6f 7071 7273 7576 oooooooooopqrsuv
00000090: 7673 706e 6a68 6461 5c57 524e 4b44 3d39 vspnjhda\WRNKD=9
```
Note that the 2x images are the same. Only difference is the range,
and the precision issues related to range conversion.
(2) Let's calculate the VMAF score:
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/usr/share/model/vmaf_v0.6.1neg.json" -report -f null -
...
[Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109
```
As we are comparing an image with itself, we expect the score to
be close to 100. Issue here is that the VMAF filter just uses the
pixel values, ignoring the color ranges.
Proposed solution is to add a warning.
```
$ ./ffmpeg -filter_threads 1 -filter_complex_threads 1 -i /tmp/lena.full.y4m -i /tmp/lena.limited.y4m -lavfi libvmaf="model=path=/us
r/share/model/vmaf_v0.6.1neg.json" -report -f null -
...
[Parsed_libvmaf_0 @ 0x3cc9b40] Warning: distorted and reference frames use different color ranges (pc != tv)
...
[Parsed_libvmaf_0 @ 0x3cc9b40] VMAF score: 85.530109
```
Tested:
Ran fate.
```
$ make fate -j
...
TEST seek-lavf-ppmpipe
TEST seek-lavf-pgmpipe
TEST seek-lavf-mxf_opatom
```
---
libavfilter/vf_libvmaf.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
index 2586f37d99..d330658abb 100644
--- a/libavfilter/vf_libvmaf.c
+++ b/libavfilter/vf_libvmaf.c
@@ -141,6 +141,13 @@ static int do_vmaf(FFFrameSync *fs)
if (ctx->is_disabled || !ref)
return ff_filter_frame(ctx->outputs[0], dist);
+ if (dist->color_range != ref->color_range) {
+ av_log(ctx, AV_LOG_WARNING, "Warning: distorted and reference "
+ "frames use different color ranges (%s != %s)\n",
+ av_color_range_name(dist->color_range),
+ av_color_range_name(ref->color_range));
+ }
+
err = copy_picture_data(ref, &pic_ref, s->bpc);
if (err) {
av_log(s, AV_LOG_ERROR, "problem during vmaf_picture_alloc.\n");
--
2.39.2
_______________________________________________
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] 8+ messages in thread
end of thread, other threads:[~2023-09-23 14:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01 17:47 [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: add warning when color ranges differ Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 2/3] lavfi/vf_ssim: " Chema Gonzalez
2023-04-01 17:47 ` [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: " Chema Gonzalez
2023-04-17 19:09 ` Kyle Swanson
2023-04-17 21:14 ` Chema Gonzalez
2023-09-23 14:55 ` Kyle Swanson
2023-09-23 14:54 ` [FFmpeg-devel] [PATCH 1/3] lavfi/vf_psnr: " Niklas Haas
-- strict thread matches above, loose matches on Subject: below --
2023-03-31 16:49 [FFmpeg-devel] [PATCH 0/3] add warnings to quality metrics on color range mistmatch Chema Gonzalez
2023-03-31 16:49 ` [FFmpeg-devel] [PATCH 3/3] lavfi/vf_libvmaf: add warning when color ranges differ Chema Gonzalez
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