* [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account
@ 2022-03-03 12:06 Martin Storsjö
2022-03-03 12:08 ` Diederick C. Niehorster
2022-03-04 20:09 ` Michael Niedermayer
0 siblings, 2 replies; 6+ messages in thread
From: Martin Storsjö @ 2022-03-03 12:06 UTC (permalink / raw)
To: ffmpeg-devel
While swscale can be reconfigured with sws_setColorspaceDetails,
the in/out ranges also need to be set before calling
sws_init_context, otherwise the initialization might choose
fastpaths that don't take the ranges into account.
Therefore, look at in->color_range too, when deciding on whether
the scaler needs to be reconfigured.
Add a new member variable for keeping track of this, for being
able to differentiate between whether the scale filter parameter
"in_range" has been set (which should override whatever the input
frame has set) or whether it has been configured based on the
latest frame (which should trigger reconfiguring the scaler if
the input frame ranges change).
Signed-off-by: Martin Storsjö <martin@martin.st>
---
To test this (without risking running many conflicting swscale
filters in one filter pipeline), we'd need to be able to tag
the incoming raw yuv data with colorspace and range without setting
the in_color_matrix and in_range options on the scale filter.
When using the rawvideo demuxer, the pixel format is set via the
ffmpeg -pix_fmt option, but there's no corresponding option for
setting color matrix or range for it.
---
libavfilter/vf_scale.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 44f85cb019..996f7aaa5b 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -138,6 +138,7 @@ typedef struct ScaleContext {
char *out_color_matrix;
int in_range;
+ int in_frame_range;
int out_range;
int out_h_chr_pos;
@@ -322,6 +323,8 @@ static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
scale->opts = *opts;
*opts = NULL;
+ scale->in_frame_range = AVCOL_RANGE_UNSPECIFIED;
+
return 0;
}
@@ -544,6 +547,9 @@ static int config_props(AVFilterLink *outlink)
if (scale->in_range != AVCOL_RANGE_UNSPECIFIED)
av_opt_set_int(s, "src_range",
scale->in_range == AVCOL_RANGE_JPEG, 0);
+ else if (scale->in_frame_range != AVCOL_RANGE_UNSPECIFIED)
+ av_opt_set_int(s, "src_range",
+ scale->in_frame_range == AVCOL_RANGE_JPEG, 0);
if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
av_opt_set_int(s, "dst_range",
scale->out_range == AVCOL_RANGE_JPEG, 0);
@@ -690,6 +696,13 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
in->sample_aspect_ratio.den != link->sample_aspect_ratio.den ||
in->sample_aspect_ratio.num != link->sample_aspect_ratio.num;
+ if (in->color_range != AVCOL_RANGE_UNSPECIFIED &&
+ scale->in_range == AVCOL_RANGE_UNSPECIFIED &&
+ in->color_range != scale->in_frame_range) {
+ scale->in_frame_range = in->color_range;
+ frame_changed = 1;
+ }
+
if (scale->eval_mode == EVAL_MODE_FRAME || frame_changed) {
unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 };
--
2.32.0 (Apple Git-132)
_______________________________________________
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] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account
2022-03-03 12:06 [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account Martin Storsjö
@ 2022-03-03 12:08 ` Diederick C. Niehorster
2022-03-04 20:09 ` Michael Niedermayer
1 sibling, 0 replies; 6+ messages in thread
From: Diederick C. Niehorster @ 2022-03-03 12:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Thu, Mar 3, 2022 at 1:07 PM Martin Storsjö <martin@martin.st> wrote:
> While swscale can be reconfigured with sws_setColorspaceDetails,
> the in/out ranges also need to be set before calling
> sws_init_context, otherwise the initialization might choose
> fastpaths that don't take the ranges into account.
>
> Therefore, look at in->color_range too, when deciding on whether
> the scaler needs to be reconfigured.
>
> Add a new member variable for keeping track of this, for being
> able to differentiate between whether the scale filter parameter
> "in_range" has been set (which should override whatever the input
> frame has set) or whether it has been configured based on the
> latest frame (which should trigger reconfiguring the scaler if
> the input frame ranges change).
>
> Signed-off-by: Martin Storsjö <martin@martin.st>
> ---
>
Tested by me to resolve https://trac.ffmpeg.org/ticket/9576.
Thanks Martin!
All the best,
Dee
_______________________________________________
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] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account
2022-03-03 12:06 [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account Martin Storsjö
2022-03-03 12:08 ` Diederick C. Niehorster
@ 2022-03-04 20:09 ` Michael Niedermayer
2022-03-05 21:33 ` Martin Storsjö
1 sibling, 1 reply; 6+ messages in thread
From: Michael Niedermayer @ 2022-03-04 20:09 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1962 bytes --]
On Thu, Mar 03, 2022 at 02:06:45PM +0200, Martin Storsjö wrote:
> While swscale can be reconfigured with sws_setColorspaceDetails,
> the in/out ranges also need to be set before calling
> sws_init_context, otherwise the initialization might choose
> fastpaths that don't take the ranges into account.
>
> Therefore, look at in->color_range too, when deciding on whether
> the scaler needs to be reconfigured.
>
> Add a new member variable for keeping track of this, for being
> able to differentiate between whether the scale filter parameter
> "in_range" has been set (which should override whatever the input
> frame has set) or whether it has been configured based on the
> latest frame (which should trigger reconfiguring the scaler if
> the input frame ranges change).
>
> Signed-off-by: Martin Storsjö <martin@martin.st>
> ---
> To test this (without risking running many conflicting swscale
> filters in one filter pipeline), we'd need to be able to tag
> the incoming raw yuv data with colorspace and range without setting
> the in_color_matrix and in_range options on the scale filter.
>
> When using the rawvideo demuxer, the pixel format is set via the
> ffmpeg -pix_fmt option, but there's no corresponding option for
> setting color matrix or range for it.
> ---
> libavfilter/vf_scale.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
This changes the output for:
ffmpeg -i tickets/524/AVCI50.mov -vframes 3 file-avci50dec.nut
ffmpeg -i tickets/4493/AVCI100.mov -vframes 3 file-avci100dec.nut
https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket524/
Is that intended ?
- 233903 file-avci100dec.nut
- 383853 file-avci50dec.nut
+ 196558 file-avci100dec.nut
+ 333893 file-avci50dec.nut
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
"I am not trying to be anyone's saviour, I'm trying to think about the
future and not be sad" - Elon Musk
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account
2022-03-04 20:09 ` Michael Niedermayer
@ 2022-03-05 21:33 ` Martin Storsjö
2022-03-05 23:08 ` Michael Niedermayer
0 siblings, 1 reply; 6+ messages in thread
From: Martin Storsjö @ 2022-03-05 21:33 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 4 Mar 2022, Michael Niedermayer wrote:
> On Thu, Mar 03, 2022 at 02:06:45PM +0200, Martin Storsjö wrote:
>> While swscale can be reconfigured with sws_setColorspaceDetails,
>> the in/out ranges also need to be set before calling
>> sws_init_context, otherwise the initialization might choose
>> fastpaths that don't take the ranges into account.
>>
>> Therefore, look at in->color_range too, when deciding on whether
>> the scaler needs to be reconfigured.
>>
>> Add a new member variable for keeping track of this, for being
>> able to differentiate between whether the scale filter parameter
>> "in_range" has been set (which should override whatever the input
>> frame has set) or whether it has been configured based on the
>> latest frame (which should trigger reconfiguring the scaler if
>> the input frame ranges change).
>>
>> Signed-off-by: Martin Storsjö <martin@martin.st>
>> ---
>> To test this (without risking running many conflicting swscale
>> filters in one filter pipeline), we'd need to be able to tag
>> the incoming raw yuv data with colorspace and range without setting
>> the in_color_matrix and in_range options on the scale filter.
>>
>> When using the rawvideo demuxer, the pixel format is set via the
>> ffmpeg -pix_fmt option, but there's no corresponding option for
>> setting color matrix or range for it.
>> ---
>> libavfilter/vf_scale.c | 13 +++++++++++++
>> 1 file changed, 13 insertions(+)
>
> This changes the output for:
> ffmpeg -i tickets/524/AVCI50.mov -vframes 3 file-avci50dec.nut
> ffmpeg -i tickets/4493/AVCI100.mov -vframes 3 file-avci100dec.nut
>
> https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket524/
>
> Is that intended ?
>
> - 233903 file-avci100dec.nut
> - 383853 file-avci50dec.nut
> + 196558 file-avci100dec.nut
> + 333893 file-avci50dec.nut
Looks like these source files have full range content; for any data with
full range input, this patch makes sure it uses the right intended
conversion through swscale. So yes, I guess it's expected that these
conversions change.
// Martin
_______________________________________________
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] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account
2022-03-05 21:33 ` Martin Storsjö
@ 2022-03-05 23:08 ` Michael Niedermayer
2022-03-06 22:47 ` Martin Storsjö
0 siblings, 1 reply; 6+ messages in thread
From: Michael Niedermayer @ 2022-03-05 23:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2531 bytes --]
On Sat, Mar 05, 2022 at 11:33:15PM +0200, Martin Storsjö wrote:
> On Fri, 4 Mar 2022, Michael Niedermayer wrote:
>
> > On Thu, Mar 03, 2022 at 02:06:45PM +0200, Martin Storsjö wrote:
> > > While swscale can be reconfigured with sws_setColorspaceDetails,
> > > the in/out ranges also need to be set before calling
> > > sws_init_context, otherwise the initialization might choose
> > > fastpaths that don't take the ranges into account.
> > >
> > > Therefore, look at in->color_range too, when deciding on whether
> > > the scaler needs to be reconfigured.
> > >
> > > Add a new member variable for keeping track of this, for being
> > > able to differentiate between whether the scale filter parameter
> > > "in_range" has been set (which should override whatever the input
> > > frame has set) or whether it has been configured based on the
> > > latest frame (which should trigger reconfiguring the scaler if
> > > the input frame ranges change).
> > >
> > > Signed-off-by: Martin Storsjö <martin@martin.st>
> > > ---
> > > To test this (without risking running many conflicting swscale
> > > filters in one filter pipeline), we'd need to be able to tag
> > > the incoming raw yuv data with colorspace and range without setting
> > > the in_color_matrix and in_range options on the scale filter.
> > >
> > > When using the rawvideo demuxer, the pixel format is set via the
> > > ffmpeg -pix_fmt option, but there's no corresponding option for
> > > setting color matrix or range for it.
> > > ---
> > > libavfilter/vf_scale.c | 13 +++++++++++++
> > > 1 file changed, 13 insertions(+)
> >
> > This changes the output for:
> > ffmpeg -i tickets/524/AVCI50.mov -vframes 3 file-avci50dec.nut
> > ffmpeg -i tickets/4493/AVCI100.mov -vframes 3 file-avci100dec.nut
> >
> > https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket524/
> >
> > Is that intended ?
> >
> > - 233903 file-avci100dec.nut
> > - 383853 file-avci50dec.nut
> > + 196558 file-avci100dec.nut
> > + 333893 file-avci50dec.nut
>
> Looks like these source files have full range content; for any data with
> full range input, this patch makes sure it uses the right intended
> conversion through swscale. So yes, I guess it's expected that these
> conversions change.
patch ok then
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: 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] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account
2022-03-05 23:08 ` Michael Niedermayer
@ 2022-03-06 22:47 ` Martin Storsjö
0 siblings, 0 replies; 6+ messages in thread
From: Martin Storsjö @ 2022-03-06 22:47 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, 6 Mar 2022, Michael Niedermayer wrote:
> On Sat, Mar 05, 2022 at 11:33:15PM +0200, Martin Storsjö wrote:
>> On Fri, 4 Mar 2022, Michael Niedermayer wrote:
>>
>>> On Thu, Mar 03, 2022 at 02:06:45PM +0200, Martin Storsjö wrote:
>>>> While swscale can be reconfigured with sws_setColorspaceDetails,
>>>> the in/out ranges also need to be set before calling
>>>> sws_init_context, otherwise the initialization might choose
>>>> fastpaths that don't take the ranges into account.
>>>>
>>>> Therefore, look at in->color_range too, when deciding on whether
>>>> the scaler needs to be reconfigured.
>>>>
>>>> Add a new member variable for keeping track of this, for being
>>>> able to differentiate between whether the scale filter parameter
>>>> "in_range" has been set (which should override whatever the input
>>>> frame has set) or whether it has been configured based on the
>>>> latest frame (which should trigger reconfiguring the scaler if
>>>> the input frame ranges change).
>>>>
>>>> Signed-off-by: Martin Storsjö <martin@martin.st>
>>>> ---
>>>> To test this (without risking running many conflicting swscale
>>>> filters in one filter pipeline), we'd need to be able to tag
>>>> the incoming raw yuv data with colorspace and range without setting
>>>> the in_color_matrix and in_range options on the scale filter.
>>>>
>>>> When using the rawvideo demuxer, the pixel format is set via the
>>>> ffmpeg -pix_fmt option, but there's no corresponding option for
>>>> setting color matrix or range for it.
>>>> ---
>>>> libavfilter/vf_scale.c | 13 +++++++++++++
>>>> 1 file changed, 13 insertions(+)
>>>
>>> This changes the output for:
>>> ffmpeg -i tickets/524/AVCI50.mov -vframes 3 file-avci50dec.nut
>>> ffmpeg -i tickets/4493/AVCI100.mov -vframes 3 file-avci100dec.nut
>>>
>>> https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket524/
>>>
>>> Is that intended ?
>>>
>>> - 233903 file-avci100dec.nut
>>> - 383853 file-avci50dec.nut
>>> + 196558 file-avci100dec.nut
>>> + 333893 file-avci50dec.nut
>>
>> Looks like these source files have full range content; for any data with
>> full range input, this patch makes sure it uses the right intended
>> conversion through swscale. So yes, I guess it's expected that these
>> conversions change.
>
> patch ok then
Pushed, thanks.
// Martin
_______________________________________________
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] 6+ messages in thread
end of thread, other threads:[~2022-03-06 22:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-03 12:06 [FFmpeg-devel] [PATCH] libavfilter: vf_scale: Properly take in->color_range into account Martin Storsjö
2022-03-03 12:08 ` Diederick C. Niehorster
2022-03-04 20:09 ` Michael Niedermayer
2022-03-05 21:33 ` Martin Storsjö
2022-03-05 23:08 ` Michael Niedermayer
2022-03-06 22:47 ` Martin Storsjö
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