-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
57 lines (40 loc) · 1.07 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include "dv4l.h"
int main(int argc, char* argv[])
{
dv4l_t camera;
dv4l_fourcc_t pixelformat_input = {.u = 0};
dv4l_fourcc_t pixelformat_output = {.u = V4L2_PIX_FMT_BGR24};
int W = -1;
int H = -1;
if(!dv4l_init(&camera,
"/dev/video0",
W,H,
// fps
1,
// stream
true,
pixelformat_input,
pixelformat_output,
// controls
NULL, 0))
return 1;
W = camera.format.fmt.pix.width;
H = camera.format.fmt.pix.height;
char* buf = malloc(W*H*3);
if(buf == NULL)
return 1;
for(int i=0; i<5; i++)
{
if(!dv4l_getframe(&camera, buf, NULL))
return 1;
char filename[128];
sprintf(filename, "/tmp/frame%d.ppm", i);
FILE* fp = fopen(filename, "w");
fprintf(fp, "P6\n%d %d\n255\n", W, H);
fwrite(buf, 1, W*H*3, fp);
fclose(fp);
}
return 0;
}