[FFmpeg-devel] [PATCH 4/4] ffmpeg: pass decoded or filtered AVFrame to output stream initialization

Jan Ekström jeebjp at gmail.com
Tue Sep 15 21:12:37 EEST 2020


On Tue, Sep 15, 2020 at 7:39 PM James Almer <jamrial at gmail.com> wrote:
>
> On 9/15/2020 1:21 PM, Jan Ekström wrote:
> > On Tue, Sep 15, 2020 at 5:28 PM Jan Ekström <jeebjp at gmail.com> wrote:
> >>
> >>
> >> Further looking into this, it seems to come from filtering (?) (diff attached)
> >>
> >> decoded AVFrame: 128x128, pix_fmt: rgba, range: pc
> >> while...
> >> AVFrame to be encoded: 128x128, pix_fmt: bgra, range: tv
> >>
> >> Jan
> >
> > For the record, the culprit seems to be this piece of logic within
> > libavfilter/vf_scale.c:
> > http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavfilter/vf_scale.c;h=58eee967440657798f84383ec6f79e8a05c3ece0;hb=HEAD#l747
> >
> > Only input has range defined, out_full never gets set to nonzero.
> > Thus,
> > out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG
> > leads to AVCOL_RANGE_MPEG.
>
> Would changing that to out->color_range = scale->out_range help, or
> break things too much?
>

I was informed that swscale doesn't say that RGB is full range, so I
moved on to fix that since that is utilized as out_full here. Patch
follows.

After doing that, FATE still passed but...

[swscaler @ 0x62f000000400] sws_init_context: srcRange: 1, dstRange: 1
[auto_scaler_0 @ 0x611000007980] w:128 h:128 fmt:rgba sar:2835/2835 ->
w:128 h:128 fmt:bgra sar:1/1 flags:0x4
scale_frame: out_full: 0
vf_scale AVFrame: 128x128, pix_fmt: bgra, range: tv

I am very confused at this point :P

Jan

------>8--------
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 9ca378bd3b..59d4d5e873 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1200,8 +1200,11 @@ av_cold int sws_init_context(SwsContext *c,
SwsFilter *srcFilter,

     unscaled = (srcW == dstW && srcH == dstH);

-    c->srcRange |= handle_jpeg(&c->srcFormat);
-    c->dstRange |= handle_jpeg(&c->dstFormat);
+    c->srcRange |= isAnyRGB(c->srcFormat) ? 1 : handle_jpeg(&c->srcFormat);
+    c->dstRange |= isAnyRGB(c->dstFormat) ? 1 : handle_jpeg(&c->dstFormat);
+
+    av_log(c, AV_LOG_VERBOSE, "%s: srcRange: %d, dstRange: %d\n",
+           __FUNCTION__, c->srcRange, c->dstRange);

     if(srcFormat!=c->srcFormat || dstFormat!=c->dstFormat)
         av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make
sure you did set range correctly\n");


More information about the ffmpeg-devel mailing list