当前位置: 技术问答>linux和unix
TV采集卡不支持VIDEO_OVERLAY,如何在SDL中显示?
来源: 互联网 发布时间:2016-02-14
本文导语: 我的视频采集卡为em2821,(sa7113a,em2820),我采用V4L2已经能够采集到YUYV格式的视频帧,但不能使用SDL来显示,设备只支持VIDEO CAPTURE,不支持VIDEO OVERLAY,我是不是要将YUYV转换成RGB的格式?如何转?另外如何在GTK+中显示...
我的视频采集卡为em2821,(sa7113a,em2820),我采用V4L2已经能够采集到YUYV格式的视频帧,但不能使用SDL来显示,设备只支持VIDEO CAPTURE,不支持VIDEO OVERLAY,我是不是要将YUYV转换成RGB的格式?如何转?另外如何在GTK+中显示采集到的图像/
#include
#include
#include
#include
#include
#include
#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 = %dn",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,"P6n%d%dn255n",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)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);
videoinput_request_buffers(vidin);
videoinput_init_mmap(vidin);
init_screen(width,height,16);
videoinput_start_capture(vidin);
//videoinput_get_frame(vidin,print_orginal_frame);
//videoinput_get_frame(vidin,frame_to_ppm);
videoinput_frame_loop(vidin,sdl_handler);
//videoinput_get_frame(vidin,sdl_handler);
videoinput_stop_capture(vidin);
videoinput_close(vidin);
// gtk_main();
return 0;
}
#include
#include
#include
#include
#include
#include
#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 = %dn",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,"P6n%d%dn255n",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)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);
videoinput_request_buffers(vidin);
videoinput_init_mmap(vidin);
init_screen(width,height,16);
videoinput_start_capture(vidin);
//videoinput_get_frame(vidin,print_orginal_frame);
//videoinput_get_frame(vidin,frame_to_ppm);
videoinput_frame_loop(vidin,sdl_handler);
//videoinput_get_frame(vidin,sdl_handler);
videoinput_stop_capture(vidin);
videoinput_close(vidin);
// gtk_main();
return 0;
}
|
我想问作者:
"videoinput.h"是自己创建的头文件吗?
SDl窗口怎么和采集设备连接起来,就是程序中的videoinput_start_capture(vidin) 函数具体是怎么实现的?
我也正在做此类程序,有些迷茫,想探讨一下。
email:zhuyating02@163.com
"videoinput.h"是自己创建的头文件吗?
SDl窗口怎么和采集设备连接起来,就是程序中的videoinput_start_capture(vidin) 函数具体是怎么实现的?
我也正在做此类程序,有些迷茫,想探讨一下。
email:zhuyating02@163.com
|
v4l设置读取格式RGB24,出来就是RGB流。