h264解码显示问题
各位兄弟,本人碰到一个怪问题,先贴代码
int h264_decode(unsigned char* p_h264_data,int data_len,unsigned char* out_buf,int out_len)
{
int ret=-1;
AVFrame* decoder_picture=NULL;
decoder_picture = avcodec_alloc_frame();
if(decoder_picture == NULL)
return ret;
int got_picture_ptr = 0;
unsigned long decoder_len = avcodec_decode_video(decoder_context,decoder_picture,&got_picture_ptr,p_h264_data,data_len);
if(!got_picture_ptr)
return -1;
if(decoder_len <0)
return ret;
AVFrame *pict = avcodec_alloc_frame();
avpicture_alloc((AVPicture *)pict,PIX_FMT_BGR24,decoder_context->width, decoder_context->height);
img_convert((AVPicture *)pict, PIX_FMT_BGR24, (AVPicture*)decoder_picture,decoder_context->pix_fmt, decoder_context->width, decoder_context->height);
avpicture_layout((AVPicture*)pict, PIX_FMT_BGR24,decoder_context->width, decoder_context->height,out_buf,pict->linesize[0]*decoder_context->height);
av_free(decoder_picture);
avpicture_free((AVPicture *)pict);
av_free(pict);
return decoder_len;
}
int play_video(unsigned char * vd_buf,int data_size)
{
//EnterCriticalSection(&m_CtxLock);
map<HDC,VideoDispContext>::iterator it;
for(it=m_mapVideoDispContext.begin();it!=m_mapVideoDispContext.end();it++)
{
VideoDispContext * pvdc = (VideoDispContext*)&it->second;
if(::IsWindowVisible(pvdc->hAttachWnd))
{
RECT rcVideo;
::GetClientRect(pvdc->hAttachWnd,&rcVideo);
int xDest = rcVideo.right - rcVideo.left;
int yDest = rcVideo.bottom - rcVideo.top;
::DrawDibDraw(m_hDib,
pvdc->hDC,
0,// dest : left pos
0,// dest : top pos
xDest, // don't zoom x
yDest, // don't zoom y
&m_bmiHdr, // bmp header info
vd_buf, // bmp data
0, // src :left
0, // src :top
m_bmiHdr.biWidth, // src : width
m_bmiHdr.biHeight, // src : height
DDF_SAME_DRAW // use prev params....
);
}
}
//LeaveCriticalSection(&m_CtxLock);
return 0;
}
问题来了,调用h264_decode解码h264的视频帧后,用play_video函数显示出来,但是显示的图像很奇怪,行与列的像素是调换了,有谁碰到过这样的问题吗,请不吝赐教,谢谢兄弟们了
[解决办法]
可以先把解码后图象DUMP存出来看看解码的对不对,如果解码后的图象正确,再看看是不是显示函数写的有问题。
[解决办法]
感觉代码写的怪怪的,参考下这个试试http://blog.csdn.net/chinabinlang/article/details/7088590