Summary of v4l video collection in Linux

Source: Internet
Author: User

Video Acquisition: Call the v4l module parameters to collect original video data. Familiar with/include/Linux/videodev. H. Define the data structure of your video device based on this header file. The following are several important data structures defined in videodev. h.
Struct video_mmap vmmap;
Struct video_capability videocap;
Struct video_mbuf videombuf;
Struct video_picture videopict;
Struct video_window videowin;
Struct video_channel videochan;
Struct video_param videoparam;

The most important thing to use MMAP for video collection is the following two data structures:
Struct video_mmap
{
Unsigned int frame;/* frame (0-N) for double buffer */
Int height, width;
Unsigned int format;/* shocould be video_palette _**/
};

# Define video_max_frame 32

Struct video_mbuf
{
Int size;/* total memory to map */
Int frames;/* frames */
Int offsets [video_max_frame];
};
Generally, you can obtain the data in these data structures through the get parameter corresponding to IOCTL. The MMAP method requires you to know the size of buffers in the memory shooting area, the ov511 webeye v2000 series cameras used in this topic are double buffer, namely buffer [0], buffer [1]; the size of the entire buffers is the size value of struct video_mbuf, frames should be 2 at this time, and offsets should be offset. After the MMAP function is used, the returned pointer is on offsets [0]. At this time, offsets [0] can be regarded as 0, the offsets [1] size should be equal to the size of a buffer.
Do not forget to set video parameters before collection. Important Parameters include fromat and dept. Each camera has different parameter settings for itself. In order to achieve better software compatibility, you can create a format parameter probe function to test whether all possible fromat values are supported by the hardware camera. The Demo code is as follows:
Int pal [] = {video_palette_jpeg, video_palette_yuv420p, video_palette_rgb24, video_palette_rgb565, video_palette_rgb32 };
Struct video_picture PICT;
// Define all possible palette format values
IOCTL (vd-> FD, vidiocgpict, & PICT );
// Use IOCTL to get the video_picture Pict and save the parameter containing the format to video_picture Pict.
For (I = 0; I <5; I ++)
// Make a loop to verify the availability of the above five formats
PICT. palette = pal [I];

Printf ("Try palette % d depth % d/N", Pict. palette, Pict. Depth );
If (IOCTL (vd-> FD, vidiocspict, & PICT) <0)
{
Printf ("couldnt set palette first try % d/N", pal [I]);

}
// If the setting is successful, a value greater than 0 is returned. If the returned value is smaller than 0, the format value is unavailable.
// The experiment proves that webeyev2000 only supports video_palette_yuv420p, while Z-star supports the preceding five formats.
If (IOCTL (vd-> FD, vidiocgpict, & PICT) <0)
{
Printf ("couldnt get palette % d/N", pal [I]);

}

Work first, and write MMAP collection and processing tomorrow.

To be continue ........

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.