先贴上代码:
openvideo中:
int open_video( char *fileptr,fb_v41 *vd ,int dep,int pal,int width,int height)
{
// 打开视频设备
if ((vd->fd = open(fileptr, O_RDWR)) < 0)
{
perror("v4l_open:");
return ERR_VIDEO_OPEN;
}
// 获取设备
if (ioctl(vd->fd, VIDIOCGCAP, &(vd->capability)) < 0)
{
perror("v4l_get_capability:");
return ERR_VIDEO_GCAP;
}
// 获取图象
if (ioctl(vd->fd, VIDIOCGPICT, &(vd->picture)) < 0)
{
perror("v4l_get_picture");
return ERR_VIDEO_GPIC;
}
// 设置图象
vd->picture.palette = pal; // 调色板
vd->picture.depth = dep; // 像素深度
vd->mmap.format =pal;
if (ioctl(vd->fd, VIDIOCSPICT, &(vd->picture)) < 0)
{
perror("v4l_set_palette");
return ERR_VIDEO_SPIC;
}
//
vd->mmap.width = width; // width;
vd->mmap.height = height; // height;
vd->mmap.format = vd->picture.palette;
vd->frame_current = 0;
vd->frame_using[0] = 0;
vd->frame_using[1] = 0;
// 获取缓冲影射信息
if (ioctl(vd->fd, VIDIOCGMBUF, &(vd->mbuf)) < 0)
{
perror("v4l_get_mbuf");
return -1;
}
// 建立设备内存影射
vd->map = mmap(0, vd->mbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED, vd->fd, 0);
if ( vd->map < 0)
{
perror("v4l_mmap_init:mmap");
return -1;
}
printf("The video device was opened successfully.\n");
// return get_first_frame(vd);
return 0;
}
主函数中这样调用:
ret = open_video( V4L_FILE, &vd ,
16, // 像素深度
VIDEO_PALETTE_RGB24, // 设置调包板
240,160 );
运行结果如下:
The framebuffer device was opened successfully.
480x272, 16bpp, xoffset=0 ,yoffset=0