--- trunk/xvidcore/examples/xvid_encraw.c 2002/09/28 13:01:15 557 +++ trunk/xvidcore/examples/xvid_encraw.c 2002/09/28 14:26:53 558 @@ -1,159 +1,516 @@ -/************************************************************************** +/***************************************************************************** * - * XVID MPEG-4 VIDEO CODEC - Example for encoding and decoding + * XVID MPEG-4 VIDEO CODEC + * - Console based test application - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright(C) 2002 Christoph Lampert * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - *************************************************************************/ + * You should have received a copy of the GNU General Public License + * 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_encraw.c,v 1.2 2002-09-28 14:26:53 edgomez Exp $ + * + ****************************************************************************/ -/************************************************************************ +/***************************************************************************** + * Application notes : * - * Speed test routine for XviD using the XviD-API - * (C) Christoph Lampert, 2002/08/17 - * - * A sequence of YUV pics in PGM or RAW file format is encoded and the - * raw MPEG-4 stream is written to stdout. - * The encoding speed of this is measured, too. + * A sequence of YUV pics in PGM file format is encoded and decoded + * The speed is measured and PSNR of decoded picture is calculated. * * The program is plain C and needs no libraries except for libxvidcore, - * and maths-lib, so with UN*X you simply compile by - * - * gcc xvid_encraw.c -lxvidcore -lm -o xvid_encraw - * - * Run without or with illegal parameters, then PGM input input is read - * from stdin. - * - * Parameters are: xvid_stat XDIM YDIM QUALITY BITRATE/QUANTIZER FRAMERATE - * - * if XDIM or YDIM are illegal (e.g. 0), they are ignored and input is - * considered to be PGM. Otherwise (X and Y both greater than 0) raw YUV - * is expected, as e.g. the standard MPEG test-files, like "foreman" - * - * 0 <= QUALITY <= 6 (default 5) - * - * BITRATE is in kbps (default 900), - * if BITRATE<32, then value is taken is fixed QUANTIZER - * - * FRAMERATE is a float (with or without decimal dot), default is 25.00 - * - * input/output and m4v-output is saved, if corresponding flags are set - * - * PGM input must in a very specific format, see read_pgmheader - * it can be generated e.g. from MPEG2 by mpeg2dec -o pgmpipe + * and maths-lib. * ************************************************************************/ -/************************************************************************ - * - * For EXAMPLES how to use this, see the seperate file xvid_stat.examples - * - ************************************************************************/ - #include #include -#include // needed for log10 -#include // only needed for gettimeofday +#include +#ifndef _MSC_VER +#include +#else +#include +#endif -#include "../src/xvid.h" /* comes with XviD */ +#include "xvid.h" -int motion_presets[7] = { - 0, // Q 0 - PMV_EARLYSTOP16, // Q 1 - PMV_EARLYSTOP16, // Q 2 - PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 - PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 - PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 // Q 5 - | PMV_HALFPELREFINE8, - PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 // Q 6 - | PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 - }; - -int general_presets[7] = { - XVID_H263QUANT, /* or use XVID_MPEGQUANT */ // Q 0 - XVID_MPEGQUANT, // Q 1 - XVID_H263QUANT, // Q 2 - XVID_H263QUANT | XVID_HALFPEL, // Q 3 - XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 - XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5 - XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V }; // Q 6 +/***************************************************************************** + * Quality presets + ****************************************************************************/ + +static int const motion_presets[7] = { + 0, // Q 0 + PMV_EARLYSTOP16, // Q 1 + PMV_EARLYSTOP16, // Q 2 + PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 3 + PMV_EARLYSTOP16 | PMV_HALFPELREFINE16, // Q 4 + PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | // Q 5 + PMV_HALFPELREFINE8, + PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | // Q 6 + PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 +}; + +static int const general_presets[7] = { + XVID_H263QUANT, // Q 0 + XVID_MPEGQUANT, // Q 1 + XVID_H263QUANT, // Q 2 + XVID_H263QUANT | XVID_HALFPEL, // Q 3 + XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4 + XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5 + XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V // Q 6 +}; -/* my default values for encoding */ +/***************************************************************************** + * Command line global variables + ****************************************************************************/ + +/* Maximum number of frames to encode */ +#define ABS_MAXFRAMENR 9999 + +static int ARG_BITRATE = 900; +static int ARG_QUANTI = 0; +static int ARG_QUALITY = 6; +static int ARG_MINQUANT = 1; +static int ARG_MAXQUANT = 31; +static float ARG_FRAMERATE = 25.00f; +static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; +static char *ARG_INPUTFILE = NULL; +static int ARG_INPUTTYPE = 0; +static int ARG_SAVEMPEGSTREAM = 0; +static int ARG_OUTPUTTYPE = 0; +static char *ARG_OUTPUTFILE = NULL; +static int XDIM = 0; +static int YDIM = 0; +#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) -#define ABS_MAXFRAMENR 9999 // max number of frames +#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) +#define SMALL_EPS 1e-10 -int ARG_BITRATE=900; -int ARG_QUANTI=0; +#define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \ + (((long)(c))<<8) |((long)(d))) -int ARG_QUALITY =6; -int ARG_MINQUANT=1; -int ARG_MAXQUANT=31; -float ARG_FRAMERATE=25.00; +#define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ + (((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) -int ARG_MAXFRAMENR=ABS_MAXFRAMENR; +/**************************************************************************** + * Nasty global vars ;-) + ***************************************************************************/ -#ifdef BFRAMES +static int i,filenr = 0; -int ARG_MAXBFRAMES=1; -int ARG_BQUANTRATIO=200; +/* the path where to save output */ +static char filepath[256] = "./"; -#endif +/* Internal structures (handles) for encoding and decoding */ +static void *enc_handle = NULL; -#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) -#define SMALL_EPS 1e-10 +/***************************************************************************** + * Local prototypes + ****************************************************************************/ + +/* Prints program usage message */ +static void usage(); + +/* Statistical functions */ +static double msecond(); + +/* PGM related functions */ +static int read_pgmheader(FILE* handle); +static int read_pgmdata(FILE* handle, unsigned char *image); +static int read_yuvdata(FILE* handle, unsigned char *image); + +/* Encoder related functions */ +static int enc_init(int use_assembler); +static int enc_stop(); +static int enc_main(unsigned char* image, unsigned char* bitstream, + int *streamlength, int* frametype); + +/***************************************************************************** + * Main function + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + + unsigned char *mp4_buffer = NULL; + unsigned char *in_buffer = NULL; + unsigned char *out_buffer = NULL; + + double enctime; + double totalenctime=0.; + + long totalsize; + int status; + int frame_type; + int bigendian; + + int m4v_size; + int use_assembler=0; + + char filename[256]; + + FILE *in_file = stdin; + FILE *out_file = NULL; + + printf("xvid_decraw - raw mpeg4 bitstream encoder "); + printf("written by Christoph Lampert 2002\n\n"); + +/***************************************************************************** + * Command line parsing + ****************************************************************************/ + + for (i=1; i< argc; i++) { + + if (strcmp("-asm", argv[i]) == 0 ) { + use_assembler = 1; + } + else if (strcmp("-w", argv[i]) == 0 && i < argc - 1 ) { + i++; + XDIM = atoi(argv[i]); + } + else if (strcmp("-h", argv[i]) == 0 && i < argc - 1 ) { + i++; + YDIM = atoi(argv[i]); + } + else if (strcmp("-b", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_BITRATE = atoi(argv[i]); + } + else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_QUALITY = atoi(argv[i]); + } + else if (strcmp("-f", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_FRAMERATE = (float)atof(argv[i]); + } + else if (strcmp("-i", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_INPUTFILE = argv[i]; + } + else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_INPUTTYPE = atoi(argv[i]); + } + else if(strcmp("-n", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_MAXFRAMENR = atoi(argv[i]); + } + else if (strcmp("-quant", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_QUANTI = atoi(argv[i]); + } + else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_SAVEMPEGSTREAM = atoi(argv[i]); + } + else if (strcmp("-mt", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_OUTPUTTYPE = atoi(argv[i]); + } + else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_OUTPUTFILE = argv[i]; + } + else if (strcmp("-help", argv[i])) { + usage(); + return(0); + } + else { + usage(); + exit(-1); + } + + } + +/***************************************************************************** + * Arguments checking + ****************************************************************************/ + + if (XDIM <= 0 || XDIM >= 2048 || YDIM <=0 || YDIM >= 2048 ) { + fprintf(stderr, "Trying to retreive width and height from PGM header\n"); + ARG_INPUTTYPE = 1; /* pgm */ + } + + if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) { + fprintf(stderr,"Wrong Quality\n"); + return -1; + } + + if ( ARG_BITRATE <= 0 && ARG_QUANTI == 0) { + fprintf(stderr,"Wrong Bitrate\n"); + return -1; + } + + if ( ARG_FRAMERATE <= 0) { + fprintf(stderr,"Wrong Framerate %s \n",argv[5]); + return -1; + } + + if ( ARG_MAXFRAMENR <= 0) { + fprintf(stderr,"Wrong number of frames\n"); + return -1; + } + + if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { + in_file = stdin; + } + else { + + in_file = fopen(ARG_INPUTFILE, "rb"); + if (in_file == NULL) { + fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE); + return -1; + } + } + + if (ARG_INPUTTYPE) { + if (read_pgmheader(in_file)) { + fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n"); + return -1; + } + } + + /* now we know the sizes, so allocate memory */ + + in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)); + if (!in_buffer) + goto free_all_memory; + + /* this should really be enough memory ! */ + mp4_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM)*2); + if (!mp4_buffer) + goto free_all_memory; + +/***************************************************************************** + * XviD PART Start + ****************************************************************************/ + + + status = enc_init(use_assembler); + if (status) + { + fprintf(stderr, "Encore INIT problem, return value %d\n", status); + goto release_all; + } + +/***************************************************************************** + * Main loop + ****************************************************************************/ + + if (ARG_SAVEMPEGSTREAM && (ARG_OUTPUTTYPE || ARG_OUTPUTFILE)) { + + if (ARG_OUTPUTFILE == NULL && ARG_OUTPUTTYPE) + ARG_OUTPUTFILE = "stream.mp4u"; + else if(ARG_OUTPUTFILE == NULL && !ARG_OUTPUTTYPE) + ARG_OUTPUTFILE = "stream.m4v"; + + if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) { + fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE); + goto release_all; + } + + /* Write header */ + if (ARG_OUTPUTTYPE) { + char *ptr; + long test; + + test = LONG_PACK('M','P','4','U'); + ptr = (unsigned char *)&test; + if(*ptr == 'M') + bigendian = 1; + else + bigendian = 0; + + test = (!bigendian)?SWAP(test):test; + + fwrite(&test, sizeof(test), 1, out_file); + + } + + } + else { + out_file = NULL; + } + +/***************************************************************************** + * Encoding loop + ****************************************************************************/ + + totalsize = 0; + + do { + + if (ARG_INPUTTYPE) + status = read_pgmdata(in_file, in_buffer); // read PGM data (YUV-format) + else + status = read_yuvdata(in_file, in_buffer); // read raw data (YUV-format) + + if (status) + { + /* Couldn't read image, most likely end-of-file */ + continue; + } + +/***************************************************************************** + * Encode and decode this frame + ****************************************************************************/ + + enctime = msecond(); + status = enc_main(in_buffer, mp4_buffer, &m4v_size, &frame_type); + enctime = msecond() - enctime; + + totalenctime += enctime; + totalsize += m4v_size; + + printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6dbytes\n", + (int)filenr, (int)frame_type, (float)enctime, (int)m4v_size); + + if (ARG_SAVEMPEGSTREAM) + { + /* Save single files */ + if (out_file == NULL) { + sprintf(filename, "%sframe%05d.m4v", filepath, filenr); + out_file = fopen(filename, "wb"); + fwrite(mp4_buffer, m4v_size, 1, out_file); + fclose(out_file); + out_file = NULL; + } + else { + /* Using mp4u container */ + if (ARG_OUTPUTTYPE) { + long size = m4v_size; + size = (!bigendian)?SWAP(size):size; + fwrite(&size, sizeof(size), 1, out_file); + } + + /* Write mp4 data */ + fwrite(mp4_buffer, m4v_size, 1, out_file); + + } + } + + /* Read the header if it's pgm stream */ + if (ARG_INPUTTYPE) + status = read_pgmheader(in_file); + + filenr++; + + } while ( (!status) && (filenr0 | default=900kbit)\n"); + fprintf(stderr, " -f float : target framerate (>0)\n"); + fprintf(stderr, " -i string : input filename (default=stdin)\n"); + fprintf(stderr, " -t integer : input data type (yuv=0, pgm=1)\n"); + fprintf(stderr, " -n integer : number of frames to encode\n"); + fprintf(stderr, " -q integer : quality ([0..5])\n"); + fprintf(stderr, " -d boolean : save decoder output (0 False*, !=0 True)\n"); + fprintf(stderr, " -m boolean : save mpeg4 raw stream (0 False*, !=0 True)\n"); + fprintf(stderr, " -o string : output container filename (only usefull when -m 1 is used) :\n"); + fprintf(stderr, " When this option is not used : one file per encoded frame\n"); + fprintf(stderr, " When this option is used :\n"); + fprintf(stderr, " + stream.m4v with -mt 0\n"); + fprintf(stderr, " + stream.mp4u with -mt 1\n"); + fprintf(stderr, " -mt integer : output type (m4v=0, mp4u=1)\n"); + fprintf(stderr, " -help : prints this help message\n"); + fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); + fprintf(stderr, " (* means default)\n"); -int read_pgmheader(FILE* handle) +} + +/***************************************************************************** + * Input and output functions + * + * the are small and simple routines to read and write PGM and YUV + * image. It's just for convenience, again nothing specific to XviD + * + *****************************************************************************/ + +static int read_pgmheader(FILE* handle) { int bytes,xsize,ysize,depth; char dummy[2]; @@ -162,93 +519,87 @@ if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' )) return 1; + fscanf(handle,"%d %d %d",&xsize,&ysize,&depth); if ( (xsize > 1440) || (ysize > 2880 ) || (depth != 255) ) { + fprintf(stderr,"%d %d %d\n",xsize,ysize,depth); return 2; } if ( (XDIM==0) || (YDIM==0) ) - { XDIM=xsize; - YDIM=ysize; + { + XDIM=xsize; + YDIM=ysize*2/3; } return 0; } -int read_pgmdata(FILE* handle, unsigned char *image) +static int read_pgmdata(FILE* handle, unsigned char *image) { - int i,status; + int i; char dummy; - - unsigned char* buff1_ptr2 = image + XDIM*YDIM; - unsigned char* buff1_ptr3 = image + XDIM*YDIM + XDIM/2*YDIM/2; + + unsigned char *y = image; + unsigned char *u = image + XDIM*YDIM; + unsigned char *v = image + XDIM*YDIM + XDIM/2*YDIM/2; - fread(image,XDIM*YDIM,1,stdin); // read Y component of picture + /* read Y component of picture */ + fread(y, 1, XDIM*YDIM, handle); - for (i=0;i + xframe.colorspace = XVID_CSP_YV12; // defined in xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0) @@ -315,258 +662,14 @@ xframe.general = general_presets[ARG_QUALITY]; xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; -#ifdef BFRAMES - xframe.bquant = 0; -#endif - xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); -/* enc_result->is_key_frame = xframe.intra; - enc_result->quantizer = xframe.quant; - enc_result->total_bits = xframe.length * 8; - enc_result->motion_bits = xstats.hlength * 8; - enc_result->texture_bits = enc_result->total_bits - enc_result->motion_bits; -*/ - -/* This is statictical data, e.g. for 2-pass. - If you are not interested in any of this, you can use - NULL instead of &xstats -*/ + /* + * This is statictical data, e.g. for 2-pass. If you are not + * interested in any of this, you can use NULL instead of &xstats + */ *frametype = xframe.intra; *streamlength = xframe.length; return xerr; } - -/*********************************************************************/ -/* Main program */ -/*********************************************************************/ - -int main(int argc, char *argv[]) -{ - unsigned char *divx_buffer = NULL; - unsigned char *in_buffer = NULL; - - double enctime; - double totalenctime=0.; - - long totalsize=0; - int status; - - int m4v_size; - int frame_type[ABS_MAXFRAMENR]; - int Iframes=0, Pframes=0, Bframes=0; - int use_assembler=1; - - char filename[256]; - - FILE *filehandle; - -/* read YUV in pgm format from stdin */ - if (!pgmflag) - { - pgmflag = 1; - -// if (argc==2 && !strcmp(argv[1],"-noasm")) -// use_assembler = 0; - - if (argc>=3) - { XDIM = atoi(argv[1]); - YDIM = atoi(argv[2]); - if ( (XDIM <= 0) || (XDIM >= 2048) || (YDIM <=0) || (YDIM >= 2048) ) - { fprintf(stderr,"Wrong frames size %d %d, trying PGM \n",XDIM, YDIM); - } - else - { - YDIM = YDIM*3/2; /* for YUV */ - pgmflag = 0; - } - } - } - - if (pgmflag) - { if (read_pgmheader(stdin)) - { - fprintf(stderr,"Wrong input format, I want YUV encapsulated in PGM\n"); - return 1; - } - } - if (argc>=4) - { ARG_QUALITY = atoi(argv[3]); - if ( (ARG_QUALITY < 0) || (ARG_QUALITY > 6) ) - { fprintf(stderr,"Wrong Quality\n"); return -1; } - else - fprintf(stderr,"Quality %d\n",ARG_QUALITY); - } - if (argc>=5) - { ARG_BITRATE = atoi(argv[4]); - if ( (ARG_BITRATE <= 0) ) - { fprintf(stderr,"Wrong Bitrate\n"); return -1; } - if ( (ARG_BITRATE < 32) ) - { ARG_QUANTI = ARG_BITRATE; - ARG_BITRATE=0; - fprintf(stderr,"Quantizer %d\n",ARG_QUANTI); - } - else - fprintf(stderr,"Bitrate %d kbps\n",ARG_BITRATE); - } - if (argc>=6) - { ARG_FRAMERATE = (float)atof(argv[5]); - if ( (ARG_FRAMERATE <= 0) ) - { fprintf(stderr,"Wrong Fraterate %s \n",argv[5]); return -1; } - fprintf(stderr,"Framerate %6.3f fps\n",ARG_FRAMERATE); - } - - if (argc>=7) - { ARG_MAXFRAMENR = atoi(argv[6]); - if ( (ARG_MAXFRAMENR <= 0) ) - { fprintf(stderr,"Wrong number of frames\n"); return -1; } - fprintf(stderr,"max. Framenr. %d\n",ARG_MAXFRAMENR); - } - -#ifdef BFRAMES - if (argc>=8) - { ARG_MAXBFRAMES = atoi(argv[7]); - if ( (ARG_MAXBFRAMES < -1) || ( ARG_MAXBFRAMES > ARG_FRAMERATE) ) - { fprintf(stderr,"Wrong maximumnumber of bframes\n"); return -1; } - fprintf(stderr,"max. B-frames %d\n",ARG_MAXBFRAMES); - } - - if (argc>=9) - { ARG_MAXFRAMENR = atoi(argv[8]); - if ( (ARG_BQUANTRATIO <= 0) ) - { fprintf(stderr,"Wrong B-frames Quantizer ratio \n"); return -1; } - fprintf(stderr,"B-frames quant-ratio %d\n",ARG_BQUANTRATIO); - } -#endif - -/* now we know the sizes, so allocate memory */ - - in_buffer = (unsigned char *) malloc(XDIM*YDIM); - if (!in_buffer) - goto free_all_memory; - - divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); - if (!divx_buffer) - goto free_all_memory; - - YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so real image height is *2/3 of PGM picture - -/*********************************************************************/ -/* XviD PART Start */ -/*********************************************************************/ - - status = enc_init(use_assembler); - if (status) - { - fprintf(stderr,"Encore INIT problem, return value %d\n", status); - goto release_all; - } - -/*********************************************************************/ -/* Main loop */ -/*********************************************************************/ - - do - { - if (pgmflag) - status = read_pgmdata(stdin, in_buffer); // read PGM data (YUV-format) - else - status = read_yuvdata(stdin, in_buffer); // read raw data (YUV-format) - - if (status) - { - // Couldn't read image, most likely end-of-file - continue; - } - - - if (save_ref_flag) - { - sprintf(filename, "%s%05d.pgm", filepath, filenr); - write_pgm(filename,in_buffer); - } - - -/*********************************************************************/ -/* analyse this frame before encoding */ -/*********************************************************************/ - -// nothing is done here at the moment, but you could e.g. create -// histograms or measure entropy or apply preprocessing filters... - -/*********************************************************************/ -/* encode and decode this frame */ -/*********************************************************************/ - - enctime = -msecond(); - status = enc_main(in_buffer, divx_buffer, &m4v_size, &frame_type[filenr]); - enctime += msecond(); - - totalenctime += enctime; - totalsize += m4v_size; - - fprintf(stderr,"Frame %5d: intra %d, enctime =%6.1f ms length=%7d bytes\n", - filenr, frame_type[filenr], enctime*1000, m4v_size); - - if (save_m4v_flag) - { - fwrite(divx_buffer, m4v_size, 1, stdout); - } - - if (pgmflag) - status = read_pgmheader(stdin); - // because if this was the last PGM, stop now - - filenr++; - - } while ( (!status) && (filenr