利用ffmpeg解码H264,花屏
UINT CMP4File::VideoCap_Thread_Fun(void* pParam)
{
CMP4File *pMP4File=(CMP4File*)pParam;
//初始化AVPacket
av_init_packet(&pMP4File->m_AVPacket);
int nFrameFinished = 0;
while(true)
{
if(av_read_frame(pMP4File->m_pFormatCtx, &(pMP4File->m_AVPacket)) >=0) {
int nDecodeResult=avcodec_decode_video2(pMP4File->m_pCodecContext, pMP4File->m_pFrame,
&nFrameFinished, &(pMP4File->m_AVPacket));
if(nDecodeResult>0)
{
if(nFrameFinished>0)
{
int iReturn=sws_scale(pMP4File->m_pSwsContext, pMP4File->m_pFrame->data,
pMP4File->m_pFrame->linesize, 0, pMP4File->m_nFrameHeight,
pMP4File->m_pRGBFrame.data, pMP4File->m_pRGBFrame.linesize);
AVFRAME_INFO pFrame;
memset(&pFrame, 0, sizeof(AVFRAME_INFO));
int m=1980, n=1080;
pFrame.uWidth=pMP4File->m_nFrameWidth;
pFrame.uHeight=pMP4File->m_nFrameHeight;
//显示
unsigned char* outStream = (unsigned char*)(pMP4File->m_pRGBFrame.data[0]);
pMP4File->Drawer(&pFrame, outStream);
av_free_packet(&pMP4File->m_AVPacket);
}
}//if
}
return 0;
}