swscaler warning : deprecated pixel format used

烂漫一生 提交于 2019-12-03 03:13:06
Thomas Ayoub

It seems you're trying to read AV_PIX_FMT_YUVJXXXP frames which are deprecated (see the libav doc). You can use this workaround to manage it :

AVPixelFormat pixFormat;
switch (_videoStream->codec->pix_fmt) {
case AV_PIX_FMT_YUVJ420P :
    pixFormat = AV_PIX_FMT_YUV420P;
    break;
case AV_PIX_FMT_YUVJ422P  :
    pixFormat = AV_PIX_FMT_YUV422P;
    break;
case AV_PIX_FMT_YUVJ444P   :
    pixFormat = AV_PIX_FMT_YUV444P;
    break;
case AV_PIX_FMT_YUVJ440P :
    pixFormat = AV_PIX_FMT_YUV440P;
    break;
default:
    pixFormat = _videoStream->codec->codec->pix_fmts;
    break;
}

It is long time since the question was asked, but as I hit the same problem then I looked at it and tried to find also the answer to the second part (How to set the color range correctly?). I am extending the Thomas Ayoub's answer:

AVCodecContext* pCodecCtx = _videoStream->codec;
AVPixelFormat pixFormat;
switch (pCodecCtx->pix_fmt)
  {
    case AV_PIX_FMT_YUVJ420P:
      pixFormat = AV_PIX_FMT_YUV420P;
      break;
    case AV_PIX_FMT_YUVJ422P:
      pixFormat = AV_PIX_FMT_YUV422P;
      break;
    case AV_PIX_FMT_YUVJ444P:
      pixFormat = AV_PIX_FMT_YUV444P;
      break;
    case AV_PIX_FMT_YUVJ440P:
      pixFormat = AV_PIX_FMT_YUV440P;
      break;
    default:
      pixFormat = pCodecCtx->pix_fmt;
  }
// initialize SWS context for software scaling
SwsContext *swsCtx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pixFormat, pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL);
// change the range of input data by first reading the current color space and then setting it's range as yuvj.
int dummy[4];
int srcRange, dstRange;
int brightness, contrast, saturation;
sws_getColorspaceDetails(swsCtx, (int**)&dummy, &srcRange, (int**)&dummy, &dstRange, &brightness, &contrast, &saturation);
const int* coefs = sws_getCoefficients(SWS_CS_DEFAULT);
srcRange = 1; // this marks that values are according to yuvj
sws_setColorspaceDetails(swsCtx, coefs, srcRange, coefs, dstRange,
                               brightness, contrast, saturation);

What is it about the ranges? The YUV pixel format has values in ranges: Y 16..235, UV 16..240. The YUVJ is extended one and all YUV are 0 ... 255. So setting

srcRange = 1

forces the libav to use extended input data range. If you do not make any changes in the range then probably you only experience exaggerated contrast. It should still scale the input data to RGB color space.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!