56 |
|
|
57 |
#define USE_PNM 0 |
#define USE_PNM 0 |
58 |
#define USE_TGA 1 |
#define USE_TGA 1 |
59 |
|
#define USE_YUV 2 |
60 |
|
|
61 |
static int XDIM = 0; |
static int XDIM = 0; |
62 |
static int YDIM = 0; |
static int YDIM = 0; |
88 |
xvid_dec_stats_t *xvid_dec_stats); |
xvid_dec_stats_t *xvid_dec_stats); |
89 |
static int dec_stop(); |
static int dec_stop(); |
90 |
static void usage(); |
static void usage(); |
91 |
static int write_image(char *prefix, unsigned char *image); |
static int write_image(char *prefix, unsigned char *image, int filenr); |
92 |
static int write_pnm(char *filename, unsigned char *image); |
static int write_pnm(char *filename, unsigned char *image); |
93 |
static int write_tga(char *filename, unsigned char *image); |
static int write_tga(char *filename, unsigned char *image); |
94 |
|
static int write_yuv(char *filename, unsigned char *image); |
95 |
|
|
96 |
const char * type2str(int type) |
const char * type2str(int type) |
97 |
{ |
{ |
176 |
i++; |
i++; |
177 |
if (strcmp(argv[i], "tga") == 0) { |
if (strcmp(argv[i], "tga") == 0) { |
178 |
FORMAT = USE_TGA; |
FORMAT = USE_TGA; |
179 |
|
} else if (strcmp(argv[i], "yuv") == 0) { |
180 |
|
FORMAT = USE_YUV; |
181 |
} else { |
} else { |
182 |
FORMAT = USE_PNM; |
FORMAT = USE_PNM; |
183 |
} |
} |
216 |
if (BPP != 1 && BPP != 3 && FORMAT == USE_PNM) { |
if (BPP != 1 && BPP != 3 && FORMAT == USE_PNM) { |
217 |
FORMAT = USE_TGA; |
FORMAT = USE_TGA; |
218 |
} |
} |
219 |
|
if (BPP != 1 && FORMAT == USE_YUV) { |
220 |
|
FORMAT = USE_TGA; |
221 |
|
} |
222 |
|
|
223 |
/***************************************************************************** |
/***************************************************************************** |
224 |
* Memory allocation |
* Memory allocation |
274 |
mp4_ptr = mp4_buffer; |
mp4_ptr = mp4_buffer; |
275 |
|
|
276 |
/* read new data */ |
/* read new data */ |
277 |
if(feof(in_file)) |
if(!feof(in_file)) { |
|
break; |
|
|
|
|
278 |
useful_bytes += fread(mp4_buffer + already_in_buffer, |
useful_bytes += fread(mp4_buffer + already_in_buffer, |
279 |
1, BUFFER_SIZE - already_in_buffer, |
1, BUFFER_SIZE - already_in_buffer, |
280 |
in_file); |
in_file); |
281 |
|
} |
282 |
} |
} |
283 |
|
|
284 |
|
|
375 |
|
|
376 |
/* Save output frame if required */ |
/* Save output frame if required */ |
377 |
if (ARG_SAVEDECOUTPUT) { |
if (ARG_SAVEDECOUTPUT) { |
378 |
sprintf(filename, "%sdec%05d", filepath, filenr); |
sprintf(filename, "%sdec", filepath); |
379 |
if(write_image(filename, out_buffer)) { |
|
380 |
|
if(write_image(filename, out_buffer, filenr)) { |
381 |
fprintf(stderr, |
fprintf(stderr, |
382 |
"Error writing decoded frame %s\n", |
"Error writing decoded frame %s\n", |
383 |
filename); |
filename); |
424 |
|
|
425 |
/* Save output frame if required */ |
/* Save output frame if required */ |
426 |
if (ARG_SAVEDECOUTPUT) { |
if (ARG_SAVEDECOUTPUT) { |
427 |
sprintf(filename, "%sdec%05d", filepath, filenr); |
sprintf(filename, "%sdec", filepath); |
428 |
if(write_image(filename, out_buffer)) { |
|
429 |
|
if(write_image(filename, out_buffer, filenr)) { |
430 |
fprintf(stderr, |
fprintf(stderr, |
431 |
"Error writing decoded frame %s\n", |
"Error writing decoded frame %s\n", |
432 |
filename); |
filename); |
482 |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
fprintf(stderr, " -i string : input filename (default=stdin)\n"); |
483 |
fprintf(stderr, " -d : save decoder output\n"); |
fprintf(stderr, " -d : save decoder output\n"); |
484 |
fprintf(stderr, " -c csp : choose colorspace output (rgb16, rgb24, rgb32, yv12, i420)\n"); |
fprintf(stderr, " -c csp : choose colorspace output (rgb16, rgb24, rgb32, yv12, i420)\n"); |
485 |
fprintf(stderr, " -f format : choose output file format (tga, pnm, pgm)\n"); |
fprintf(stderr, " -f format : choose output file format (tga, pnm, pgm, yuv)\n"); |
486 |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
fprintf(stderr, " -m : save mpeg4 raw stream to individual files\n"); |
487 |
fprintf(stderr, " -help : This help message\n"); |
fprintf(stderr, " -help : This help message\n"); |
488 |
fprintf(stderr, " (* means default)\n"); |
fprintf(stderr, " (* means default)\n"); |
512 |
* output functions |
* output functions |
513 |
****************************************************************************/ |
****************************************************************************/ |
514 |
|
|
515 |
static int write_image(char *prefix, unsigned char *image) |
static int write_image(char *prefix, unsigned char *image, int filenr) |
516 |
{ |
{ |
517 |
char filename[1024]; |
char filename[1024]; |
518 |
char *ext; |
char *ext; |
522 |
ext = "pgm"; |
ext = "pgm"; |
523 |
} else if (FORMAT == USE_PNM && BPP == 3) { |
} else if (FORMAT == USE_PNM && BPP == 3) { |
524 |
ext = "pnm"; |
ext = "pnm"; |
525 |
|
} else if (FORMAT == USE_YUV) { |
526 |
|
ext = "yuv"; |
527 |
} else if (FORMAT == USE_TGA) { |
} else if (FORMAT == USE_TGA) { |
528 |
ext = "tga"; |
ext = "tga"; |
529 |
} else { |
} else { |
531 |
exit(-1); |
exit(-1); |
532 |
} |
} |
533 |
|
|
534 |
|
if (FORMAT == USE_YUV) { |
535 |
sprintf(filename, "%s.%s", prefix, ext); |
sprintf(filename, "%s.%s", prefix, ext); |
536 |
|
|
537 |
|
if (!filenr) { |
538 |
|
FILE *fp = fopen(filename, "wb"); |
539 |
|
fclose(fp); |
540 |
|
} |
541 |
|
} else |
542 |
|
sprintf(filename, "%s%05d.%s", prefix, filenr, ext); |
543 |
|
|
544 |
if (FORMAT == USE_PNM) { |
if (FORMAT == USE_PNM) { |
545 |
ret = write_pnm(filename, image); |
ret = write_pnm(filename, image); |
546 |
|
} else if (FORMAT == USE_YUV) { |
547 |
|
ret = write_yuv(filename, image); |
548 |
} else { |
} else { |
549 |
ret = write_tga(filename, image); |
ret = write_tga(filename, image); |
550 |
} |
} |
644 |
|
|
645 |
if (BPP == 1) { |
if (BPP == 1) { |
646 |
int i; |
int i; |
647 |
fprintf(f, "P5\n#xvid\n%i %i\n255\n", XDIM, YDIM*3/2); |
fprintf(f, "P5\n%i %i\n255\n", XDIM, YDIM*3/2); |
648 |
|
|
649 |
fwrite(image, 1, XDIM*YDIM, f); |
fwrite(image, 1, XDIM*YDIM, f); |
650 |
|
|
673 |
return 0; |
return 0; |
674 |
} |
} |
675 |
|
|
676 |
|
static int write_yuv(char *filename, unsigned char *image) |
677 |
|
{ |
678 |
|
FILE * f; |
679 |
|
|
680 |
|
f = fopen(filename, "ab+"); |
681 |
|
if ( f == NULL) { |
682 |
|
return -1; |
683 |
|
} |
684 |
|
|
685 |
|
fwrite(image, 1, 3*XDIM*YDIM/2, f); |
686 |
|
|
687 |
|
fclose(f); |
688 |
|
|
689 |
|
return 0; |
690 |
|
} |
691 |
|
|
692 |
/***************************************************************************** |
/***************************************************************************** |
693 |
* Routines for decoding: init decoder, use, and stop decoder |
* Routines for decoding: init decoder, use, and stop decoder |
694 |
****************************************************************************/ |
****************************************************************************/ |