[cvs] / xvidcore / examples / xvid_encraw.c Repository:
ViewVC logotype

Diff of /xvidcore/examples/xvid_encraw.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11.2.35, Sun Aug 10 13:10:09 2003 UTC revision 1.19, Tue Jul 5 20:55:12 2005 UTC
# Line 141  Line 141 
141  static char *ARG_INPUTFILE = NULL;  static char *ARG_INPUTFILE = NULL;
142  static int ARG_INPUTTYPE = 0;  static int ARG_INPUTTYPE = 0;
143  static int ARG_SAVEMPEGSTREAM = 0;  static int ARG_SAVEMPEGSTREAM = 0;
144    static int ARG_SAVEINDIVIDUAL = 0;
145  static char *ARG_OUTPUTFILE = NULL;  static char *ARG_OUTPUTFILE = NULL;
146  static int XDIM = 0;  static int XDIM = 0;
147  static int YDIM = 0;  static int YDIM = 0;
# Line 150  Line 151 
151  static int ARG_PACKED = 0;  static int ARG_PACKED = 0;
152  static int ARG_DEBUG = 0;  static int ARG_DEBUG = 0;
153  static int ARG_VOPDEBUG = 0;  static int ARG_VOPDEBUG = 0;
154    static int ARG_GREYSCALE = 0;
155  static int ARG_GMC = 0;  static int ARG_GMC = 0;
156    static int ARG_INTERLACING = 0;
157  static int ARG_QPEL = 0;  static int ARG_QPEL = 0;
158    static int ARG_VHQMODE = 0;
159    static int ARG_CLOSED_GOP = 0;
160    
161  #ifndef READ_PNM  #ifndef READ_PNM
162  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
# Line 235  Line 240 
240          int stats_type;          int stats_type;
241          int stats_quant;          int stats_quant;
242          int stats_length;          int stats_length;
243          int use_assembler = 0;          int use_assembler = 1;  // this default changed!
244    
245          int input_num;          int input_num;
246          int output_num;          int output_num;
# Line 262  Line 267 
267    
268                  if (strcmp("-asm", argv[i]) == 0) {                  if (strcmp("-asm", argv[i]) == 0) {
269                          use_assembler = 1;                          use_assembler = 1;
270                    } else if (strcmp("-noasm", argv[i]) == 0) {
271                            use_assembler = 0;
272                  } else if (strcmp("-w", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-w", argv[i]) == 0 && i < argc - 1) {
273                          i++;                          i++;
274                          XDIM = atoi(argv[i]);                          XDIM = atoi(argv[i]);
# Line 308  Line 315 
315                  } else if (strcmp("-quality", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-quality", argv[i]) == 0 && i < argc - 1) {
316                          i++;                          i++;
317                          ARG_QUALITY = atoi(argv[i]);                          ARG_QUALITY = atoi(argv[i]);
318                    } else if (strcmp("-vhqmode", argv[i]) == 0 && i < argc - 1) {
319                            i++;
320                            ARG_VHQMODE = atoi(argv[i]);
321                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {
322                          i++;                          i++;
323                          ARG_FRAMERATE = (float) atof(argv[i]);                          ARG_FRAMERATE = (float) atof(argv[i]);
# Line 326  Line 336 
336                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {
337                          i++;                          i++;
338                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
339                  } else if (strcmp("-nframes", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-frames", argv[i]) == 0 && i < argc - 1) {
340                          i++;                          i++;
341                          ARG_MAXFRAMENR = atoi(argv[i]);                          ARG_MAXFRAMENR = atoi(argv[i]);
342                  } else if (strcmp("-save", argv[i]) == 0) {                  } else if (strcmp("-save", argv[i]) == 0) {
343                          ARG_SAVEMPEGSTREAM = 1;                          ARG_SAVEMPEGSTREAM = 1;
344                            ARG_SAVEINDIVIDUAL = 1;
345                  } else if (strcmp("-debug", argv[i]) == 0) {                  } else if (strcmp("-debug", argv[i]) == 0) {
346                          i++;                          i++;
347              if (sscanf(argv[i],"0x%x", &ARG_DEBUG) || sscanf(argv[i],"%d", &ARG_DEBUG)) ;              if (sscanf(argv[i],"0x%x", &ARG_DEBUG) || sscanf(argv[i],"%d", &ARG_DEBUG)) ;
348                  } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {
349                            ARG_SAVEMPEGSTREAM = 1;
350                          i++;                          i++;
351                          ARG_OUTPUTFILE = argv[i];                          ARG_OUTPUTFILE = argv[i];
352                  } else if (strcmp("-vop_debug", argv[i]) == 0) {                  } else if (strcmp("-vop_debug", argv[i]) == 0) {
353                          ARG_VOPDEBUG = 1;                          ARG_VOPDEBUG = 1;
354                  } else if (strcmp("-qpel", argv[i]) == 0) {                  }
355                    else if (strcmp("-grey", argv[i]) == 0) {
356                            ARG_GREYSCALE = 1;
357                    }
358                    else if (strcmp("-qpel", argv[i]) == 0) {
359                          ARG_QPEL = 1;                          ARG_QPEL = 1;
360                  } else if (strcmp("-gmc", argv[i]) == 0) {                  } else if (strcmp("-gmc", argv[i]) == 0) {
361                          ARG_GMC = 1;                          ARG_GMC = 1;
362                    } else if (strcmp("-interlaced", argv[i]) == 0) {
363                            ARG_INTERLACING = 1;
364                    } else if (strcmp("-closed_gop", argv[i]) == 0) {
365                            ARG_CLOSED_GOP = 1;
366                  } else if (strcmp("-help", argv[i])) {                  } else if (strcmp("-help", argv[i])) {
367                          usage();                          usage();
368                          return (0);                          return (0);
# Line 357  Line 377 
377   *                            Arguments checking   *                            Arguments checking
378   ****************************************************************************/   ****************************************************************************/
379    
380          if (XDIM <= 0 || XDIM >= 2048 || YDIM <= 0 || YDIM >= 2048) {          if (XDIM <= 0 || XDIM >= 4096 || YDIM <= 0 || YDIM >= 4096) {
381                  fprintf(stderr,                  fprintf(stderr,
382                                  "Trying to retreive width and height from PGM header\n");                                  "Trying to retreive width and height from PGM header\n");
383                  ARG_INPUTTYPE = 1;              /* pgm */                  ARG_INPUTTYPE = 1;              /* pgm */
# Line 541  Line 561 
561   ****************************************************************************/   ****************************************************************************/
562    
563                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {
564    
565                          /* Save single files */                          /* Save single files */
566                          if (out_file == NULL) {                          if (ARG_SAVEINDIVIDUAL) {
567                                    FILE *out;
568                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
569                                  out_file = fopen(filename, "wb");                                  out = fopen(filename, "w+b");
570                                  fwrite(mp4_buffer, m4v_size, 1, out_file);                                  fwrite(mp4_buffer, m4v_size, 1, out);
571                                  fclose(out_file);                                  fclose(out);
                                 out_file = NULL;  
572                                  output_num++;                                  output_num++;
573                          } else {                          }
574    
575                                  /* Write mp4 data */                          /* Save ES stream */
576                            if (ARG_OUTPUTFILE && out_file)
577                                  fwrite(mp4_buffer, 1, m4v_size, out_file);                                  fwrite(mp4_buffer, 1, m4v_size, out_file);
   
                         }  
578                  }                  }
579    
580                  input_num++;                  input_num++;
# Line 663  Line 683 
683          fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");          fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");
684          fprintf(stderr, " -w       integer: frame width ([1.2048])\n");          fprintf(stderr, " -w       integer: frame width ([1.2048])\n");
685          fprintf(stderr, " -h       integer: frame height ([1.2048])\n");          fprintf(stderr, " -h       integer: frame height ([1.2048])\n");
686          fprintf(stderr, " -nframes integer: number of frames to encode\n");          fprintf(stderr, " -frames integer: number of frames to encode\n");
687          fprintf(stderr, "\n");          fprintf(stderr, "\n");
688          fprintf(stderr, "Output options:\n");          fprintf(stderr, "Output options:\n");
689          fprintf(stderr, " -dump    : save decoder output\n");          fprintf(stderr, " -dump    : save decoder output\n");
690          fprintf(stderr, " -save    : save mpeg4 raw stream\n");          fprintf(stderr, " -save    : save an Elementary Stream file per frame\n");
691          fprintf(stderr, " -o string: output filename\n");          fprintf(stderr, " -o string: save an Elementary Stream for the complete sequence\n");
692          fprintf(stderr, "\n");          fprintf(stderr, "\n");
693          fprintf(stderr, "BFrames options:\n");          fprintf(stderr, "BFrames options:\n");
694          fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");          fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");
# Line 687  Line 707 
707      fprintf(stderr, "\n");      fprintf(stderr, "\n");
708          fprintf(stderr, "Other options\n");          fprintf(stderr, "Other options\n");
709          fprintf(stderr, " -asm            : use assembly optmized code\n");          fprintf(stderr, " -asm            : use assembly optmized code\n");
710            fprintf(stderr, " -noasm            : do not use assembly optmized code\n");
711          fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1);          fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1);
712            fprintf(stderr, " -vhqmode integer: level of Rate-Distorsion optimizations ([0..4]) (default=0)\n");
713          fprintf(stderr, " -qpel           : use quarter pixel ME\n");          fprintf(stderr, " -qpel           : use quarter pixel ME\n");
714          fprintf(stderr, " -gmc            : use global motion compensation\n");          fprintf(stderr, " -gmc            : use global motion compensation\n");
715            fprintf(stderr, " -interlaced     : use interlaced encoding (this is NOT a deinterlacer!)\n");
716          fprintf(stderr, " -packed         : packed mode\n");          fprintf(stderr, " -packed         : packed mode\n");
717            fprintf(stderr, " -closed_gop     : closed GOP mode\n");
718            fprintf(stderr, " -grey           : grey scale coding (chroma is discarded)\n");
719          fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");          fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");
720          fprintf(stderr, " -stats          : print stats about encoded frames\n");          fprintf(stderr, " -stats          : print stats about encoded frames\n");
721          fprintf(stderr, " -debug          : activates xvidcore internal debugging output\n");          fprintf(stderr, " -debug          : activates xvidcore internal debugging output\n");
# Line 722  Line 747 
747                  return (1);                  return (1);
748    
749          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
750          if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) {          if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) {
751                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
752                  return (2);                  return (2);
753          }          }
# Line 918  Line 943 
943          /* Width and Height of input frames */          /* Width and Height of input frames */
944          xvid_enc_create.width = XDIM;          xvid_enc_create.width = XDIM;
945          xvid_enc_create.height = YDIM;          xvid_enc_create.height = YDIM;
946            xvid_enc_create.profile = XVID_PROFILE_AS_L4;
947    
948          /* init plugins  */          /* init plugins  */
949      xvid_enc_create.zones = ZONES;      xvid_enc_create.zones = ZONES;
# Line 942  Line 968 
968                  rc2pass2.filename = ARG_PASS2;                  rc2pass2.filename = ARG_PASS2;
969                  rc2pass2.bitrate = ARG_BITRATE;                  rc2pass2.bitrate = ARG_BITRATE;
970    
971    /*              An example of activating VBV could look like this
972                    rc2pass2.vbv_size     =  3145728;
973                    rc2pass2.vbv_initial  =  2359296;
974                    rc2pass2.vbv_maxrate  =  4000000;
975                    rc2pass2.vbv_peakrate = 10000000;
976    */
977    
978                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
979                  plugins[xvid_enc_create.num_plugins].param = &rc2pass2;                  plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
980                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
# Line 1010  Line 1043 
1043          if (ARG_PACKED)          if (ARG_PACKED)
1044                  xvid_enc_create.global |=XVID_GLOBAL_PACKED;                  xvid_enc_create.global |=XVID_GLOBAL_PACKED;
1045    
1046            if (ARG_CLOSED_GOP)
1047                    xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
1048    
1049          if (ARG_STATS)          if (ARG_STATS)
1050                  xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;                  xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;
1051    
# Line 1080  Line 1116 
1116                  xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL;                  xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL;
1117          if (ARG_GMC)          if (ARG_GMC)
1118                  xvid_enc_frame.vol_flags |= XVID_VOL_GMC;                  xvid_enc_frame.vol_flags |= XVID_VOL_GMC;
1119            if (ARG_INTERLACING)
1120                    xvid_enc_frame.vol_flags |= XVID_VOL_INTERLACING;
1121    
1122          /* Set up core's general features */          /* Set up core's general features */
1123          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
         if (ARG_GMC)  
                 xvid_enc_frame.vop_flags |= XVID_ME_GME_REFINE;  
1124    
1125      if (ARG_VOPDEBUG) {      if (ARG_VOPDEBUG) {
1126          xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG;          xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG;
1127      }      }
1128    
1129        if (ARG_GREYSCALE) {
1130            xvid_enc_frame.vop_flags |= XVID_VOP_GREYSCALE;
1131        }
1132    
1133          /* Frame type -- let core decide for us */          /* Frame type -- let core decide for us */
1134          xvid_enc_frame.type = XVID_TYPE_AUTO;          xvid_enc_frame.type = XVID_TYPE_AUTO;
1135    
# Line 1099  Line 1139 
1139          /* Set up motion estimation flags */          /* Set up motion estimation flags */
1140          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];
1141    
1142            if (ARG_GMC)
1143                    xvid_enc_frame.motion |= XVID_ME_GME_REFINE;
1144    
1145          if (ARG_QPEL)          if (ARG_QPEL)
1146                  xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16;                  xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16;
1147          if (ARG_QPEL && (xvid_enc_frame.vop_flags & XVID_VOP_INTER4V))          if (ARG_QPEL && (xvid_enc_frame.vop_flags & XVID_VOP_INTER4V))
1148                  xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8;                  xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8;
1149    
1150            switch (ARG_VHQMODE) /* this is the same code as for vfw */
1151            {
1152            case 1: /* VHQ_MODE_DECISION */
1153                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1154                    break;
1155    
1156            case 2: /* VHQ_LIMITED_SEARCH */
1157                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1158                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE16_RD;
1159                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;
1160                    break;
1161    
1162            case 3: /* VHQ_MEDIUM_SEARCH */
1163                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1164                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE16_RD;
1165                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE8_RD;
1166                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;
1167                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8_RD;
1168                    xvid_enc_frame.motion |= XVID_ME_CHECKPREDICTION_RD;
1169                    break;
1170    
1171            case 4: /* VHQ_WIDE_SEARCH */
1172                    xvid_enc_frame.vop_flags |= XVID_VOP_MODEDECISION_RD;
1173                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE16_RD;
1174                    xvid_enc_frame.motion |= XVID_ME_HALFPELREFINE8_RD;
1175                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16_RD;
1176                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8_RD;
1177                    xvid_enc_frame.motion |= XVID_ME_CHECKPREDICTION_RD;
1178                    xvid_enc_frame.motion |= XVID_ME_EXTSEARCH_RD;
1179                    break;
1180    
1181            default :
1182                    break;
1183            }
1184    
1185          /* We don't use special matrices */          /* We don't use special matrices */
1186          xvid_enc_frame.quant_intra_matrix = NULL;          xvid_enc_frame.quant_intra_matrix = NULL;
1187          xvid_enc_frame.quant_inter_matrix = NULL;          xvid_enc_frame.quant_inter_matrix = NULL;

Legend:
Removed from v.1.11.2.35  
changed lines
  Added in v.1.19

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4