--- branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/08/02 15:08:48 1107 +++ branches/dev-api-4/xvidcore/examples/xvid_encraw.c 2003/12/17 08:38:06 1265 @@ -21,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.30 2003-08-02 15:07:59 edgomez Exp $ + * $Id: xvid_encraw.c,v 1.11.2.40 2003-12-17 08:38:06 chl Exp $ * ****************************************************************************/ @@ -141,6 +141,7 @@ static char *ARG_INPUTFILE = NULL; static int ARG_INPUTTYPE = 0; static int ARG_SAVEMPEGSTREAM = 0; +static int ARG_SAVEINDIVIDUAL = 0; static char *ARG_OUTPUTFILE = NULL; static int XDIM = 0; static int YDIM = 0; @@ -150,6 +151,9 @@ static int ARG_PACKED = 0; static int ARG_DEBUG = 0; static int ARG_VOPDEBUG = 0; +static int ARG_GMC = 0; +static int ARG_QPEL = 0; +static int ARG_CLOSED_GOP = 0; #ifndef READ_PNM #define IMAGE_SIZE(x,y) ((x)*(y)*3/2) @@ -324,19 +328,27 @@ } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) { i++; ARG_INPUTTYPE = atoi(argv[i]); - } else if (strcmp("-nframes", argv[i]) == 0 && i < argc - 1) { + } else if (strcmp("-frames", argv[i]) == 0 && i < argc - 1) { i++; ARG_MAXFRAMENR = atoi(argv[i]); } else if (strcmp("-save", argv[i]) == 0) { ARG_SAVEMPEGSTREAM = 1; + ARG_SAVEINDIVIDUAL = 1; } else if (strcmp("-debug", argv[i]) == 0) { i++; if (sscanf(argv[i],"0x%x", &ARG_DEBUG) || sscanf(argv[i],"%d", &ARG_DEBUG)) ; } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) { + ARG_SAVEMPEGSTREAM = 1; i++; ARG_OUTPUTFILE = argv[i]; } else if (strcmp("-vop_debug", argv[i]) == 0) { ARG_VOPDEBUG = 1; + } else if (strcmp("-qpel", argv[i]) == 0) { + ARG_QPEL = 1; + } else if (strcmp("-gmc", argv[i]) == 0) { + ARG_GMC = 1; + } else if (strcmp("-closed_gop", argv[i]) == 0) { + ARG_CLOSED_GOP = 1; } else if (strcmp("-help", argv[i])) { usage(); return (0); @@ -351,7 +363,7 @@ * Arguments checking ****************************************************************************/ - if (XDIM <= 0 || XDIM >= 2048 || YDIM <= 0 || YDIM >= 2048) { + if (XDIM <= 0 || XDIM >= 4096 || YDIM <= 0 || YDIM >= 4096) { fprintf(stderr, "Trying to retreive width and height from PGM header\n"); ARG_INPUTTYPE = 1; /* pgm */ @@ -535,20 +547,20 @@ ****************************************************************************/ if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) { + /* Save single files */ - if (out_file == NULL) { + if (ARG_SAVEINDIVIDUAL) { + FILE *out; sprintf(filename, "%sframe%05d.m4v", filepath, output_num); - out_file = fopen(filename, "wb"); - fwrite(mp4_buffer, m4v_size, 1, out_file); - fclose(out_file); - out_file = NULL; + out = fopen(filename, "w+b"); + fwrite(mp4_buffer, m4v_size, 1, out); + fclose(out); output_num++; - } else { + } - /* Write mp4 data */ + /* Save ES stream */ + if (ARG_OUTPUTFILE && out_file) fwrite(mp4_buffer, 1, m4v_size, out_file); - - } } input_num++; @@ -653,16 +665,16 @@ { fprintf(stderr, "Usage : xvid_stat [OPTIONS]\n\n"); fprintf(stderr, "Input options:\n"); - fprintf(stderr, " -i string : input filename (default=stdin)\n"); - fprintf(stderr, " -type integer: input data type (yuv=0, pgm=1)\n"); - fprintf(stderr, " -w integer: frame width ([1.2048])\n"); - fprintf(stderr, " -h integer: frame height ([1.2048])\n"); - fprintf(stderr, " -nframes integer: number of frames to encode\n"); + fprintf(stderr, " -i string : input filename (default=stdin)\n"); + fprintf(stderr, " -type integer: input data type (yuv=0, pgm=1)\n"); + fprintf(stderr, " -w integer: frame width ([1.2048])\n"); + fprintf(stderr, " -h integer: frame height ([1.2048])\n"); + fprintf(stderr, " -frames integer: number of frames to encode\n"); fprintf(stderr, "\n"); fprintf(stderr, "Output options:\n"); fprintf(stderr, " -dump : save decoder output\n"); - fprintf(stderr, " -save : save mpeg4 raw stream\n"); - fprintf(stderr, " -o string: output filename\n"); + fprintf(stderr, " -save : save an Elementary Stream file per frame\n"); + fprintf(stderr, " -o string: save an Elementary Stream for the complete sequence\n"); fprintf(stderr, "\n"); fprintf(stderr, "BFrames options:\n"); fprintf(stderr, " -max_bframes integer: max bframes (default=0)\n"); @@ -682,7 +694,10 @@ fprintf(stderr, "Other options\n"); fprintf(stderr, " -asm : use assembly optmized code\n"); fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1); + fprintf(stderr, " -qpel : use quarter pixel ME\n"); + fprintf(stderr, " -gmc : use global motion compensation\n"); fprintf(stderr, " -packed : packed mode\n"); + fprintf(stderr, " -closed_gop : closed GOP mode\n"); fprintf(stderr, " -lumimasking : use lumimasking algorithm\n"); fprintf(stderr, " -stats : print stats about encoded frames\n"); fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); @@ -910,6 +925,7 @@ /* Width and Height of input frames */ xvid_enc_create.width = XDIM; xvid_enc_create.height = YDIM; + xvid_enc_create.profile = XVID_PROFILE_AS_L4; /* init plugins */ xvid_enc_create.zones = ZONES; @@ -1000,10 +1016,13 @@ xvid_enc_create.global = 0; if (ARG_PACKED) - xvid_enc_create.global |=XVID_GLOBAL_PACKED; + xvid_enc_create.global |= XVID_GLOBAL_PACKED; + + if (ARG_CLOSED_GOP) + xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; if (ARG_STATS) - xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE; + xvid_enc_create.global |= XVID_GLOBAL_EXTRASTATS_ENABLE; /* 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); @@ -1068,9 +1087,14 @@ xvid_enc_frame.vol_flags = 0; if (ARG_STATS) xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS; + if (ARG_QPEL) + xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL; + if (ARG_GMC) + xvid_enc_frame.vol_flags |= XVID_VOL_GMC; /* Set up core's general features */ xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY]; + if (ARG_VOPDEBUG) { xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG; } @@ -1084,14 +1108,21 @@ /* Set up motion estimation flags */ xvid_enc_frame.motion = motion_presets[ARG_QUALITY]; + if (ARG_GMC) + xvid_enc_frame.motion |= XVID_ME_GME_REFINE; + + if (ARG_QPEL) + xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16; + if (ARG_QPEL && (xvid_enc_frame.vop_flags & XVID_VOP_INTER4V)) + xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8; + /* We don't use special matrices */ xvid_enc_frame.quant_intra_matrix = NULL; xvid_enc_frame.quant_inter_matrix = NULL; /* Encode the frame */ - ret = - xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, - &xvid_enc_stats); + 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;