v4l2编程经典_
Generated by Foxit PDF Creator © Foxit Software
For evaluation only.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define USB_VIDEO_DEV "/dev/ video0"
#define FILE_NAME "/tmp/1.jpg"
#define STILL_IMAGE -1
#define VIDEO_START 0
#define VIDEO_STOP 1
#define VIDEO_PALETTE_RAW_JPEG 20
#define VIDEO_PALETTE_JPEG 21
static int debug = 1;
int get_jpegsize(unsigned char *buf, int size)
{
int i;
for(i = 1024; i < size; i++)
{
if ( (buf[i] == 0xFF)&&(buf[i+1] == 0xD9)) return i+2;//jpeg 文件格式中是以 0xFF 0xD9 结尾
的,
// 以此判断文件大小
}
return -1;
}
int main(int argc, char *argv[])
{
int usb_camera_fd = -1,framesize=0,jpegsize=0;
char *usb_video_dev = USB_VIDEO_DEV; //"/dev/ video0"
char *filename = FILE_NAME;// "/tmp/1.jpg"
1
Generated by Foxit PDF Creator © Foxit Software
For evaluation only.
FILE *fp;
struct video_capability video_caps;
struct video_channel video_chan;
struct video_picture video_pic;
struct video_mbuf video_mbuffer;
struct video_mmap vid_mmap;
unsigned char *mapaddr=NULL,*framebuffer=NULL,*destbuffer=NULL;
usb_camera_fd = open(usb_video_dev,O_RDWR);//打开设备,可读写,也即打开"/dev/ video0"
// usb_camera_fd 是设备号,open 成功则返回设备号
if (usb_camera_fd == -1)
{
fprintf(stderr,"Can't open device