[Libav-user] Is there any way to retrieve flags from SWS context?

Pavel Krasnovskij pavel at videntifier.com
Tue Dec 17 12:07:42 EET 2019


When creating SWS context, it can silently internally modify sent flags.
For example, it can add/remove SWS_FULL_CHR_H_INT flag
(f.ex. https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/utils.c#L1346
https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/utils.c#L1378)
Then later, if trying to get cached SWS context using f.ex.:

sws_getCachedContext(
          old_context, // Potentialy reusable context
          dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, // Src params
          frame_rgb->width, frame_rgb->height,
static_cast<AVPixelFormat>(frame_rgb->format),
          SWS_BICUBIC, NULL, NULL, NULL));

It will always produce a cache miss, since flags in old context won't be
same, here:
https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/utils.c#L2394
It would be helpful to call sws_getCachedContext with old_context->flags
instead, like so:

sws_getCachedContext(
          old_context, // Potentialy reusable context
          dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, // Src params
          frame_rgb->width, frame_rgb->height,
static_cast<AVPixelFormat>(frame_rgb->format),
          old_context->flags, NULL, NULL, NULL));

However external ffmpeg API doesnt seem to allow access to
old_context->flags, there is only forward declartion for SwsContext struct
in swscale.h

Also tried using:

>  int64_t flags = SWS_BICUBIC;
>  int success = av_opt_get_int(old_context, "flags", 0, &flags);
>  uint8_t* aflags = 0;
>  success = av_opt_get(old_context, "flags", 0, *aflags);

However, this doesnt succeed (success == -1)

Is there perhaps some solution to this?

Thank you,
Pavel K.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20191217/5c092b82/attachment.html>


More information about the Libav-user mailing list