Parent Directory | Revision Log
Revision 1054 - (view) (download)
1 : | edgomez | 1054 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - Deprecated Code - | ||
5 : | * | ||
6 : | * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org> | ||
7 : | * | ||
8 : | * This program is free software ; you can redistribute it and/or modify | ||
9 : | * it under the terms of the GNU General Public License as published by | ||
10 : | * the Free Software Foundation ; either version 2 of the License, or | ||
11 : | * (at your option) any later version. | ||
12 : | * | ||
13 : | * This program is distributed in the hope that it will be useful, | ||
14 : | * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
15 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 : | * GNU General Public License for more details. | ||
17 : | * | ||
18 : | * You should have received a copy of the GNU General Public License | ||
19 : | * along with this program ; if not, write to the Free Software | ||
20 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 : | * | ||
22 : | * $Id: rawdec.c,v 1.1.2.2 2003-06-09 13:49:50 edgomez Exp $ | ||
23 : | * | ||
24 : | ****************************************************************************/ | ||
25 : | suxen_drol | 887 | |
26 : | #include <stdio.h> | ||
27 : | #include <stdlib.h> | ||
28 : | #include <string.h> | ||
29 : | |||
30 : | #include <xvid.h> | ||
31 : | |||
32 : | |||
33 : | const static char * xvid_err(int err) | ||
34 : | { | ||
35 : | if (err == XVID_ERR_MEMORY) return "mem"; | ||
36 : | if (err == XVID_ERR_FORMAT) return "format"; | ||
37 : | if (err == XVID_ERR_VERSION) return "version"; | ||
38 : | return "unknown"; | ||
39 : | } | ||
40 : | |||
41 : | |||
42 : | /* returns true if the string contains scanf %'s chars | ||
43 : | (ignores %% sequences) */ | ||
44 : | |||
45 : | static int detect_sscanf(const char *s) | ||
46 : | { | ||
47 : | int percent = 0; | ||
48 : | while(*s){ | ||
49 : | if (percent){ | ||
50 : | if (*s!='%') | ||
51 : | return 1; | ||
52 : | percent=0; | ||
53 : | } | ||
54 : | if (*s=='%') | ||
55 : | percent = 1; | ||
56 : | s++; | ||
57 : | } | ||
58 : | return 0; | ||
59 : | } | ||
60 : | |||
61 : | |||
62 : | int main(int argc, char **argv) | ||
63 : | { | ||
64 : | char tmp[1024]; | ||
65 : | FILE * fbs, *fpgm; | ||
66 : | int fscanf; | ||
67 : | void * bs; | ||
68 : | int quit; | ||
69 : | int length; | ||
70 : | int pos; | ||
71 : | int frameno; | ||
72 : | int result; | ||
73 : | int width, height; | ||
74 : | |||
75 : | xvid_gbl_info_t info; | ||
76 : | xvid_gbl_init_t init; | ||
77 : | xvid_dec_create_t create; | ||
78 : | xvid_dec_frame_t frame; | ||
79 : | xvid_dec_stats_t stats; | ||
80 : | |||
81 : | memset(&info, 0, sizeof(info)); | ||
82 : | info.version = XVID_VERSION; | ||
83 : | |||
84 : | result = xvid_global(0, XVID_GBL_INFO, &info, 0); | ||
85 : | if (result < 0) | ||
86 : | { | ||
87 : | |||
88 : | printf("xvid_gbl_info error: %s\n", xvid_err(result)); | ||
89 : | return EXIT_FAILURE; | ||
90 : | } | ||
91 : | printf("xvidcore version %d.%d.%d (\"%s\")\n", | ||
92 : | XVID_MAJOR(info.actual_version), | ||
93 : | XVID_MINOR(info.actual_version), | ||
94 : | XVID_PATCH(info.actual_version), | ||
95 : | info.build); | ||
96 : | printf("cpu_flags:"); | ||
97 : | if ((info.cpu_flags & XVID_CPU_ASM)) printf(" ASM"); | ||
98 : | if ((info.cpu_flags & XVID_CPU_MMX)) printf(" MMX"); | ||
99 : | if ((info.cpu_flags & XVID_CPU_MMXEXT)) printf(" MMXEXT"); | ||
100 : | if ((info.cpu_flags & XVID_CPU_3DNOW)) printf(" 3DNOW"); | ||
101 : | if ((info.cpu_flags & XVID_CPU_3DNOWEXT)) printf(" 3DNOWEXT"); | ||
102 : | if ((info.cpu_flags & XVID_CPU_SSE)) printf(" SSE"); | ||
103 : | if ((info.cpu_flags & XVID_CPU_SSE2)) printf(" SSE2"); | ||
104 : | printf("\n"); | ||
105 : | printf("num_threads: %i\n", info.num_threads); | ||
106 : | |||
107 : | if (argc != 3 && argc != 5) | ||
108 : | { | ||
109 : | fprintf(stderr, | ||
110 : | "\nusage: rawdec bitstream outfile [width height]\n" | ||
111 : | "\n" | ||
112 : | "eg: rawdec foo.m4v [-|out.pgm|out%%05i.pgm]\n"); | ||
113 : | |||
114 : | return -1; | ||
115 : | } | ||
116 : | |||
117 : | /* open bitstream file & get length */ | ||
118 : | |||
119 : | fbs = fopen(argv[1], "rb"); | ||
120 : | if (fbs == NULL) | ||
121 : | { | ||
122 : | fprintf(stderr, "fatal: \"%s\" not found", argv[1]); | ||
123 : | return -1; | ||
124 : | } | ||
125 : | |||
126 : | if (argc == 5) | ||
127 : | { | ||
128 : | width = atoi(argv[3]); | ||
129 : | height = atoi(argv[4]); | ||
130 : | } | ||
131 : | else | ||
132 : | { | ||
133 : | width = height = 0; /* auto detect */ | ||
134 : | } | ||
135 : | |||
136 : | fseek(fbs, 0, SEEK_END); | ||
137 : | length = ftell(fbs); | ||
138 : | fseek(fbs, 0, SEEK_SET); | ||
139 : | |||
140 : | /* XXX: load entire bitstream file into memory */ | ||
141 : | |||
142 : | bs = malloc(length); | ||
143 : | if (bs == NULL) | ||
144 : | { | ||
145 : | fprintf(stderr, "fatal: bitstream malloc failed\n"); | ||
146 : | return -1; | ||
147 : | } | ||
148 : | |||
149 : | fread(bs, length, 1, fbs); | ||
150 : | fclose(fbs); | ||
151 : | |||
152 : | |||
153 : | /* otuput file stuff */ | ||
154 : | fscanf = detect_sscanf(argv[2]); | ||
155 : | if (argv[2][0] != '-' && !fscanf) | ||
156 : | { | ||
157 : | fpgm = fopen(argv[2], "wb"); | ||
158 : | if (fpgm == NULL){ | ||
159 : | fprintf(stderr,"aborting: \"%s\" write error\n", argv[2]); | ||
160 : | free(bs); | ||
161 : | return EXIT_FAILURE; | ||
162 : | } | ||
163 : | } | ||
164 : | |||
165 : | |||
166 : | /* init globals | ||
167 : | note: init.cpu_flags is optional | ||
168 : | */ | ||
169 : | |||
170 : | memset(&init, 0, sizeof(init)); | ||
171 : | init.version = XVID_VERSION; | ||
172 : | //init.cpu_flags = XVID_CPU_FORCE; | ||
173 : | result = xvid_global(0, XVID_GBL_INIT, &init, NULL); | ||
174 : | if (result < 0) | ||
175 : | { | ||
176 : | free(bs); | ||
177 : | printf("xvid_gbl_init error: %s\n", xvid_err(result)); | ||
178 : | return EXIT_FAILURE; | ||
179 : | } | ||
180 : | |||
181 : | |||
182 : | /* create decoder instance */ | ||
183 : | |||
184 : | memset(&create, 0, sizeof(create)); | ||
185 : | create.version = XVID_VERSION; | ||
186 : | create.width = width; | ||
187 : | create.height = height; | ||
188 : | result = xvid_decore(0, XVID_DEC_CREATE, &create, NULL); | ||
189 : | if (result < 0) | ||
190 : | { | ||
191 : | free(bs); | ||
192 : | fprintf(stderr, "xvid_dec_create error: %s\n", xvid_err(result)); | ||
193 : | return EXIT_FAILURE; | ||
194 : | } | ||
195 : | |||
196 : | |||
197 : | /* init other struct; we only have to do this once */ | ||
198 : | memset(&frame, 0, sizeof(frame)); | ||
199 : | frame.version = XVID_VERSION; | ||
200 : | |||
201 : | memset(&stats, 0, sizeof(stats)); | ||
202 : | stats.version = XVID_VERSION; | ||
203 : | |||
204 : | |||
205 : | /* decode frames ... */ | ||
206 : | quit = 0; | ||
207 : | pos = 0; | ||
208 : | frameno = 0; | ||
209 : | while (!quit) | ||
210 : | { | ||
211 : | int y; | ||
212 : | |||
213 : | if (pos < length) | ||
214 : | { | ||
215 : | frame.bitstream = (void*)((unsigned long)bs + pos); | ||
216 : | frame.length = length - pos; | ||
217 : | }else{ | ||
218 : | printf("**FLUSH LAST FRAME\n"); | ||
219 : | frame.length = -1; /* flush last frame */ | ||
220 : | quit = 1; | ||
221 : | } | ||
222 : | /* xvid will return pointers to it's internal image buffers */ | ||
223 : | frame.output.csp = XVID_CSP_INTERNAL; | ||
224 : | |||
225 : | result = xvid_decore(create.handle, XVID_DEC_DECODE, &frame, &stats); | ||
226 : | fprintf(stdout," #%i [%i/%i] length=%i\n", frameno, pos, length, frame.length); fflush(stderr); | ||
227 : | if (result < 0) | ||
228 : | { | ||
229 : | fprintf(stderr, "xvid_dec_decode error: %s\n", xvid_err(result)); | ||
230 : | break; | ||
231 : | } | ||
232 : | |||
233 : | /* increase position by the ammount consumed for this frame */ | ||
234 : | pos += result; | ||
235 : | |||
236 : | |||
237 : | if (stats.type == XVID_TYPE_NOTHING) /* no output */ | ||
238 : | { | ||
239 : | continue; | ||
240 : | } | ||
241 : | |||
242 : | if (stats.type == XVID_TYPE_VOL) /* vol/resize */ | ||
243 : | { | ||
244 : | printf("**RESIZE** %i,%i\n", stats.data.vol.width, stats.data.vol.height); | ||
245 : | width = stats.data.vol.width; | ||
246 : | height = stats.data.vol.height; | ||
247 : | printf("%i\n", frame.length); | ||
248 : | continue; | ||
249 : | } | ||
250 : | |||
251 : | /* write output image to pgm file */ | ||
252 : | if (argv[2][0] == '-') | ||
253 : | { | ||
254 : | fpgm = stdout; | ||
255 : | }else if (fscanf) { | ||
256 : | sprintf(tmp,argv[2], frameno); | ||
257 : | fpgm = fopen(tmp, "wb"); | ||
258 : | if (fpgm == NULL) { | ||
259 : | fprintf(stderr,"aborting: \"%s\" write error\n", tmp); | ||
260 : | break; | ||
261 : | } | ||
262 : | } | ||
263 : | |||
264 : | sprintf(tmp, "P5\n%i %i\n255\n", width, height * 3 / 2); | ||
265 : | fwrite(tmp, strlen(tmp) , 1, fpgm); | ||
266 : | |||
267 : | for (y = height; y; y--) { | ||
268 : | fwrite(frame.output.plane[0], width, 1, fpgm); | ||
269 : | frame.output.plane[0] = (void*)((char *)frame.output.plane[0] + frame.output.stride[0]); | ||
270 : | } | ||
271 : | |||
272 : | for (y = height >> 1; y; y--) { | ||
273 : | fwrite(frame.output.plane[1], width / 2, 1, fpgm); | ||
274 : | frame.output.plane[1] = (void*)((char *)frame.output.plane[1] + frame.output.stride[1]); | ||
275 : | |||
276 : | fwrite(frame.output.plane[2], width / 2, 1, fpgm); | ||
277 : | frame.output.plane[2] = (void*)((char *)frame.output.plane[2] + frame.output.stride[2]); | ||
278 : | } | ||
279 : | |||
280 : | if (argv[2][0] != '-' && fscanf) { | ||
281 : | fclose(fpgm); | ||
282 : | } | ||
283 : | |||
284 : | |||
285 : | /* finally, increment frame num */ | ||
286 : | frameno++; | ||
287 : | } | ||
288 : | |||
289 : | |||
290 : | /* cleanup & exit */ | ||
291 : | |||
292 : | if (argv[2][0] != '-' && !fscanf) | ||
293 : | { | ||
294 : | fclose(fpgm); | ||
295 : | } | ||
296 : | |||
297 : | free(bs); | ||
298 : | |||
299 : | result = xvid_decore(create.handle, XVID_DEC_DESTROY, NULL, NULL); | ||
300 : | if (result < 0) | ||
301 : | { | ||
302 : | fprintf(stderr, "xvid_dec_destroy error: %s\n", xvid_err(result)); | ||
303 : | return EXIT_FAILURE; | ||
304 : | } | ||
305 : | |||
306 : | return EXIT_SUCCESS; | ||
307 : | edgomez | 1054 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |