Analysis of Video4linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. • Video4linux (V4L for short) is the kernel driver for video devices in linux.
• Video4linux2 is now available and has not been added to the Linux kernel. You need to download the patch by yourself.
• In Linux, a video device is a device file that can be read and written just like a common file.
• Camera under/dev/video0
1. Enable the video device:
2. Read Device Information
3. Change the current device settings (if necessary)
4. Two Methods for video collection: (failed) L
1. Memory ing
2. Read from the device directly
5. process the collected video (not done)
6. Disable the video device.
Data structure defined for the program
• Typedef struct v4l_struct
•{
• Int fd;
• Struct video_capability capability;
• Struct video_channel [4];
• Struct video_picture picture;
• Struct video_window window;
• Struct video_capture capture;
• Struct video_buffer buffer;
• Struct video_mmap mmap;
• Struct video_mbuf mbuf;
• Unsigned char * map;
• Int frame;
• Int framestat [2];
•} Vd;
• 1. video_capability
• Contains basic device information (device name, supported maximum and minimum resolutions, and signal source information)
• Contained components:
• Name [32] // device name
• Maxwidth, maxheight, minwidth, and minheight
• Channels // Number of signal sources
• Type // capture, color, black/white, and cropping. Values such as VID_TYPE_CAPTURE
2 • video_picture
• Various attributes of images collected by devices
• Brightness 0 ~ 65535
• Hue
• Color
• Contrast
• Whiteness
• Depth // 24
• Palette // VIDEO_PALETTE_RGB24
3 • video_channel attributes of each signal source
Channel // signal source number
Name
Tuners
Type VIDEO_TYPE_ TV | IDEO_TYPE_CAMERA
Norm Standard
4
• Video_window // contains the capture area information
X coordinates in windows.
Y x coordinates in windows.
Width The width of the image capture.
Height The height of the image capture.
Chromakey A host order RGB32 value for the chroma key.
Flags Additional capture flags.
Clips A list of clipping rectangles. (Set only)
Clipcount The number of clipping rectangles. (Set only)
5 • video_mbuf
Information of frames mapped using mmap
Size // the size of each frame
Frames // The maximum number of supported Frames
Offsets // The offset of each frame to the base address
6 • video_buffer bottom layer buffer description
Void * baseBase physical address of the buffer
Int height Height of the frame buffer
Int widthWidth of the frame buffer
Int depthDepth of the frame buffer
Int bytesperline Number of bytes of memory between the start of two adjacent lines
The actually displayed part is generally smaller than the part described in it.
7 • video_mmap // used for mmap
Key steps
• Work done in the initialization phase
• Int ioctl (int fd, ind cmd ,...) Abbreviation of input output control
• It is used to "talk" with devices ".
• If the driver supports ioctl, you can use the ioctl function in your program to control the I/O channel of the device.
• Fd: The file descriptor of the device. cmd: the control command of the user program on the device. The ellipsis is generally a parameter indicating the type length.
• 1. Open the video:
• Open ("/dev/video0", vd à fd );
• Disable close ("/dev/video0", vd à fd) for video devices );
• 4. Change the value of the component in video_picture.
• Add a value to the component before calling VIDIOCSPICT
• Eg.
• Vd-> picture. color = 65535;
• If (ioctl (vd-> fd, VIDIOCSPICT, & (vd-> picture) <0)
•{
• Perror ("VIDIOCSPICT ");
• Return-1;
•}
• 5. initialize the channel
• Information in vd-> capability must be obtained first.
• For (I = 0; I <vd-> capability. channels; I ++)
•{
• Vd-> channel
. Channel = I;
• If (ioctl (vd-> fd, VIDIOCGCHAN, & (vd-> channel) <0)
•{
• Perror ("v4l_get_channel :");
• Return-1;
•}
•}
• The first method for capturing images: Using mmap (memory ing)
• Mmap () system calls allow processes to implement shared memory by ing to the same common file. After a common file is mapped to the process address space, the process can access the file like accessing the common memory without calling read (), write (), and other operations.
• Two Different Processes A and B share the memory, which means that the same physical memory is mapped to the process address space of process A and process B. Process A can instantly view the updates to data in the shared memory of process B, and vice versa.
• One obvious advantage of using shared memory communication is high efficiency, because the process can directly read and write the memory without any data copying.
• 1. Set picture attributes
• 2. initialize video_mbuf to obtain the mapped buffer information.
? Ioctl (vd-> fd, VIDIOCGMBUF, & (vd-> mbuf ))
• 3. You can modify the current settings of video_mmap and frame status.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.