linux下V4L視頻採集總結

來源:互聯網
上載者:User

視頻採集,調用V4L模組參數進行視頻未經處理資料的採集。熟悉/include/linux/videodev.h,根據這個標頭檔來定義自己的video device的資料結構,下面是幾個重要的資料結構,定義在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;

用mmap方法做視頻採集最重要是以下兩個資料結構
struct video_mmap
{
 unsigned int frame;  /* Frame (0 - n) for double buffer */
 int  height,width;
 unsigned int format;  /* should 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];
};
一般來說,可以通過ioctl相應的get參數擷取這幾個資料結構中的資料,使用mmap方法就要知道記憶體影射區buffers的大小,本課題使用的OV511 WebEye V2000系列網路攝影機都是double buffer,即buffer[0],buffer[1];整個buffers的大小為struct video_mbuf的size值,frames此時應該為2,offsets為位移量。在使用mmap函數以後,返回的指標就指在offsets[0]上,此時的offsets[0]可以看為0,offsets[1]的大小則應該等於一個buffer的大小。
在採集之前不要忘記對視頻參數的設定,重要的參數有fromat,dept,各個網路攝影機對其自身的參數設定都不一樣,為了獲得更好的軟體相容性,可以做一個format參數的probe函數,測試所有可能的fromat值是否受硬體網路攝影機的支援,demo代碼如下:
int pal[] ={VIDEO_PALETTE_JPEG,VIDEO_PALETTE_YUV420P,VIDEO_PALETTE_RGB24,VIDEO_PALETTE_RGB565,VIDEO_PALETTE_RGB32};
struct video_picture pict;
//定義所有可能的palette format值
ioctl (vd->fd, VIDIOCGPICT, &pict);
//通過ioctl對video_picture pict的get命令,把包含format的參數儲存到video_picture pict中
for(i = 0; i < 5 ; i++)
//做一個迴圈,驗證上述5個format的可用性
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]);
     
     }
//設定成功則返回大於0值,返回小於0則說明該format值不可用
//實驗證明WebeyeV2000隻支援VIDEO_PALETTE_YUV420P,而Z-Star的對上面五種format都支援
 if (ioctl (vd->fd, VIDIOCGPICT, &pict) < 0)
      {
        printf("Couldnt get palette %d /n", pal[i]);
     
      }

先幹活去了,明天接著寫mmap的採集和處理                                                 

to be continue........

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.