Phytec中国的wiki
support@phytec.cn
热线:0755-61802110-803
v4l2介绍
v4l2最初是用于在linux上捕捉图像,后来发展成为一个视频硬件接口框架。
- v4l2开发文档:https://linuxtv.org/downloads/v4l-dvb-apis-new/userspace-api/v4l/v4l2.html
- Linux Media Kernel API Documentation https://linuxtv.org/docs.php
- 适用于我们i.MX6核心板IPU的V4L2文档 https://linuxtv.org/downloads/v4l-dvb-apis-new/admin-guide/imx.html
使用这个指令可以查看这个硬件解码器支持的输入格式,以及输出格式。
从以上信息可以看到 /dev/video9 是VPU的接口,可以将NV12的视频压缩为H264格式的视频。
v4l2的例子
参考文档:
- https://linuxtv.org/downloads/v4l-dvb-apis-new/userspace-api/v4l/v4l2.html
- https://blog.csdn.net/xiongmaojiayou/article/details/7559948
- http://jwhsmith.net/2014/12/capturing-a-webcam-stream-using-v4l2/
- https://jayrambhia.com/blog/capture-v4l2
一个使用v4l2的接口来读取vpu解码设备信息的例子:
#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <linux/videodev2.h> #include <sys/ioctl.h> int main(int argc, char *argv[]) { int fd; struct v4l2_capability cap; struct v4l2_fmtdesc fmtdesc; fd = open("/dev/video9", O_RDWR); if (fd == -1) { perror("Opening Video device"); return 1; } ioctl(fd,VIDIOC_QUERYCAP,&cap); printf("Driver Name:%s\nCard Name:%s\nBus info:%s\ncaps:0x%x\n",\ cap.driver,\ cap.card,\ cap.bus_info,\ cap.device_caps); fmtdesc.index=0; fmtdesc.type=V4L2_BUF_TYPE_VIDEO_CAPTURE; printf("input format:\n"); while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1) { printf("/t%d.%s\n",fmtdesc.index+1,fmtdesc.description); fmtdesc.index++; } fmtdesc.index=0; fmtdesc.type=V4L2_BUF_TYPE_VIDEO_OUTPUT; printf("out format:\n"); while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc)!=-1) { printf("/t%d.%s\n",fmtdesc.index+1,fmtdesc.description); fmtdesc.index++; } close(fd); return 0; }
编译方式:
$CC $CFLAGS v4l2.c -o v4l2
执行结果:
root@phyboard-mira-imx6-3:~# ./v4l2 Driver Name:coda Card Name:CODA960 Bus info:platform:coda caps:0x4208000 input format: /t1.Y/CbCr 4:2:0 /t2.Planar YUV 4:2:0 /t3.Planar YVU 4:2:0 /t4.YUYV 4:2:2 out format: /t1.H.264 /t2.MPEG-2 ES /t3.MPEG-4 part 2 ES
Overview
Content Tools
Tasks