這次是在linux下開發網路攝影機的程式,主要用的是video4linux來做的,介面用qt來實現,開始準備用framebuffer來直接寫屏但是效果不怎麼好,後來就用qt來做了,這樣用起來效果還蠻好的,幀率也可以,可以上到30fps;運用v4l來編程主要掌握其api,要提高幀率最重要的是用到記憶體映射,其實用qt和framebuffer的時候都要用到記憶體映射來做,只有這樣才可以達到較高的幀率,不過要注意資源的利用問題.mmap後一定要munmap.對於framebuffer是很有意思的一個東西,特別是驅動的設計.
代碼如下:
1.open device:
video_dev = open("\dev\video0",O_RDWR));
2.get the information of the video device
struct video_capability video_cap;
memset(&video_cap,0,sizeof(video_cap));
if(ioctl(video_dev,VIDIOCGCAP,&video_cap) == -1)
{
perror("Cann't get the information of the video device");
close(video_dev);
exit(1);
}
3.get the information of the channels
struct video_channel video_chan;
memset(&video_chan,0,sizeof(video_chan));
for(channel = 0;channel < video_cap.channels;channel++)
{
video_chan.channel = channel;
if(ioctl(video_dev,VIDIOCGCHAN,&video_chan) == -1)
{
perror("Cann't get the information of the channels");
close(video_dev);
exit(3);
}
if(video_chan.type == VIDEO_TYPE_TV)
{
#ifdef DEBUG
printf("NO.%d channel is %s,type is
tv!\n",channel,video_chan.name);