• 嵌入式linux------SDL移植(am335x下显示yuv420) 分类: TI-AM335X arm-linux-Ubuntu ffmpeg-SDL-VLC-Live555 2015-07-28 16:35 136人阅读 评论(0) 收藏


    #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

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    day 1 认识js
    day2,request对象
    day3
    day 14 函数的嵌套,作用域
    命名空间(名称空间)
    day 13 函数
    day 11(2) 集合
    day 11 字典拆包
    字典
    两周英语函数(记)
  • 原文地址:https://www.cnblogs.com/mao0504/p/4705496.html
Copyright © 2020-2023  润新知