[FFmpeg-devel] [PATCH v2] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.

Niklas Haas ffmpeg at haasn.xyz
Mon Mar 25 17:02:23 EET 2024


On Mon, 25 Mar 2024 15:36:26 +0100 Damiano Galassi <damiog at gmail.com> wrote:
> On Mon, Mar 25, 2024 at 2:40 PM Niklas Haas <ffmpeg at haasn.xyz> wrote:
> 
> > > ffmpeg -i in.mp4 -vf
> > > "scale='width=1920:height=1080',zscale='width=1920:height=1080'" out.mp4
> > > ffmpeg -i in.jpg -vf "zscale='width=1920:height=1080'" out.jpg
> > >
> > > it doesn't need a specific mp4 or jpg file.
> >
> > I cannot reproduce any error with your first command line.
> 
> 
>  here's a sample file, and the output I get:
> 
> https://subler.org/downloads/test.mp4
> https://gist.github.com/galad87/a6ddc3318cf20cd2f1ac7d053e1a0786

Okay, I see the problem. Basically, swap_color_spaces() doesn't re-run
after pick_formats() settles a filter's format. So swap_color_spaces()
never actually sets zscale's preferred output format, because at that
point there are still multiple options for swscale's output format.

This patch appears to help, but I'm honestly not sure what exactly the
difference is between this REDUCE_FORMATS() and swap_color_spaces(), or
actually, for what case the latter even exists.

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index bb5399c55e8..3b8f7464889 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -794,6 +794,10 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
                    nb_formats, ff_add_format);
     REDUCE_FORMATS(int,      AVFilterFormats,        samplerates,     formats,
                    nb_formats, ff_add_format);
+    REDUCE_FORMATS(int,      AVFilterFormats,        color_spaces,    formats,
+                   nb_formats, ff_add_format);
+    REDUCE_FORMATS(int,      AVFilterFormats,        color_ranges,    formats,
+                   nb_formats, ff_add_format);
 
     /* reduce channel layouts */
     for (i = 0; i < filter->nb_inputs; i++) {


More information about the ffmpeg-devel mailing list