diff mbox series

[FFmpeg-devel] avfilter/vf_scale: reset color matrix in case of identity & non-RGB

Message ID 20210822205542.16631-1-jeebjp@gmail.com
State Accepted
Commit 9dd410c80416197188337e3b7e1600be41d2ea64
Headers show
Series [FFmpeg-devel] avfilter/vf_scale: reset color matrix in case of identity & non-RGB
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Jan Ekström Aug. 22, 2021, 8:55 p.m. UTC
Fixes passing through mismatching metadata from the input side
when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.

Fixes #9132
---
 libavfilter/vf_scale.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Jan Ekström Aug. 26, 2021, 10:02 p.m. UTC | #1
On Sun, Aug 22, 2021 at 11:55 PM Jan Ekström <jeebjp@gmail.com> wrote:
>
> Fixes passing through mismatching metadata from the input side
> when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.
>
> Fixes #9132
> ---
>  libavfilter/vf_scale.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index ce39217515..7ca833bbb1 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -738,6 +738,15 @@ scale:
>      out->width  = outlink->w;
>      out->height = outlink->h;
>
> +    // Sanity check: If we've got the RGB/XYZ (identity) matrix configured, and
> +    //               the output is no longer RGB, unset the matrix.
> +    //               In theory this should be in swscale itself as the AVFrame
> +    //               based API gets in, so that not every swscale API user has
> +    //               to go through duplicating such sanity checks.
> +    if (out->colorspace == AVCOL_SPC_RGB &&
> +        !(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
> +        out->colorspace = AVCOL_SPC_UNSPECIFIED;
> +
>      if (scale->output_is_pal)
>          avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
>
> --
> 2.31.1
>

Unless there are objections, I will pull this in soon. I will also
attempt to see if I can add a programmatic FATE test for all of the
allowed configurations of vf_scale, to see if there are any other
clear-cut cases where not all metadata from the input AVFrame can be
passed on as-is and has to be reset.

Jan
Michael Niedermayer Aug. 27, 2021, 9:03 p.m. UTC | #2
On Fri, Aug 27, 2021 at 01:02:31AM +0300, Jan Ekström wrote:
> On Sun, Aug 22, 2021 at 11:55 PM Jan Ekström <jeebjp@gmail.com> wrote:
> >
> > Fixes passing through mismatching metadata from the input side
> > when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.
> >
> > Fixes #9132
> > ---
> >  libavfilter/vf_scale.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> > index ce39217515..7ca833bbb1 100644
> > --- a/libavfilter/vf_scale.c
> > +++ b/libavfilter/vf_scale.c
> > @@ -738,6 +738,15 @@ scale:
> >      out->width  = outlink->w;
> >      out->height = outlink->h;
> >
> > +    // Sanity check: If we've got the RGB/XYZ (identity) matrix configured, and
> > +    //               the output is no longer RGB, unset the matrix.
> > +    //               In theory this should be in swscale itself as the AVFrame
> > +    //               based API gets in, so that not every swscale API user has
> > +    //               to go through duplicating such sanity checks.
> > +    if (out->colorspace == AVCOL_SPC_RGB &&
> > +        !(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
> > +        out->colorspace = AVCOL_SPC_UNSPECIFIED;
> > +
> >      if (scale->output_is_pal)
> >          avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
> >
> > --
> > 2.31.1
> >
> 
> Unless there are objections, I will pull this in soon. I will also
> attempt to see if I can add a programmatic FATE test for all of the
> allowed configurations of vf_scale, to see if there are any other
> clear-cut cases where not all metadata from the input AVFrame can be
> passed on as-is and has to be reset.

no objections

thx

[...]
Jan Ekström Aug. 27, 2021, 10:47 p.m. UTC | #3
On Sat, Aug 28, 2021 at 12:03 AM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Fri, Aug 27, 2021 at 01:02:31AM +0300, Jan Ekström wrote:
> > On Sun, Aug 22, 2021 at 11:55 PM Jan Ekström <jeebjp@gmail.com> wrote:
> > >
> > > Fixes passing through mismatching metadata from the input side
> > > when RGB input (from f.ex. H.264 or HEVC) gets converted to YCbCr.
> > >
> > > Fixes #9132
> > > ---
> > >  libavfilter/vf_scale.c | 9 +++++++++
> > >  1 file changed, 9 insertions(+)
> > >
> > > diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> > > index ce39217515..7ca833bbb1 100644
> > > --- a/libavfilter/vf_scale.c
> > > +++ b/libavfilter/vf_scale.c
> > > @@ -738,6 +738,15 @@ scale:
> > >      out->width  = outlink->w;
> > >      out->height = outlink->h;
> > >
> > > +    // Sanity check: If we've got the RGB/XYZ (identity) matrix configured, and
> > > +    //               the output is no longer RGB, unset the matrix.
> > > +    //               In theory this should be in swscale itself as the AVFrame
> > > +    //               based API gets in, so that not every swscale API user has
> > > +    //               to go through duplicating such sanity checks.
> > > +    if (out->colorspace == AVCOL_SPC_RGB &&
> > > +        !(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
> > > +        out->colorspace = AVCOL_SPC_UNSPECIFIED;
> > > +
> > >      if (scale->output_is_pal)
> > >          avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
> > >
> > > --
> > > 2.31.1
> > >
> >
> > Unless there are objections, I will pull this in soon. I will also
> > attempt to see if I can add a programmatic FATE test for all of the
> > allowed configurations of vf_scale, to see if there are any other
> > clear-cut cases where not all metadata from the input AVFrame can be
> > passed on as-is and has to be reset.
>
> no objections
>
> thx

Thanks, applied as 9dd410c80416197188337e3b7e1600be41d2ea64 .

Jan
diff mbox series

Patch

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index ce39217515..7ca833bbb1 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -738,6 +738,15 @@  scale:
     out->width  = outlink->w;
     out->height = outlink->h;
 
+    // Sanity check: If we've got the RGB/XYZ (identity) matrix configured, and
+    //               the output is no longer RGB, unset the matrix.
+    //               In theory this should be in swscale itself as the AVFrame
+    //               based API gets in, so that not every swscale API user has
+    //               to go through duplicating such sanity checks.
+    if (out->colorspace == AVCOL_SPC_RGB &&
+        !(av_pix_fmt_desc_get(out->format)->flags & AV_PIX_FMT_FLAG_RGB))
+        out->colorspace = AVCOL_SPC_UNSPECIFIED;
+
     if (scale->output_is_pal)
         avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);