-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
executable file
·144 lines (132 loc) · 3.21 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "misc.h"
#include "codec.h"
#include "cif.h"
#include "bitstream.h"
#include "time.h"
int Decode = 0;
static IMAGE image;
PICTURE *pic;
static int op_start_image, op_end_image;
static int format = SF_QCIF;
CONTEXT codeccontext;
int process_arg(int argc, char **argv);
int main(int argc, char **argv)
{
int i;
int pictpos = 0;
codeccontext.o_stream = stdout;
codeccontext.i_stream = stdin;
codeccontext.t_stream = 0;
codeccontext.debug = 0;
codeccontext.op_quant = 1;
codeccontext.motest_alg = MOTEST_4SS;
codeccontext.insert_intra_cycle = 25;
if (process_arg(argc, argv))
exit(1);
image.src_format = format;
codec_init(codeccontext);
for (i=op_start_image; i<=op_end_image; i++) {
trace("Frame %d\n", i);
if (Decode == 0) {
if (yuv_read_image(codeccontext, i, &image)) {
fprintf(stderr, "Can't read frame %d\n", i);
return 1;
}
// fprintf(stderr, "Frame %3d\n", i);
codec_encode_image(pic, &image);
} else {
int pictsize = 0;
if ((pictsize = read_h263_picture(pictpos, pic)) <= 0) {
fprintf(stderr, "Can't read frame %d\n", i);
return 1;
}
pictpos += pictsize;
codec_decode_picture(pic);
}
pic=pic->prev;
}
yuv_finit_image(&image);
codec_finit();
return 0;
}
int process_arg(int argc, char **argv)
{
opterr = 0;
optind = 1;
op_start_image = 0;
op_end_image = INT_MAX;
for (;;)
{
int c;
c = getopt(argc, argv, "i:o:f:d:t:a:b:m:s:M:DGJq:");
if (c==EOF) break;
switch (c)
{
case 'D':
Decode = 1;
break;
case 'i':
codeccontext.i_stream = stdin;
if (!(codeccontext.i_stream = fopen(optarg, "rb"))) {
fprintf(stderr, "Can't open %s\n", optarg);
return 1;
}
break;
case 'o':
codeccontext.o_stream = stdout;
if (!(codeccontext.o_stream = fopen(optarg, "wb"))) {
fprintf(stderr, "Can't open %s\n", optarg);
return 1;
}
break;
case 'f':
format = atoi(optarg);
break;
case 't':
codeccontext.t_stream = stdout;
if (!(codeccontext.t_stream = fopen(optarg, "w"))) {
fprintf(stderr, "Can't open %s\n", optarg);
return 1;
}
break;
case 'd':
codeccontext.debug = atoi(optarg);
if (debug < 0 || codeccontext.debug > 5) {
fprintf(stderr, "Error: incorrect debug level\n");
return 1;
}
break;
case 'a':
op_start_image = atoi(optarg);
if (op_start_image < 0) {
fprintf(stderr, "Error: incorrect op_start_image\n");
return 1;
}
break;
case 'b':
op_end_image = atoi(optarg);
if (op_end_image < 0) {
op_end_image = INT_MAX;
}
break;
case 'm':
codeccontext.motest_alg = atoi(optarg);
if (codeccontext.motest_alg < 0 || codeccontext.motest_alg > MOTEST_MAX) {
fprintf(stderr, "unknown motest_alg:\nFS\t%d\n4SS\t%d\nCBOSA\t%d\n" \
"HASA\t%d\n\n", MOTEST_FS, MOTEST_4SS, MOTEST_CBOSA, MOTEST_HASA);
exit(1);
}
break;
case 'q':
codeccontext.op_quant = atoi(optarg);
break;
case 's':
codeccontext.insert_intra_cycle = atoi(optarg);
break;
default:
fprintf(stderr, "Unknown option: %s\n", argv[optind-1]);
return 1;
}
}
return 0;
}