Rh9 for linux video capture

Source: Internet
Author: User


Rh9 supports linux video capture. In rh9, linux videos are captured in bmp format. /*************************************** * ************ // * V4lgrab. h *//**//******************************** * ******************/# ifndef _ V4LGRAB_H __# define _ V4LGRAB_H _ # include <stdio. h> // typedef enum {FALSE = 0, TRUE = 1, OK = 2} BOOL; // # define SWAP_HL_WORD (x) {(x) = (x) <8) | (x)> 8);} // # define SWAP_HL_DWORD (x) {(x) = (x) <24) | (x)> 24) | (x) & 0xff0000)> 8) | (x) & 0xff00) <8 );} # Define FREE (x) if (x) {free (x); (x) = NULL;} typedef unsigned char BYTE; typedef unsigned into word; typedef unsigned long DWORD;/* www.2cto.com # pragma pack (1) typedef struct tagBITMAPFILEHEADER {WORDbfType; // the flag of bmp, value is "BM" DWORD bfSize; // size BMP file, unit is bytes DWORD bfReserved; // 0 DWORD bfOffBits; // must be 54} BITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER {DWOR D biSize; // must be 0x28 DWORD biWidth; // DWORD biHeight; // WORDbiPlanes; // must be 1 WORDbiBitCount; // DWORD biCompression; // DWORD biSizeImage; // DWORD biXPelsPerMeter; // DWORD biYPelsPerMeter; // DWORD biClrUsed; // DWORD break; //} BITMAPINFOHEADER; typedef struct break {BYTE rgbBlue; BYTErgbGreen; BYTErgbRed ;} RGBQUAD; */# if defined (_ cplusplus) extern "C" {/* Make sure we have C-declarations in C ++ programs */# endif // if successful return 1, or else return 0int openVideo (); int closeVideo (); // data space used to store data. size Space void getVideoData (unsigned char * data, int size); # if defined (_ cplusplus )} # endif/_ V4LGRAB_H ___ www.2cto.com /**************************** * ************************ // * v4lgrab. c *//**//******************************** ***** * **************/# 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/types. h> # include <linux/videodev. h> # include "v4lgrab. h "# define TRUE 1 # define FALSE 0 # define WIDTHBYTES (I) (I + 31)/32*4) # define FILE_VIDEO "/dev/video0" // # define BMP "image.bmp" # define IMAGEWIDTH 176 # define IMAGEHEIGHT 144 stat Ic int fd; static struct video_capability cap; static struct video_window win; static struct video_picture vpic; int openVideo () {www.2cto.com // Open video device fd = open (FILE_VIDEO, O_RDONLY ); if (fd <0) {perror (FILE_VIDEO); return (FALSE);} // Get capabilities if (ioctl (fd, VIDIOCGCAP, & cap) <0) {perror ("VIDIOGCAP"); printf ("(" FILE_VIDEO "not a video4linux device ?) /N "); close (fd); return (FALSE);} // Get the video overlay window if (ioctl (fd, VIDIOCGWIN, & win) <0) {perror ("VIDIOCGWIN"); close (fd); return (FALSE);} // Set the video overlay window win. width = IMAGEWIDTH; win. height = IMAGEHEIGHT; if (ioctl (fd, VIDIOCSWIN, & win) <0) {perror ("VIDIOCSWIN"); close (fd); return (FALSE );;} // Get picture properties if (ioctl (fd, VIDIOCGPICT, & vpic) <0) {perror ("V IDIOCGPICT "); close (fd); return (FALSE);} // if (cap. type & VID_TYPE_MONOCHROME) {//} else {vpic. depth = 24; vpic. palette = VIDEO_PALETTE_RGB24; if (ioctl (fd, VIDIOCSPICT, & vpic) <0) {printf ("Unable to find a supported capture format. /n "); return (FALSE);} www.2cto.com //} return (TRUE);} int closeVideo () {if (fd! =-1) {close (fd); return (TRUE);} return (FALSE);} void getVideoData (unsigned char * data, int size) {size = read (fd, data, size);}/* int main (int argc, char ** argv) {FILE * fp; BITMAPFILEHEADER bf; BITMAPINFOHEADER bi; unsigned char * buffer; int I; fp = fopen (BMP, "wb"); if (! Fp) {perror (BMP); exit (1) ;}if (openVideo () = FALSE) {return (-1) ;}www.2cto.com // Set BITMAPINFOHEADER bi. biSize = 40; bi. biWidth = win. width; bi. biHeight = win. height; bi. biPlanes = 1; bi. biBitCount = 24; bi. biCompression = 0; bi. biSizeImage = WIDTHBYTES (bi. biWidth * bi. biBitCount) * bi. biHeight; bi. biXPelsPerMeter = 0; bi. biYPelsPerMeter = 0; bi. biClrUsed = 0; bi. biClrImportant = 0; // Set BITM APFILEHEADER bf. bfType = 0x4d42; bf. bfSize = 54 + bi. biSizeImage; bf. bfReserved = 0; bf. bfOffBits = 54; buffer = malloc (bi. biSizeImage); if (! Buffer) {printf ("Out of memory. /n "); exit (1) ;}for (I = 0; I <20; I ++) getVideoData (buffer, bi. biSizeImage); fwrite (& bf, 14, 1, fp); fwrite (& bi, 40, 1, fp); fwrite (buffer, bi. biSizeImage, 1, fp); printf ("get bmp form video/t [OK]/n"); fclose (fp); closeVideo (); return 0 ;} */author fengyv

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.