#include <SDL.h>#include <SDL_thread.h>if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)){fprintf(stderr,"Could not initialize SDL - %s \n",SDL_GetError());exit(1);}
其中SDL_Init用于初始化SDL库,SDL_GetError是一个 debug 处理函数。
创建显示区域
现在需要屏幕上的一个区域来显示图像。SDL中用于显示图像的区域称之为surface。
123456
SDL_Surface*screen;screen=SDL_SetVideoMode(pCodecCtx->width,pCodecCtx->height,0,0);if(!screen){fprintf(stderr,"SDL:could not set video mode -exiting \n");exit(1);}
if(frameFinished){SDL_LockYUVOverlay(bmp);AVPicturepict;pict.data[0]=bmp->pixels[0];pict.data[1]=bmp->pixels[2];pict.data[2]=bmp->pixels[1];pict.linesize[0]=bmp->pitches[0];pict.linesize[1]=bmp->pitches[2];pict.linesize[2]=bmp->pitches[1];// Convert the image into YUV format that SDL usessws_scale(sws_ctx,(uint8_tconst*const*)pFrame->data,pFrame->linesize,0,pCodecCtx->height,pict.data,pict.linesize);SDL_UnlockYUVOverlay(bmp);}
SDL_Rectrect;if(frameFinished){/* ... code ... */// Convert the image into YUV format that SDL usessws_scale(sws_ctx,(uint8_tconst*const*)pFrame->data,pFrame->linesize,0,pCodecCtx->height,pict.data,pict.linesize);SDL_UnlockYUVOverlay(bmp);rect.x=0;rect.y=0;rect.w=pCodecCtx->width;rect.h=pCodecCtx->height;SDL_DisplayYUVOverlay(bmp,&rect);}