--- trunk/xvidcore/examples/xvid_decraw.c 2004/04/15 19:44:06 1432 +++ trunk/xvidcore/examples/xvid_decraw.c 2005/08/01 10:53:46 1627 @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid_decraw.c,v 1.14 2004-04-15 19:44:05 edgomez Exp $ + * $Id: xvid_decraw.c,v 1.20 2005-08-01 10:53:46 Isibaar Exp $ * ****************************************************************************/ @@ -54,9 +54,6 @@ * Global vars in module and constants ****************************************************************************/ -/* max number of frames */ -#define ABS_MAXFRAMENR 9999 - #define USE_PNM 0 #define USE_TGA 1 @@ -74,13 +71,13 @@ #define BUFFER_SIZE (2*1024*1024) +static const int display_buffer_bytes = 0; + /***************************************************************************** * Local prototypes ****************************************************************************/ static double msecond(); -static int write_pgm(char *filename, - unsigned char *image); static int dec_init(int use_assembler, int debug_level); static int dec_main(unsigned char *istream, unsigned char *ostream, @@ -88,9 +85,9 @@ xvid_dec_stats_t *xvid_dec_stats); static int dec_stop(); static void usage(); -int write_image(char *prefix, unsigned char *image); -int write_pnm(char *filename, unsigned char *image); -int write_tga(char *filename, unsigned char *image); +static int write_image(char *prefix, unsigned char *image); +static int write_pnm(char *filename, unsigned char *image); +static int write_tga(char *filename, unsigned char *image); const char * type2str(int type) { @@ -113,6 +110,7 @@ unsigned char *mp4_ptr = NULL; unsigned char *out_buffer = NULL; int useful_bytes; + int chunk; xvid_dec_stats_t xvid_dec_stats; double totaldectime; @@ -246,7 +244,8 @@ totalsize = 0; filenr = 0; mp4_ptr = mp4_buffer; - + chunk = 0; + do { int used_bytes = 0; double dectime; @@ -304,6 +303,22 @@ fprintf(stderr, "Resized frame buffer to %dx%d\n", XDIM, YDIM); } + + /* Save individual mpeg4 stream if required */ + if(ARG_SAVEMPEGSTREAM) { + FILE *filehandle = NULL; + + sprintf(filename, "%svolhdr.m4v", filepath); + filehandle = fopen(filename, "wb"); + if(!filehandle) { + fprintf(stderr, + "Error writing vol header mpeg4 stream to file %s\n", + filename); + } else { + fwrite(mp4_ptr, 1, used_bytes, filehandle); + fclose(filehandle); + } + } } /* Update buffer pointers */ @@ -315,7 +330,10 @@ totalsize += used_bytes; } - }while(xvid_dec_stats.type <= 0 && useful_bytes > 0); + if (display_buffer_bytes) { + printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes); + } + } while (xvid_dec_stats.type <= 0 && useful_bytes > 0); /* Check if there is a negative number of useful bytes left in buffer * This means we went too far */ @@ -326,9 +344,11 @@ totaldectime += dectime; - printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", - filenr, type2str(xvid_dec_stats.type), dectime, used_bytes); - + if (!display_buffer_bytes) { + printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", + filenr, type2str(xvid_dec_stats.type), dectime, used_bytes); + } + /* Save individual mpeg4 stream if required */ if(ARG_SAVEMPEGSTREAM) { FILE *filehandle = NULL; @@ -351,14 +371,16 @@ sprintf(filename, "%sdec%05d", filepath, filenr); if(write_image(filename, out_buffer)) { fprintf(stderr, - "Error writing decoded PGM frame %s\n", + "Error writing decoded frame %s\n", filename); } } filenr++; - } while ( (status>=0) && (filenr0 || !feof(in_file)); + + useful_bytes = 0; /* Empty buffer */ /***************************************************************************** * Flush decoder buffers @@ -374,7 +396,10 @@ dectime = msecond(); used_bytes = dec_main(NULL, out_buffer, -1, &xvid_dec_stats); dectime = msecond() - dectime; - }while(used_bytes>=0 && xvid_dec_stats.type <= 0); + if (display_buffer_bytes) { + printf("Data chunk %d: %d bytes consumed, %d bytes in buffer\n", chunk++, used_bytes, useful_bytes); + } + } while(used_bytes>=0 && xvid_dec_stats.type <= 0); if (used_bytes < 0) { /* XVID_ERR_END */ break; @@ -384,9 +409,11 @@ totaldectime += dectime; /* Prints some decoding stats */ - printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", - filenr, type2str(xvid_dec_stats.type), dectime, used_bytes); - + if (!display_buffer_bytes) { + printf("Frame %5d: type = %s, dectime(ms) =%6.1f, length(bytes) =%7d\n", + filenr, type2str(xvid_dec_stats.type), dectime, used_bytes); + } + /* Save output frame if required */ if (ARG_SAVEDECOUTPUT) { sprintf(filename, "%sdec%05d", filepath, filenr); @@ -476,7 +503,7 @@ * output functions ****************************************************************************/ -int write_image(char *prefix, unsigned char *image) +static int write_image(char *prefix, unsigned char *image) { char filename[1024]; char *ext; @@ -504,7 +531,7 @@ return(ret); } -int write_tga(char *filename, unsigned char *image) +static int write_tga(char *filename, unsigned char *image) { FILE * f; char hdr[18]; @@ -547,21 +574,21 @@ #else { int i; - for (i=0; iversion = XVID_VERSION;