This repository was archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
83 lines (65 loc) · 2.21 KB
/
Copy pathmain.c
File metadata and controls
83 lines (65 loc) · 2.21 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "../include/vidio.c"
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#define FRAMES_DIR "frames/"
#define FRAMES_DIR_LEN 7
int main(int argc, char *argv[]) {
unsigned pixel;
int vi_fd, frame_fd, frame = 0, exit_code = 0;
char frame_path[] = FRAMES_DIR "\0.ppm";
const volatile VidioHeader *vi_header;
VidioPixel *vi_frame;
VidioPixel vi_frame_pixel;
if (argc < 2) {
fputs("please supply me with a *.vi file through arguments :)\n",
stderr);
return 1;
}
vi_fd = open(argv[1], O_RDONLY);
if (vi_fd == -1) {
fprintf(stderr, "failed to open(\"%s\", O_RDONLY): %s\n", argv[1],
strerror(errno));
return 2;
}
vi_header = vidio_read_header(vi_fd);
printf("video information\n\n"
"fps: %u\n"
"width: %u\n"
"height: %u\n",
vi_header->fps, vi_header->width, vi_header->height);
mkdir(FRAMES_DIR, 0700);
while (++frame) {
if ((vi_frame = vidio_get_next_frame(vi_fd, vi_header->width,
vi_header->height)) == NULL) {
puts("no (other) frames found");
goto end;
}
frame_path[FRAMES_DIR_LEN] = 'A' + frame;
frame_fd = open(frame_path, O_WRONLY | O_CREAT);
if (vidio_render_frame_to_ppm(frame_fd, vi_header->width,
vi_header->height, vi_frame) == -1) {
fprintf(stderr,
"failed to export frame %u to ppm, are you sure %s is "
"fully removed ?\n",
frame - 1, FRAMES_DIR);
free(vi_frame);
close(frame_fd);
exit_code = 3;
goto end;
}
close(frame_fd);
for (pixel = 0; pixel < vi_header->width * vi_header->height; ++pixel) {
vi_frame_pixel = vi_frame[pixel];
printf("frame %u pixel %u: rgb(%hhu, %hhu, %hhu)\n", frame - 1,
pixel, vi_frame_pixel.red, vi_frame_pixel.green,
vi_frame_pixel.blue);
}
free(vi_frame);
}
end:
close(vi_fd);
return exit_code;
}