日期:2014-05-16  浏览次数:20857 次

TV采集卡不支持VIDEO_OVERLAY,如何在SDL中显示?
我的视频采集卡为em2821,(sa7113a,em2820),我采用V4L2已经能够采集到YUYV格式的视频帧,但不能使用SDL来显示,设备只支持VIDEO   CAPTURE,不支持VIDEO   OVERLAY,我是不是要将YUYV转换成RGB的格式?如何转?另外如何在GTK+中显示采集到的图像/

#include   <stdio.h>
#include   <gtk/gtk.h>
#include   <glade/glade.h>

#include   <sys/types.h>
#include   <sys/time.h>
#include   <SDL/SDL.h>

#include   "videoinput.h "
#include   "colorspace.h "


static   int   file_index;
static   int   width=640;
static   int   height=480;

static   unsigned   int   curr_frame=0;

int   print_orginal_frame(void   *data)
{
// g_print( "%s ",data);
g_print( ". ");
// g_print( "current   frame   =   %d\n ",curr_frame++);

}

int   frame_to_ppm(void   *data)
{

FILE*   fp;
int   i;


fp=fopen( "test.ppm ", "wb ");

void   *rgb24=malloc(width*height*2);
// yuv2rgb_init();
//yuv422_to_rgb24(rgb24,data,width*height);
yuyv2rgb24(rgb24,data,width,height);


fprintf(fp, "P6\n%d%d\n255\n ",width,height);
fwrite(rgb24,height,3*width,fp);
fclose(fp);


return   0;
             
}

SDL_Surface   *screen   ,*image;
SDL_Overlay   *overlay;


void   init_screen(int   width,int   height,int   bpp)
{

if(SDL_Init(SDL_INIT_VIDEO) <0){
printf( "init   sdl   video   and   audio   error:%s\n ",SDL_GetError());
}

atexit(SDL_Quit);

screen=SDL_SetVideoMode(width,height,bpp,SDL_HWSURFACE);
if(!screen)printf( "unable   to   set   video   mode:   %s\n ",SDL_GetError());

overlay=SDL_CreateYUVOverlay(width,height,SDL_YUY2_OVERLAY,screen);
if(!overlay)printf( "unable   to   create   yuv   overlay:%s\n ",SDL_GetError());

}

int   sdl_handler(void   *data)
{
SDL_Rect   rect;
SDL_Event   event;

rect.x=rect.y=0;
rect.w=width;
rect.h=height;

// overlay-> pixels=(unsigned   char*)data;
// printf( "%s ",data);

       
SDL_UnlockYUVOverlay(overlay);
SDL_DisplayYUVOverlay(overlay,&rect);
SDL_LockYUVOverlay(overlay);

while(SDL_PollEvent(&event)){
if(event.type==SDL_QUIT)
exit(0);
}


return   0;
}


int   main(int   argc,   char   *argv[]){

// GtkWidget*   window;
//GladeXML*   xml;

videoinput_t   *vidin;

//gtk_init(&argc,&argv);

//xml=glade_xml_new( "ultrasound.glade ",NULL,NULL);
//glade_xml_signal_autoconnect(xml);

// window=glade_xml_get_widget(xml, "main_window ");

//gtk_widget_hide(window);
/*full   screen*/
//gtk_window_fullscreen((GtkWindow*)window);

// gtk_widget_show(window);


vidin=videoinput_new( "/dev/video0 ");

/*set   format*/
videoinput_set_fmt(vidin,width,height);