使用ffmpeg缩放时报错deprecated pixel format used

在使用ffmpeg的scale函数进行转换时报的错

int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[],
              const int srcStride[], int srcSliceY, int srcSliceH,
              uint8_t *const dst[], const int dstStride[]);

报错信息如下:

deprecated pixel format used, make sure you did set range correctly

原因是YUVJ420P格式已经被弃用了,需要换成YUV420格式,并设置color range。

AVPixelFormat pixFormat;
bool changeColorspaceDetails = false;
switch (pCodecCtx->pix_fmt)
  {
    case AV_PIX_FMT_YUVJ420P:
      pixFormat = AV_PIX_FMT_YUV420P;
      changeColorspaceDetails = true;
      break;
    case AV_PIX_FMT_YUVJ422P:
      pixFormat = AV_PIX_FMT_YUV422P;
      changeColorspaceDetails = true;
      break;
    case AV_PIX_FMT_YUVJ444P:
      pixFormat = AV_PIX_FMT_YUV444P;
      changeColorspaceDetails = true;
      break;
    case AV_PIX_FMT_YUVJ440P:
      pixFormat = AV_PIX_FMT_YUV440P;
      changeColorspaceDetails = true;
      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);

if (changeColorspaceDetails)
{
    // 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);
}

为什么要设置color range?

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值