Ffmpeg swscaler警告:使用了不推荐的像素格式
我想先对视频帧执行颜色空间转换,然后再使用以下代码将其转换为opengl纹理:Ffmpeg swscaler警告:使用了不推荐的像素格式,ffmpeg,format,pixel,Ffmpeg,Format,Pixel,我想先对视频帧执行颜色空间转换,然后再使用以下代码将其转换为opengl纹理: struct SwsContext * pSwsCtx = sws_getCachedContext(NULL,width, height, codec->pix_fmt, width, height, AV_PIX_FMT_RGBA, SWS_POINT, NULL, NULL, NULL); 每次调用sws_getCachedContext()函数时,我都会收到以下警告: [swscaler @ 0x10
struct SwsContext * pSwsCtx = sws_getCachedContext(NULL,width, height, codec->pix_fmt, width, height, AV_PIX_FMT_RGBA, SWS_POINT, NULL, NULL, NULL);
每次调用sws_getCachedContext()函数时,我都会收到以下警告:
[swscaler @ 0x10506fa00] deprecated pixel format used, make sure you did set range correctly
以下是我的ffmpeg输出以获取版本信息:
ffmpeg version 2.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Mar 26 2014 15:29:01 with Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libavresample 1. 2. 0 / 1. 2. 0
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Hyper fast Audio and Video encoder
有没有办法禁用此警告?如何正确设置颜色范围?您似乎正在尝试读取已弃用的
AV\u PIX\u FMT\u YUVJXXXP
帧(请参阅)。您可以使用此解决方案来管理它:
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;
}
这个问题已经问了很久了,但当我遇到同样的问题时,我看了看,试图找到第二部分的答案(如何正确设置颜色范围?)。我扩展了托马斯·阿尤布的答案:
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);
关于射程是什么?YUV像素格式的值的范围为:Y 16..235、UV 16..240。YUVJ扩展为1,所有YUV均为0。。。255所以设置
srcRange = 1
强制libav使用扩展的输入数据范围。如果您没有对范围进行任何更改,那么您可能只会体验到夸张的对比度。它仍应将输入数据缩放到RGB颜色空间。您的ffmpeg最近有多新?你在sws_getContext上得到同样的结果了吗?@nmxprime我在sws_getContext上得到同样的结果我的视频流avpixel格式是AV_PIX_FMT_YUVJ420P。使用上述解决方法,它将转换为AV_PIX_FMT_YUV420P。“[swscaler@0dd9e620]使用了不推荐的像素格式,请确保正确设置了范围。”。我如何解决它?是的。我获取RTSP视频流,使用FFMpeg解码,然后将其转换为cv::MAT。@Tariq您应该发布另一个问题,并提供更多代码,我无法帮您完成此任务。谢谢您的建议,Thomas;我将此问题作为另一个问题发布在@ThomasAyoub上,示例代码为@ThomasAyoub。使用此W/A的含义是什么?的确,它将消除警告,但关于转换为RGB本身?我非常喜欢您的答案,因为它解释了格式的差异以及如何完全导航它们。