说了你也不相信,我用 directx 采集到的数据是从web camera来的 yuy2 数据,我用自己写的转换程序可以成功转换正确的图像rgb24, yuy2 -> rgb24 -> I420 都可以,但是用ffmpeg的sws__scale 怎么也无法正确转换。
sws__scale 的解码过程如下
void scaleYUY2toI420(const void *pSrc, int widthSrc, int heightSrc,
void *pDest, int widthDest, int heightDest, bool bQualityImportant/* = false*/)
{
struct SwsContext *pctx;
AVPicture picSrc = { 0 };
AVPicture picDst = { 0 };
enum AVPixelFormat fmtSrc = AV_PIX_FMT_YUYV422;
enum AVPixelFormat fmtDst = AV_PIX_FMT_YUV420P;
avpicture_fill(&picSrc, (uint8_t*)pSrc, fmtSrc, widthSrc, heightSrc); //
avpicture_fill(&picDst, (uint8_t*)pDest, fmtDst, widthDest, heightDest);
pctx = sws_getContext(widthSrc, heightSrc, fmtSrc,
widthDest, heightDest, fmtDst,
bQualityImportant ? SWS_BICUBIC : SWS_POINT, NULL, NULL, NULL);
if (pctx == NULL)
return;
sws_scale(pctx, picSrc.data, picSrc.linesize, 0, heightSrc, picDst.data, picDst.linesize);
sws_freeContext(pctx);
}
问题在哪里始终不得要领,希望专家们不吝赐教。
为了验证问题,我用 ffmpeg 转换 rgb24 -> I420每问题,是不是ffmpeg不支持 yuy2 packed 包到 i420?但是我看它的像素格式定义, AV_PIX_FMT_YUYV422 排在最前面啊