--- trunk/xvidcore/examples/xvid_encraw.c 2002/09/28 16:01:15 566 +++ branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/03/13 11:07:20 919 @@ -3,7 +3,7 @@ * XVID MPEG-4 VIDEO CODEC * - Console based test application - * - * Copyright(C) 2002 Christoph Lampert + * Copyright(C) 2002-2003 Christoph Lampert * * 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 @@ -19,15 +19,15 @@ * 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.4 2002-09-28 16:01:15 edgomez Exp $ + * $Id: xvid_encraw.c,v 1.11.2.5 2003-03-13 11:07:20 suxen_drol Exp $ * ****************************************************************************/ /***************************************************************************** * Application notes : * - * A sequence of YUV pics in PGM file format is encoded and decoded - * The speed is measured and PSNR of decoded picture is calculated. + * A sequence of raw YUV I420 pics or YUV I420 PGM file format is encoded + * The speed is measured and frames' PSNR are taken from core. * * The program is plain C and needs no libraries except for libxvidcore, * and maths-lib. @@ -38,7 +38,7 @@ #include #include #include -#ifndef _MSC_VER +#ifndef WIN32 #include #else #include @@ -50,28 +50,32 @@ * 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 xvid_motion_t const motion_presets[] = { + 0, + PMV_HALFPELREFINE16, + PMV_HALFPELREFINE16, + PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8, + PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16, + PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16 | PMV_CHROMA16 | PMV_CHROMA8, }; -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 +static xvid_vol_t const vol_presets[] = { + XVID_MPEGQUANT, + 0, + 0, + XVID_QUARTERPEL, + XVID_QUARTERPEL | XVID_GMC, + XVID_QUARTERPEL | XVID_GMC +}; + +static xvid_vop_t const vop_presets[] = { + XVID_DYNAMIC_BFRAMES, + XVID_DYNAMIC_BFRAMES, + XVID_DYNAMIC_BFRAMES | XVID_HALFPEL, + XVID_DYNAMIC_BFRAMES | XVID_HALFPEL | XVID_INTER4V, + XVID_DYNAMIC_BFRAMES | XVID_HALFPEL | XVID_INTER4V | XVID_HQACPRED, + XVID_DYNAMIC_BFRAMES | XVID_HALFPEL | XVID_INTER4V | XVID_HQACPRED | XVID_MODEDECISION_BITS }; - /***************************************************************************** * Command line global variables @@ -80,9 +84,10 @@ /* Maximum number of frames to encode */ #define ABS_MAXFRAMENR 9999 +static int ARG_STATS = 0; static int ARG_BITRATE = 900; static int ARG_QUANTI = 0; -static int ARG_QUALITY = 6; +static int ARG_QUALITY = 5; static int ARG_MINQUANT = 1; static int ARG_MAXQUANT = 31; static float ARG_FRAMERATE = 25.00f; @@ -90,17 +95,17 @@ 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; +static int ARG_BQRATIO = 150; +static int ARG_BQOFFSET = 100; +static int ARG_MAXBFRAMES = 0; +static int ARG_PACKED = 0; #define IMAGE_SIZE(x,y) ((x)*(y)*3/2) #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) -#define SMALL_EPS 1e-10 - -#define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \ - (((long)(c))<<8) |((long)(d))) +#define SMALL_EPS (1e-10) #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \ (((a)&0x00ff0000)>>8) | (((a)&0xff000000)>>24) ) @@ -135,8 +140,13 @@ /* 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); +static int enc_main(unsigned char* image, + unsigned char* bitstream, + int *key, + int *stats_type, + int *stats_quant, + int *stats_length, + int stats[3]); /***************************************************************************** * Main function @@ -152,12 +162,13 @@ double enctime; double totalenctime=0.; - long totalsize; + int totalsize; int status; - int frame_type; - int bigendian; - int m4v_size; + int key; + int stats_type; + int stats_quant; + int stats_length; int use_assembler=0; char filename[256]; @@ -165,8 +176,8 @@ FILE *in_file = stdin; FILE *out_file = NULL; - printf("xvid_decraw - raw mpeg4 bitstream encoder "); - printf("written by Christoph Lampert 2002\n\n"); + printf("xvid_encraw - raw mpeg4 bitstream encoder "); + printf("written by Christoph Lampert 2002-2003\n\n"); /***************************************************************************** * Command line parsing @@ -189,6 +200,21 @@ i++; ARG_BITRATE = atoi(argv[i]); } + else if (strcmp("-bn", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_MAXBFRAMES = atoi(argv[i]); + } + else if (strcmp("-p", argv[i]) == 0) { + ARG_PACKED = 1; + } + else if (strcmp("-bqr", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_BQRATIO = atoi(argv[i]); + } + else if (strcmp("-bqo", argv[i]) == 0 && i < argc - 1 ) { + i++; + ARG_BQOFFSET = atoi(argv[i]); + } else if (strcmp("-q", argv[i]) == 0 && i < argc - 1 ) { i++; ARG_QUALITY = atoi(argv[i]); @@ -201,6 +227,9 @@ i++; ARG_INPUTFILE = argv[i]; } + else if (strcmp("-s", argv[i]) == 0) { + ARG_STATS = 1; + } else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) { i++; ARG_INPUTTYPE = atoi(argv[i]); @@ -213,13 +242,8 @@ 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("-m", argv[i]) == 0) { + ARG_SAVEMPEGSTREAM = 1; } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) { i++; @@ -245,24 +269,24 @@ ARG_INPUTTYPE = 1; /* pgm */ } - if ( ARG_QUALITY < 0 || ARG_QUALITY > 6) { + if ( ARG_QUALITY < 0 || ARG_QUALITY > 5) { fprintf(stderr,"Wrong Quality\n"); - return -1; + return(-1); } if ( ARG_BITRATE <= 0 && ARG_QUANTI == 0) { fprintf(stderr,"Wrong Bitrate\n"); - return -1; + return(-1); } if ( ARG_FRAMERATE <= 0) { fprintf(stderr,"Wrong Framerate %s \n",argv[5]); - return -1; + return(-1); } if ( ARG_MAXFRAMENR <= 0) { fprintf(stderr,"Wrong number of frames\n"); - return -1; + return(-1); } if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { @@ -273,19 +297,18 @@ in_file = fopen(ARG_INPUTFILE, "rb"); if (in_file == NULL) { fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE); - return -1; + return(-1); } } if (ARG_INPUTTYPE) { if (read_pgmheader(in_file)) { fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n"); - return -1; + 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; @@ -311,35 +334,13 @@ * Main loop ****************************************************************************/ - totalsize = LONG_PACK('M','P','4','U'); - if(*((char *)(&totalsize)) == 'M') - bigendian = 1; - else - bigendian = 0; - - 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 (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) { 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) { - - long test = LONG_PACK('M','P','4','U'); - - test = (!bigendian)?SWAP(test):test; - - fwrite(&test, sizeof(test), 1, out_file); - - } - } else { out_file = NULL; @@ -353,13 +354,18 @@ 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) + char *type; + int stats[3]; + + if(ARG_INPUTTYPE) { + /* read PGM data (YUV-format) */ + status = read_pgmdata(in_file, in_buffer); + } else { + /* read raw data (YUV-format) */ + status = read_yuvdata(in_file, in_buffer); + } - if (status) - { + if(status) { /* Couldn't read image, most likely end-of-file */ continue; } @@ -369,14 +375,61 @@ ****************************************************************************/ enctime = msecond(); - status = enc_main(in_buffer, mp4_buffer, &m4v_size, &frame_type); + m4v_size = enc_main(in_buffer, mp4_buffer, &key, &stats_type, &stats_quant, &stats_length, stats); enctime = msecond() - enctime; + /* Write the Frame statistics */ + + printf("Frame %5d: key=%i, time(ms)=%6.1f, length=%7d", + (int)filenr, + key, + (float)enctime, + (int)m4v_size); + + if (stats_type > 0) { /* !XVID_TYPE_NOTHING */ + + switch(stats_type) { + case XVID_TYPE_IVOP: + type = "I"; + break; + case XVID_TYPE_PVOP: + type = "P"; + break; + case XVID_TYPE_BVOP: + type = "B"; + break; + case XVID_TYPE_SVOP: + type = "S"; + break; + default: + type = "U"; + break; + } + + printf(" | type=%s quant=%2d, length=%7d", type, stats_quant, stats_length); + + if(ARG_STATS) { + printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f", + (stats[0] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[0]/((float)(XDIM)*(YDIM))), + (stats[1] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[1]/((float)(XDIM)*(YDIM)/4)), + (stats[2] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[2]/((float)(XDIM)*(YDIM)/4))); + } + } + + printf("\n"); + + + /* Update encoding time stats */ 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); + /* Not coded frames return 0 */ + if(m4v_size == 0) goto next_frame; + + +/***************************************************************************** + * Save stream to file + ****************************************************************************/ if (ARG_SAVEMPEGSTREAM) { @@ -389,25 +442,20 @@ 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); + fwrite(mp4_buffer, 1, m4v_size, out_file); } } + filenr++; + + next_frame: /* 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, " -bn integer : max bframes (default=0)\n"); + fprintf(stderr, " -p : packed mode\n"); + fprintf(stderr, " -bqr integer : bframe quantizer ratio (default=150)\n"); + fprintf(stderr, " -bqo integer : bframe quantizer offset (default=100)\n"); fprintf(stderr, " -f float : target framerate (>0)\n"); fprintf(stderr, " -i string : input filename (default=stdin)\n"); + fprintf(stderr, " -s : print stats about encoded frames\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, " -m : save mpeg4 raw stream\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, " When this option is used : save to 'string' file\n"); fprintf(stderr, " -help : prints this help message\n"); fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n"); fprintf(stderr, " (* means default)\n"); @@ -518,13 +570,13 @@ bytes = fread(dummy,1,2,handle); if ( (bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5' )) - return 1; + 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; + return(2); } if ( (XDIM==0) || (YDIM==0) ) { @@ -532,7 +584,7 @@ YDIM=ysize*2/3; } - return 0; + return(0); } static int read_pgmdata(FILE* handle, unsigned char *image) @@ -563,113 +615,208 @@ /* I don't know why, but this seems needed */ fread(&dummy, 1, 1, handle); - return 0; + return(0); } static int read_yuvdata(FILE* handle, unsigned char *image) { if (fread(image, 1, IMAGE_SIZE(XDIM, YDIM), handle) != (unsigned int)IMAGE_SIZE(XDIM, YDIM)) - return 1; + return(1); else - return 0; + return(0); } /***************************************************************************** * Routines for encoding: init encoder, frame step, release encoder ****************************************************************************/ +/* sample plugin */ + +int rawenc_debug(void * handle, int opt, void * param1, void * param2) +{ + switch(opt) + { + case XVID_PLG_INFO : + case XVID_PLG_CREATE : + case XVID_PLG_DESTROY : + case XVID_PLG_BEFORE : + return 0; + + case XVID_PLG_AFTER : + { + xvid_plg_data_t * data = (xvid_plg_data_t*)param1; + printf("type=%i, quant=%i, length=%i\n", data->type, data->quant, data->length); + return 0; + } + } + + return XVID_ERR_FAIL; +} + + #define FRAMERATE_INCR 1001 /* Initialize encoder for first use, pass all needed parameters to the codec */ static int enc_init(int use_assembler) { int xerr; + + /* xvid_enc_plugin_t plugins[1]; */ - XVID_INIT_PARAM xinit; - XVID_ENC_PARAM xparam; + xvid_gbl_init_t xvid_gbl_init; + xvid_enc_create_t xvid_enc_create; + /*------------------------------------------------------------------------ + * XviD core initialization + *----------------------------------------------------------------------*/ + + /* Set version -- version checking will done by xvidcore*/ + memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); + xvid_gbl_init.version = XVID_VERSION; + + + /* Do we have to enable ASM optimizations ? */ if(use_assembler) { -#ifdef ARCH_IA64 - xinit.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; +#ifdef ARCH_IS_IA64 + xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; #else - xinit.cpu_flags = 0; + xvid_gbl_init.cpu_flags = 0; #endif } else { - xinit.cpu_flags = XVID_CPU_FORCE; + xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; } - xvid_init(NULL, 0, &xinit, NULL); + /* Initialize XviD core -- Should be done once per __process__ */ + xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); - xparam.width = XDIM; - xparam.height = YDIM; - if ((ARG_FRAMERATE - (int)ARG_FRAMERATE) < SMALL_EPS) - { - xparam.fincr = 1; - xparam.fbase = (int)ARG_FRAMERATE; - } - else - { - xparam.fincr = FRAMERATE_INCR; - xparam.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE); + /*------------------------------------------------------------------------ + * XviD encoder initialization + *----------------------------------------------------------------------*/ + + /* Version again */ + memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); + xvid_enc_create.version = XVID_VERSION; + + /* Width and Height of input frames */ + xvid_enc_create.width = XDIM; + xvid_enc_create.height = YDIM; + + /* init plugins + plugins[0].func = rawenc_debug; + plugins[0].param = NULL; + xvid_enc_create.num_plugins = 1; + xvid_enc_create.plugins = plugins; */ + + /* No fancy thread tests */ + xvid_enc_create.num_threads = 0; + + /* Frame rate - Do some quick float fps = fincr/fbase hack */ + if ((ARG_FRAMERATE - (int)ARG_FRAMERATE) < SMALL_EPS) { + xvid_enc_create.fincr = 1; + xvid_enc_create.fbase = (int)ARG_FRAMERATE; + } else { + xvid_enc_create.fincr = FRAMERATE_INCR; + xvid_enc_create.fbase = (int)(FRAMERATE_INCR * ARG_FRAMERATE); } - xparam.rc_reaction_delay_factor = 16; - xparam.rc_averaging_period = 100; - xparam.rc_buffer = 10; - xparam.rc_bitrate = ARG_BITRATE*1000; - xparam.min_quantizer = ARG_MINQUANT; - xparam.max_quantizer = ARG_MAXQUANT; - xparam.max_key_interval = (int)ARG_FRAMERATE*10; + + /* Maximum key frame interval */ + xvid_enc_create.max_key_interval = (int)ARG_FRAMERATE*10; + + /* Bframes settings */ + xvid_enc_create.max_bframes = ARG_MAXBFRAMES; + xvid_enc_create.bquant_ratio = ARG_BQRATIO; + xvid_enc_create.bquant_offset = ARG_BQOFFSET; + + /* Dropping ratio frame -- we don't need that */ + xvid_enc_create.frame_drop_ratio = 0; + + /* Global encoder options */ + xvid_enc_create.global = 0; + if (ARG_STATS) xvid_enc_create.global |= XVID_EXTRASTATS_ENABLE; + if (ARG_PACKED) xvid_enc_create.global |= XVID_PACKED; /* I use a small value here, since will not encode whole movies, but short clips */ + xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); - xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xparam, NULL); - enc_handle=xparam.handle; + /* Retrieve the encoder instance from the structure */ + enc_handle = xvid_enc_create.handle; - return xerr; + return(xerr); } static int enc_stop() { int xerr; + /* Destroy the encoder instance */ xerr = xvid_encore(enc_handle, XVID_ENC_DESTROY, NULL, NULL); - return xerr; + return(xerr); } -static int enc_main(unsigned char* image, unsigned char* bitstream, - int *streamlength, int* frametype) +static int enc_main(unsigned char* image, + unsigned char* bitstream, + int * key, + int *stats_type, + int *stats_quant, + int *stats_length, + int stats[3]) { - int xerr; - - XVID_ENC_FRAME xframe; - XVID_ENC_STATS xstats; - - xframe.bitstream = bitstream; - xframe.length = -1; // this is written by the routine + int ret; - xframe.image = image; - xframe.colorspace = XVID_CSP_YV12; // defined in + xvid_enc_frame_t xvid_enc_frame; + xvid_enc_stats_t xvid_enc_stats; - xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0) - - xframe.quant = ARG_QUANTI; // is quant != 0, use a fixed quant (and ignore bitrate) - - xframe.motion = motion_presets[ARG_QUALITY]; - xframe.general = general_presets[ARG_QUALITY]; - xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL; - - xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats); + /* Version for the frame and the stats */ + memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame)); + xvid_enc_frame.version = XVID_VERSION; + + memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats)); + xvid_enc_stats.version = XVID_VERSION; + + /* Bind output buffer */ + xvid_enc_frame.bitstream = bitstream; + xvid_enc_frame.length = -1; + + /* Initialize input image fields */ + xvid_enc_frame.input.plane[0] = image; + xvid_enc_frame.input.csp = XVID_CSP_I420; + xvid_enc_frame.input.stride[0] = XDIM; + + /* Set up core's general features */ + xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY]; + + /* Set up core's general features */ + xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY]; + + /* Frame type -- let core decide for us */ + xvid_enc_frame.type = XVID_TYPE_AUTO; + + /* Force the right quantizer */ + xvid_enc_frame.quant = ARG_QUANTI; + xvid_enc_frame.bquant = 0; + + /* Set up motion estimation flags */ + xvid_enc_frame.motion = motion_presets[ARG_QUALITY]; - /* - * 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; + /* We don't use special matrices */ + xvid_enc_frame.quant_intra_matrix = NULL; + xvid_enc_frame.quant_inter_matrix = NULL; + + /* Encode the frame */ + xvid_enc_frame.vop_flags |= (ARG_STATS)?XVID_EXTRASTATS:0; + ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats); + + *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME); + *stats_type = xvid_enc_stats.type; + *stats_quant = xvid_enc_stats.quant; + *stats_length = xvid_enc_stats.length; + stats[0] = xvid_enc_stats.sse_y; + stats[1] = xvid_enc_stats.sse_u; + stats[2] = xvid_enc_stats.sse_v; - return xerr; + return(ret); }