📄 video.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.zyinside.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: video.c
** Last modified Date: 2006-01-14
** Last Version: v1.0
** Description:
** Note:
**------------------------------------------------------------------------------------------------------
** Created By: 周立山
** Created date: 2006-01-01
** Version: v1.0
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
********************************************************************************************************/
// arm-linux-gcc -s -Wall -I/zls/2410/kernel2.4.18/include -Wstrict-prototypes video.c -o video.ko
// mknod /dev/video0 c 81 0
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <linux/videodev.h>
#define FILE "/dev/video0" // 定义打开文件的名称
int main(void)
{
struct video_capability cap; // 设备的性能
struct video_picture vpic; // 设备的图片特性
struct video_mbuf mbuf; // 设备缓冲区信息
int fd = open(FILE, O_RDONLY); // 打开设备
if (fd < 0) {
perror(FILE);
exit(1);
}
printf("\n==================Get struct video_capability=======================\n");
if (ioctl(fd, VIDIOCGCAP, &cap) < 0) { // 获取设备性能描述数据结构
perror("VIDIOGCAP");
fprintf(stderr, "(" FILE " not a video4linux device?)\n");
close(fd);
exit(1); }
printf(cap.name);printf(", Type:%d\n",cap.type);
printf("Maxwidth:%d,Maxheight:%d\n",cap.maxwidth ,cap.maxheight);
printf("Minwidth:%d,Minheight:%d\n",cap.minwidth,cap.minheight);
printf("Channels:%d,Audios:%d\n",cap.channels,cap.audios);
printf("\n====================Get struct video_mbuf==========================\n");
if (ioctl(fd, VIDIOCGMBUF, &mbuf) < 0) { // 获取设备性能描述数据结构
perror("VIDIOGCAP");
fprintf(stderr, "(" FILE " not a video4linux device?)\n");
close(fd);
exit(1); }
printf("Memery buffer size:%d\n",mbuf.size);
printf("Memery buffer frames:%d\n",mbuf.frames );
printf("\n===================Get struct video_picture=========================\n");
if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) { // 获取图象特性数据结构
perror("VIDIOCGPICT");
close(fd);
exit(1); }
printf("Brightness:%d,Hue:%d,Colour:%d\n",vpic.brightness,vpic.hue,vpic.colour);
printf("Contrast:%d,Whiteness:%d(Black and white only)\n",vpic.contrast,vpic.whiteness);
printf("Capture depth:%d,Palette:%d\n",vpic.depth,vpic.palette);
printf("\nSet vpic.palette to VIDEO_PALETTE_RGB565,and vpic.depth to 16.\n");
vpic.palette=VIDEO_PALETTE_RGB565; // 设置调色板
vpic.depth=16; // 设置象素深度
if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) { // 设置图像特性
fprintf(stderr, "Unable to find a supported capture format.\n");
close(fd);
exit(1);
}
printf("\n===================Get struct video_picture=========================\n");
if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) { // 获取图象特性数据结构
perror("VIDIOCGPICT");
close(fd);
exit(1);
}
printf("Brightness:%d,Hue:%d,Colour:%d\n",vpic.brightness,vpic.hue,vpic.colour);
printf("Contrast:%d,Whiteness:%d(Black and white only)\n",vpic.contrast,vpic.whiteness);
printf("Capture depth:%d,Palette:%d\n",vpic.depth,vpic.palette);
close(fd); // 关闭设备
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -