-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractf.c
106 lines (102 loc) · 2.19 KB
/
extractf.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "dct.h"
int main(int argc, char *argv[])
{
int W=MAXWIDTH, H=MAXHEIGHT, frames=FRAMES_NO, result;
const rlim_t kStackSize = 32L * 1024L * 1024L; /* 32MB as a stack limit */
struct rlimit rl;
register int i;
uchar curframe[MAXHEIGHT][MAXWIDTH];
char fname[256];
/* Increase stack size (see ulimit(1) bash built-in command) allowing us to pass
really large arrays to performDCT() */
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0)
{
if (rl.rlim_cur < kStackSize)
{
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0)
{
perror("main()");
exit(2);
}
}
}
else
{
perror("main()");
exit(1);
}
if (argc < 2)
{
fprintf(stderr, "Syntax: %s [Width] [Height] [-nNumber] filename\n", argv[0]);
fprintf(stderr, "To extract <number> frames of raw video with resolution of <Width x Height>\n");
return 1;
}
if (argc==2)
strcpy(fname, argv[1]);
if (argc == 3)
{
if (!strncmp(argv[1], "-n",2))
{
frames=atoi(*(argv+1)+2);
if (frames==0)
{
fprintf(stderr, "Wrong arguments!\n");
return 1;
}
strcpy(fname, argv[2]);
}
else
{
fprintf(stderr, "Wrong arguments!\n");
fprintf(stderr, "What do you mean by %s ?\n", argv[1]);
return 1;
}
}
if (argc == 4)
{
W=atoi(argv[1]);
H=atoi(argv[2]);
if ((W==0) || (H==0))
{
fprintf(stderr, "Wrong arguments! (width, weight ?)\n");
return 1;
}
strcpy(fname,argv[3]);
}
if (argc == 5)
{
if (strncmp(argv[3],"-n",2))
{
fprintf(stderr, "Wrong arguments!\n");
fprintf(stderr, "What do you mean by %s ?\n", argv[3]);
return 1;
}
frames=atoi(*(argv+3)+2);
if (frames==0)
{
fprintf(stderr, "Wrong arguments! (Frame no ?)\n");
return 1;
}
W=atoi(argv[1]);
H=atoi(argv[2]);
strcpy(fname, argv[4]);
}
printf("Going to extract %d frames sized %dx%d from file: %s\n", frames, W,H, fname);
fp=fopen(fname, "r");
if (!fp)
{
perror("In main()");
exit(1);
}
for (i=0;i<frames;i++)
{
readFrame(fp,curframe, H, W);
printf("Calculating DCT for frame no. %d ...\n", i+1);
performDCT(curframe, H, W);
}
fclose(fp);
return 0; /* Everything Ok. */
}