Created
September 24, 2014 12:13
-
-
Save rdb/ddabee214feade0ff002 to your computer and use it in GitHub Desktop.
Small programs that lists supported V4L2 formats.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/videodev2.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
struct v4l2_fmtdesc fmt; | |
int i; | |
const char *dev; | |
int fd; | |
dev = "/dev/video0"; | |
if (argc > 1) { | |
dev = argv[1]; | |
} | |
fd = open(dev, O_RDWR); | |
if (fd == -1) { | |
printf("failed to open %s\n", dev); | |
return 1; | |
} | |
printf("opened %s\n", dev); | |
for (i = 0;; i++) { | |
memset(&fmt, 0, sizeof fmt); | |
fmt.index = i; | |
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
if (ioctl(fd, VIDIOC_ENUM_FMT, &fmt) == -1) { | |
break; | |
} | |
char fourcc[5]; | |
fourcc[0] = fmt.pixelformat & 0xff; | |
fourcc[1] = (fmt.pixelformat & 0xff00) >> 8; | |
fourcc[2] = (fmt.pixelformat & 0xff0000) >> 16; | |
fourcc[3] = (fmt.pixelformat & 0xff000000) >> 24; | |
fourcc[4] = 0; | |
printf("format %s\n", fourcc); | |
} | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment