Embedded video acquisition Programming ideas (Video 4 Linux)-Go

Source: Internet
Author: User

 

Transferred from: http://zyg0227.blog.51cto.com/1043164/271954

1. The Linux kernel has video for Linux abbreviation v4l. V4L is the basis of Linux image system and embedded image, is a set of APIs supporting image equipment in Linux kernel, with appropriate video capture card and video capture card driver, V4L can achieve image acquisition, AM/FM radio, image codec, channel switching and other functions. At present, v4l is mainly used in image streaming system and embedded image system, and its application scope is quite wide, for example: distance teaching, telemedicine, video conferencing, video surveillance, videophone, etc. The V4L is a 2-tier architecture, with the v4l driver at the top and the image device driver at the bottom. 2. Connect the USB camera, the hardware device under Linux is as a file access, so just look under/dev/, generally video0. When the camera is connected to the video capture terminal via the USB interface, the camera video data acquisition can be realized by invoking the V4L APIs in the program to read the device file Video0. The main process is as follows: 1) To open a device file: [CPP]View PlainCopy
    1. int V4l_open (char *dev, V4l_device *vd) {}; Open the device file of the image source;
2) Initialize Picture: [CPP]View PlainCopy
    1. int v4l_get_picture (V4l_device *vd) {}; //Get the input image information;
3) Initialize channel[CPP]View PlainCopy
    1. int V4l_get_channels (V4l_device *vd) {}; //Get information on each channel;
4) Set Norm to channel: [CPP]View PlainCopy
    1. int V4l_set_norm (V4l_device *vd, int norm) {}; Norm for all channel settings;
5) Device address mapping[CPP]View PlainCopy
    1. V4l_mmap_init (V4l_device *vd) {}; //Return the address where the image data is stored;
6) Initialize the mmap buffer: [CPP]View PlainCopy
    1. int V4l_grab_init (V4l_device *vd, int width, int height) {};
7) Video capture synchronization[CPP]View PlainCopy
    1. int V4l_grab_sync (V4l_device *vd) {};
8) video capture: [CPP]View PlainCopy
    1. int device_grab_frame () {}.
For the USB camera device file/dev/video0 video capture program flow, first call the V4l_open () function to open the video device, the device file opened successfully using V4l_get_capability () Read device information, Then select the appropriate video capture mode for video capture and processing of the captured image, and finally call the V4l_close () function to close the video device file. There are two kinds of video collection methods, one is read () Direct reading, the other is mmap () memory mapping mode. mmap () modeBy mapping the same file between processes, each process can access the file as if it were accessing normal memory.       In addition, the mmap () method accelerates I/O access and improves efficiency, so the memory-mapped approach is often used to obtain the video. Data structures supported by Video for Linux and their uses: video_capability: basic information of the device (device name, supported resolution, etc.); video_picture: The various properties of the captured image; Video_channel: The properties of each signal source; video_windows: Contains information about the acquisition area; Video_mbuf: The use of mmap mapped frame information; Video_mmap: For Mmap mode. The camera video can be collected into memory with the above operation. Video data that is captured in memory can be saved as a file or compressed and published to the Internet over a network.

Embedded video acquisition Programming ideas (Video 4 Linux)-Go

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.