#include<stdio.h>
#include "/usr/local/ffmpeg_arm/include/SDL/SDL.h"
char *bmp_name[3] = {"000.bmp","111.bmp","222.bmp"};
int main()
{
int i=0;
int w = 720;
int h = 576,retu;
unsigned char* pY;
unsigned char* pU;
unsigned char* pV;
FILE* fp;
SDL_Rect rect;
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
//Start SDL
// SDL_Init( SDL_INIT_EVERYTHING );
SDL_Init(SDL_INIT_VIDEO);
//Set up screen
screen = SDL_SetVideoMode( 1024, 768, 32, SDL_SWSURFACE );
SDL_Overlay* overlay = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, screen);
pY = (unsigned char*)malloc(w*h);
pU = (unsigned char*)malloc(w*h/4);
pV = (unsigned char*)malloc(w*h/4);
SDL_LockSurface(screen);
SDL_LockYUVOverlay(overlay);
fp = fopen("1.yuv", "rb");
while (!feof(fp))
{
fread(pY, 1, w*h, fp);
fread(pU, 1, w*h/4, fp);
fread(pV, 1, w*h/4, fp);
memcpy(overlay->pixels[0], pY, w*h);
memcpy(overlay->pixels[1], pV, w*h/4);
memcpy(overlay->pixels[2], pU, w*h/4);
SDL_UnlockYUVOverlay(overlay);
SDL_UnlockSurface(screen);
rect.w = w;
rect.h = h;
rect.x = rect.y = 0;
SDL_DisplayYUVOverlay(overlay, &rect);
SDL_Delay(40);
i += 1;
}
fclose(fp);
free(pY);
free(pU);
free(pV);
SDL_FreeYUVOverlay(overlay);
SDL_FreeSurface(screen);
//Quit SDL
SDL_Quit();
return 0;
}
编译命令:arm-linux-gcc yuv420.c -o yuv -lpthread libSDL.a
参考:MFC下用sdl 显示bmp、rgb、yuv http://blog.csdn.net/mao0514/article/details/10007873