Ticket #1560: v4l2_testcase.c

File v4l2_testcase.c, 1.0 KB (added by Tristan Matthews, 14 years ago)

compile with "cc v4l2_testcase.c -o v4l2_testcase pkg-config --cflags --libs libavdevice libavformat"

Line 
1#include <libavdevice/avdevice.h>
2#include <libavformat/avformat.h>
3
4/* compile with
5 cc v4l2_testcase.c -o v4l2_testcase `pkg-config --cflags --libs libavdevice libavformat` */
6
7#define RETURN_IF_FAIL(A, M, ...) if (!(A)) { fprintf(stderr, M "\n", ##__VA_ARGS__); return 1; }
8
9int main()
10{
11 av_register_all();
12 avdevice_register_all();
13
14 int i;
15 for (i = 0; i < 20; ++i) {
16 const char *const format_str = "video4linux2";
17 AVInputFormat *file_iformat = av_find_input_format(format_str);
18 RETURN_IF_FAIL(file_iformat, "Could not find format \"%s\"", format_str);
19
20 AVDictionary *options = NULL;
21 // Open video file
22 printf("Opening input\n");
23 AVFormatContext *input_ctx = avformat_alloc_context();
24 const char * const dev = "/dev/video0";
25 int ret = avformat_open_input(&input_ctx, dev, file_iformat, NULL);
26 RETURN_IF_FAIL(ret == 0, "Could not open input \"%s\"", dev);
27
28 if (input_ctx)
29 avformat_close_input(&input_ctx);
30 }
31
32 return 0;
33}