Skip to content

Instantly share code, notes, and snippets.

@licheegh
Last active April 17, 2019 09:08
Show Gist options
  • Save licheegh/5db32482b06a6d0864f09f41463588bd to your computer and use it in GitHub Desktop.
Save licheegh/5db32482b06a6d0864f09f41463588bd to your computer and use it in GitHub Desktop.
read a v4l2 vpu decoder device's name, capability, in/out format
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment