牵着老婆满街逛

严以律己,宽以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

sws_scale解出来的RGB图像颠倒问题

转载自:http://blog.csdn.net/rightorwrong/article/details/6432042
AVFrame* pFrame;                   // Frame 
AVCodecContext* pContext;          // Codec Context
int nUsedBytes = avcodec_decode_video(pContext, pFrame,  &nFrame, pSrcBuffer, nSrcLength);
if(nUsedBytes > 0)
{
    AVFrame  out_pic;
    SwsContext
* img_convert_ctx = sws_getContext(pContext->width, pContext->height, pContext->pix_fmt, nDestW, nDestH,(PixelFormat)PIX_FMT_BGR24,SWS_BICUBIC, NULL, NULL, NULL);
    
if(img_convert_ctx != NULL)
    
{
        
if(avpicture_alloc((AVPicture *)&out_pic, PIX_FMT_RGB24, nDestW, nDestH)>=0)
        
{
            pFrame
->data[0= pFrame->data[0]+pFrame->linesize[0]*(pContext->height-1);
            pFrame
->data[1= pFrame->data[1]+pFrame->linesize[0]*pContext->height/4-1;
       pFrame
->data[2= pFrame->data[2]+pFrame->linesize[0]*pContext->height/4-1;
            pFrame
->linesize[0*= -1;
            pFrame
->linesize[1*= -1;
       pFrame
->linesize[2*= -1;
       sws_scale(img_convert_ctx, pFrame
->data, pFrame->linesize, 0, pContext->height, out_pic.data, out_pic.linesize);
            avpicture_free((AVPicture 
*)&out_pic);
        }

        sws_freeContext(img_convert_ctx);
    }

}

AVFrame的data和linesize:

YUV: linesize[0] =  width + padding size(16+16),linesize[1]=linesize[0]/2

        data[0],data[1],data[2]分别代表yuv 

RGB: linesize[0] = width*pixel_size  for RGB
        data[0]为packet rgb


  pFrame->data[0] = pFrame->data[0]+pFrame->linesize[0]*(pContext->height-1);
  pFrame->data[1] = pFrame->data[1]+pFrame->linesize[1]*(pContext->height/2-1);
  pFrame->data[2] = pFrame->data[2]+pFrame->linesize[2]*(pContext->height/2-1);

posted on 2013-01-28 18:21 杨粼波 阅读(2350) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理