linux视频采集命令 linux视频处理( 二 )


VideoBuffer* buffers = calloc( req.count, sizeof(VideoBuffer) );
printf("sizeof(VideoBuffer) is %d\n",sizeof(VideoBuffer));
struct v4l2_buffer buf;
for (numBufs = 0; numBufsreq.count; numBufs++)
{
memset( buf, 0, sizeof(buf) );
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = numBufs;
if (ioctl(fd, VIDIOC_QUERYBUF, buf)0)
{
printf("VIDIOC_QUERYBUF error\n");
//return -1;
}
printf("buf len is %d\n",sizeof(buf));
//内存映射
buffers[numBufs].length = buf.length;
buffers[numBufs].offset = (size_t) buf.m.offset;
buffers[numBufs].start = mmap (NULL, buf.length,PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset);
printf("buffers.length = %d,buffers.offset = %d ,buffers.start[0] = %d\n",buffers[numBufs].length,buffers[numBufs].offset,buffers[numBufs].start[0]);
printf("buf2 len is %d\n",sizeof(buffers[numBufs].start));
if (buffers[numBufs].start == MAP_FAILED)
{
perror("buffers error\n");
//return -1;
}
if (ioctl (fd, VIDIOC_QBUF, buf)0)
{
printf("VIDIOC_QBUF error\n");
//return -1;
}
}
7. 开始视频的采集 。
enum v4l2_buf_type type;
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl (fd, VIDIOC_STREAMON, type)0)
{
printf("VIDIOC_STREAMON error\n");
// return -1;
}
8. 出队列以取得已采集数据的帧缓冲 , 取得原始采集数据 。VIDIOC_DQBUF, 将缓冲重新入队列尾,这样可以循环采集 。VIDIOC_QBUF
if (ioctl(fd, VIDIOC_DQBUF, buf)0)
{
perror("VIDIOC_DQBUF failed.\n");
//return -1;
}
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
unsigned char *ptcur = buffers[numBufs].start;
DEBUG("buf.bytesused = %d \n",buf.bytesused);
int i1;
for(i1=0; i1buf.bytesused; i1++)
{
if((buffers[numBufs].start[i1] == 0x000000FF)(buffers[numBufs].start[i1+1] == 0x000000C4))
{
DEBUG("huffman table finded! \nbuf.bytesused = %d\nFFC4 = %d \n",buf.bytesused,i1);
break;
}
}
if(i1 == buf.bytesused)printf("huffman table don't exist! \n");
int i;
for(i=0; ibuf.bytesused; i++)
{
if((buffers[numBufs].start[i] == 0x000000FF)(buffers[numBufs].start[i+1] == 0x000000D8)) break;
ptcur++;
}
DEBUG("i=%d,FF=%02x,D8=%02x\n",i,buffers[numBufs].start[i],buffers[numBufs].start[i+1]);
int imagesize =buf.bytesused - i;
DEBUG("buf.bytesused = %d \n",buf.bytesused);
DEBUG ("imagesize = %d \n",imagesize);
9. 停止视频的采集 。VIDIOC_STREAMOFF
10. 关闭视频设备 。close(fd);
如何在arm下开发linux视频采集卡驱动程序你可能需要手动创建设备节点,首先cat /proc/device 看看能否找到video的设备号,再用mknod命令创建/dev/下的设备节点,如果没有再考虑去内核make menuconfig查看相关驱动选项有没有勾上 。
ffmpeg录屏/录音/录摄像头----命令行实现原文地址:
ffmpeg在linux下支持linux视频采集命令的采集设备的种类比较多 。
在操作设备之前,我们可以查看当前系统可以支持的操作设备:
ffmpeg -hide_banner -devices
///////////////////////////////////
采集设备fbdev的参数:我们能看出fb(FrameBuffer)的操作参数 , 指定帧率就行(默认值为25).
ffmpeg-h demuxer=fbdev
ffmpeg -framerate 30-f fbdev -i /dev/fb0out.mp4
/////////////////////////////////////
v4l2即就是video4linux2的缩写,也是常见视频设备 。获取摄像头的视频图片~
通过ffmpeg -h demuxer=v4l2查看相关的操作参数
例子:
获取本电脑的v4l2摄像头所支持的色彩格式和分辨率:
ffmpeg -hide_banner -f v4l2 -list_formats all -i /dev/video0

推荐阅读