注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

_

_

 
 
 

日志

 
 

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

2014-09-14 03:47:49|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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

2011-05-19 14:18 2418人阅读 评论(2) 收藏 举报

nullcodecvideo

[cpp] view plaincopyprint?

  1. AVFrame* pFrame;?????????????????? // Frame
  2. AVCodecContext* pContext;????????? // Codec Context
  3. int nUsedBytes = avcodec_decode_video(pContext, pFrame,? &nFrame, pSrcBuffer, nSrcLength);?
  4. if(nUsedBytes > 0)?
  5. {?
  6. ??? AVFrame? out_pic;?
  7. ??? SwsContext* img_convert_ctx = sws_getContext(pContext->width, pContext->height, pContext->pix_fmt, nDestW, nDestH,(PixelFormat)PIX_FMT_BGR24,SWS_BICUBIC, NULL, NULL, NULL);?
  8. if(img_convert_ctx != NULL)?
  9. ??? {?
  10. if(avpicture_alloc((AVPicture *)&out_pic, PIX_FMT_RGB24, nDestW, nDestH)>=0)?
  11. ??????? {?
  12. ??????????? pFrame->data[0] = pFrame->data[0]+pFrame->linesize[0]*(pContext->height-1);?
  13. ??????????? pFrame->data[1] = pFrame->data[1]+pFrame->linesize[0]*pContext->height/4-1;?
  14. ?????? pFrame->data[2] = pFrame->data[2]+pFrame->linesize[0]*pContext->height/4-1;?
  15. ??????????? pFrame->linesize[0] *= -1;?
  16. ??????????? pFrame->linesize[1] *= -1;?
  17. ?????? pFrame->linesize[2] *= -1;?
  18. ?????? sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pContext->height, out_pic.data, out_pic.linesize);?
  19. ??????????? avpicture_free((AVPicture *)&out_pic);?
  20. ??????? }?
  21. ??????? sws_freeContext(img_convert_ctx);?
  22. ??? }?
  23. }?

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);

  评论这张
 
阅读(345)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017