Hi,
there is a really brain-dead one :-)
8<------------------------ begin
---------------------------------------------------
/*
v4l single frame grabber sample
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
#include <linux/videodev.h>
const int mywidth = 640; // !!!!!!!
const int myheight = 480; // NTSC-J - pls, put your here
static struct video_capability capability;
static int fd = -1;
static int ret_bytes,vfd;
static char *map = NULL;
static char *dest_buf=NULL;
static char src_buf[691200];
static struct video_mbuf gb_buffers;
static struct video_mmap my_buf;
int main(void)
{
int mymode;
int no_bytes,i;
char my_video_dev[100] = "/dev/video0";
// Open video device
if (-1 == (fd = open(my_video_dev, O_RDWR)))
{
printf("Error opening device: %s\n", my_video_dev);
goto err;
}
// Get video device captions
if (-1 == ioctl(fd,VIDIOCGCAP,&capability))
{
printf("Error: ioctl(fd,VIDIOCGCAP,&capability)\n");
goto err;
}
fcntl(fd,F_SETFD,FD_CLOEXEC);
// Get number and size of the internal buffers
if (-1 == ioctl(fd, VIDIOCGMBUF, &gb_buffers))
{
printf("Error: Error getting buffers, I think\n");
goto err;
}
printf("Memory map buffer:\nsize: %d\nframes: %d\n\n",
gb_buffers.size,
gb_buffers.frames);
// Mapping internal driver's buffers to the user space
map = mmap(0, mywidth * myheight * 2 + 4096, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
if (map == NULL)
{
printf("Error: mmap returned NULL\n");
goto err;
}
printf("Memory mapped to 0x%08x\n", map);
// set capture dimensions and format
my_buf.width = mywidth;
my_buf.height = myheight;
my_buf.format = VIDEO_PALETTE_RGB565;
my_buf.frame = 0;
// start capture
if (-1 == ioctl(fd, VIDIOCMCAPTURE, &my_buf))
{
printf("Error: Grabber chip can't sync\n");
goto err;
}
// wait for end of the frame capturing
if (-1 == ioctl(fd, VIDIOCSYNC, &my_buf.frame))
{
printf("Error on sync!\n");
goto err;
}
memcpy(src_buf, map, mywidth * myheight * 2);
{
int i, j, k;
char r, g, b;
unsigned short *ptr = (unsigned short *)src_buf;
unsigned short word;
char *ppm_hdr = "P6\n# CREATOR: anonimous :-) (RGB565)\n640 480\n255\n";
int vfd = open("video-data.ppm",O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
k = 0;
write(vfd, ppm_hdr, strlen(ppm_hdr));
for(i = 0; i < myheight; i++)
for(j = 0; j < mywidth; j++)
{
word = ptr[k];
r = (word >> 8) & 0xf8;
g = (word >> 3) & 0xfc;
b = (word << 3) & 0xf8;
write(vfd, &r, 1);
write(vfd, &g, 1);
write(vfd, &b, 1);
k++;
}
close(vfd);
}
munmap(map, mywidth * myheight * 2 + 4096);
printf("Press enter to quit\n");
getchar();
return 0;
err:
return -1;
}
8<---------------------------- end
------------------------------------------------------------------------------------
Mauricio Henriquez wrote:
Hi:
My name is Mauricio and I write you from Chili.
I have a Phoebe TV-Master+FM working fine with my redhat 8 system,
I like to do some basic test and I need some basic "C" or "C++"
example code about how to set and capture a image from the capture
card and saved in some image format in my hard drive. If any of you
have some basic sample code I very appriciate.
For advance thanks.
Mauricio Henriquez