--- branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/05/17 13:26:51 1031 +++ branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/08/04 17:23:37 1111 @@ -3,7 +3,9 @@ * XVID MPEG-4 VIDEO CODEC * - Console based test application - * - * Copyright(C) 2002-2003 Christoph Lampert + * Copyright(C) 2002-2003 Christoph Lampert + * 2002-2003 Edouard Gomez + * 2003 Peter Ross * * 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,7 +21,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_encraw.c,v 1.11.2.25 2003-05-17 13:21:26 suxen_drol Exp $ + * $Id: xvid_encraw.c,v 1.11.2.32 2003-08-04 17:23:37 chl Exp $ * ****************************************************************************/ @@ -31,6 +33,8 @@ * * The program is plain C and needs no libraries except for libxvidcore, * and maths-lib. + * + * Use ./xvid_encraw -help for a list of options * ************************************************************************/ @@ -46,11 +50,13 @@ #include "xvid.h" +#undef READ_PNM /***************************************************************************** * Quality presets ****************************************************************************/ -static xvid_motion_t const motion_presets[] = { + +static const int motion_presets[] = { /* quality 0 */ 0, @@ -67,22 +73,22 @@ /* quality 4 */ XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | - XVID_ME_CHROMA16 | XVID_ME_CHROMA8, + XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, /* quality 5 */ XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | - XVID_ME_CHROMA16 | XVID_ME_CHROMA8, + XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, /* quality 6 */ XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 | - XVID_ME_CHROMA16 | XVID_ME_CHROMA8 , + XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, }; #define ME_ELEMENTS (sizeof(motion_presets)/sizeof(motion_presets[0])) -static xvid_vop_t const vop_presets[] = { +static const int vop_presets[] = { /* quality 0 */ 0, @@ -145,7 +151,11 @@ static int ARG_DEBUG = 0; static int ARG_VOPDEBUG = 0; +#ifndef READ_PNM #define IMAGE_SIZE(x,y) ((x)*(y)*3/2) +#else +#define IMAGE_SIZE(x,y) ((x)*(y)*3) +#endif #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) #define SMALL_EPS (1e-10) @@ -176,9 +186,15 @@ static double msecond(); /* PGM related functions */ +#ifndef READ_PNM static int read_pgmheader(FILE * handle); static int read_pgmdata(FILE * handle, unsigned char *image); +#else +static int read_pnmheader(FILE * handle); +static int read_pnmdata(FILE * handle, + unsigned char *image); +#endif static int read_yuvdata(FILE * handle, unsigned char *image); @@ -321,7 +337,6 @@ ARG_OUTPUTFILE = argv[i]; } else if (strcmp("-vop_debug", argv[i]) == 0) { ARG_VOPDEBUG = 1; - } else if (strcmp("-help", argv[i])) { usage(); return (0); @@ -370,7 +385,11 @@ } if (ARG_INPUTTYPE) { +#ifndef READ_PNM if (read_pgmheader(in_file)) { +#else + if (read_pnmheader(in_file)) { +#endif fprintf(stderr, "Wrong input format, I want YUV encapsulated in PGM\n"); return (-1); @@ -436,7 +455,11 @@ if (!result) { if (ARG_INPUTTYPE) { /* read PGM data (YUV-format) */ +#ifndef READ_PNM result = read_pgmdata(in_file, in_buffer); +#else + result = read_pnmdata(in_file, in_buffer); +#endif } else { /* read raw data (YUV-format) */ result = read_yuvdata(in_file, in_buffer); @@ -532,8 +555,11 @@ /* Read the header if it's pgm stream */ if (!result && ARG_INPUTTYPE) - result = read_pgmheader(in_file); - +#ifndef READ_PNM + result = read_pgmheader(in_file); +#else + result = read_pnmheader(in_file); +#endif } while (1); @@ -644,7 +670,7 @@ fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (default=100)\n"); fprintf(stderr, "\n"); fprintf(stderr, "Rate control options:\n"); - fprintf(stderr, " -framerate float : target framerate (>0 | default=25.0)\n"); + fprintf(stderr, " -framerate float : target framerate (>0 | default=25.0)\n"); fprintf(stderr, " -bitrate integer : target bitrate\n"); fprintf(stderr, " -single : single pass mode\n"); fprintf(stderr, " -pass1 filename : twopass mode (first pass)\n"); @@ -659,7 +685,8 @@ fprintf(stderr, " -packed : packed mode\n"); fprintf(stderr, " -lumimasking : use lumimasking algorithm\n"); fprintf(stderr, " -stats : print stats about encoded frames\n"); - fprintf(stderr, " -debug : print all MB dquants\n"); + fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); + fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n"); fprintf(stderr, " -help : prints this help message\n"); fprintf(stderr, "\n"); fprintf(stderr, "NB: You can define %d zones repeating the -z[qw] option as many times as needed.\n", MAX_ZONES); @@ -674,6 +701,7 @@ * *****************************************************************************/ +#ifndef READ_PNM static int read_pgmheader(FILE * handle) { @@ -729,6 +757,46 @@ return (0); } +#else +static int +read_pnmheader(FILE * handle) +{ + int bytes, xsize, ysize, depth; + char dummy[2]; + + bytes = fread(dummy, 1, 2, handle); + + if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '6')) + 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); + } + + XDIM = xsize; + YDIM = ysize; + + return (0); +} + +static int +read_pnmdata(FILE * handle, + unsigned char *image) +{ + int i; + char dummy; + + /* read Y component of picture */ + fread(image, 1, XDIM * YDIM * 3, handle); + + /* I don't know why, but this seems needed */ + fread(&dummy, 1, 1, handle); + + return (0); +} +#endif static int read_yuvdata(FILE * handle, @@ -813,7 +881,6 @@ /* Set version -- version checking will done by xvidcore */ memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); xvid_gbl_init.version = XVID_VERSION; - printf("0x%x\n", ARG_DEBUG); xvid_gbl_init.debug = ARG_DEBUG; @@ -821,7 +888,7 @@ if (use_assembler) { #ifdef ARCH_IS_IA64 - xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; + xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ASM; #else xvid_gbl_init.cpu_flags = 0; #endif @@ -894,11 +961,13 @@ xvid_enc_create.num_plugins++; } - /* if (ARG_DEBUG) { +#if 0 + if (ARG_DEBUG) { plugins[xvid_enc_create.num_plugins].func = rawenc_debug; plugins[xvid_enc_create.num_plugins].param = NULL; xvid_enc_create.num_plugins++; - }*/ + } +#endif /* No fancy thread tests */ xvid_enc_create.num_threads = 0; @@ -913,7 +982,6 @@ } /* Maximum key frame interval */ - if (ARG_MAXKEYINTERVAL > 0) { xvid_enc_create.max_key_interval = ARG_MAXKEYINTERVAL; }else { @@ -985,14 +1053,19 @@ /* Initialize input image fields */ if (image) { xvid_enc_frame.input.plane[0] = image; +#ifndef READ_PNM xvid_enc_frame.input.csp = XVID_CSP_I420; xvid_enc_frame.input.stride[0] = XDIM; +#else + xvid_enc_frame.input.csp = XVID_CSP_BGR; + xvid_enc_frame.input.stride[0] = XDIM*3; +#endif } else { xvid_enc_frame.input.csp = XVID_CSP_NULL; } /* Set up core's general features */ - xvid_enc_frame.vol_flags = 0; + xvid_enc_frame.vol_flags = XVID_VOL_GMC; if (ARG_STATS) xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS;