[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.31, Mon Aug 4 17:22:36 2003 UTC revision 1.17, Wed Jun 22 06:18:14 2005 UTC
# Line 58  Line 58 
58    
59  static const int motion_presets[] = {  static const int motion_presets[] = {
60          /* quality 0 */          /* quality 0 */
61          XVID_ME_GME_REFINE,          0,
62    
63          /* quality 1 */          /* quality 1 */
64          XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16,          XVID_ME_ADVANCEDDIAMOND16,
65    
66          /* quality 2 */          /* quality 2 */
67          XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16,          XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16,
68    
69          /* quality 3 */          /* quality 3 */
70          XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |          XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
71          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8,          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8,
72    
73          /* quality 4 */          /* quality 4 */
74          XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |          XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
75          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |
76          XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,          XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,
77    
78          /* quality 5 */          /* quality 5 */
79          XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |          XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 |
80          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 |
81          XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,          XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,
82    
83          /* quality 6 */          /* quality 6 */
84          XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |          XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |
85          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 |          XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 |
86          XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,          XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP,
87    
# 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;
156    static int ARG_INTERLACING = 0;
157    static int ARG_QPEL = 0;
158    static int ARG_CLOSED_GOP = 0;
159    
160  #ifndef READ_PNM  #ifndef READ_PNM
161  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
# Line 324  Line 330 
330                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {
331                          i++;                          i++;
332                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
333                  } else if (strcmp("-nframes", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-frames", argv[i]) == 0 && i < argc - 1) {
334                          i++;                          i++;
335                          ARG_MAXFRAMENR = atoi(argv[i]);                          ARG_MAXFRAMENR = atoi(argv[i]);
336                  } else if (strcmp("-save", argv[i]) == 0) {                  } else if (strcmp("-save", argv[i]) == 0) {
337                          ARG_SAVEMPEGSTREAM = 1;                          ARG_SAVEMPEGSTREAM = 1;
338                            ARG_SAVEINDIVIDUAL = 1;
339                  } else if (strcmp("-debug", argv[i]) == 0) {                  } else if (strcmp("-debug", argv[i]) == 0) {
340                          i++;                          i++;
341              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)) ;
342                  } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) {
343                            ARG_SAVEMPEGSTREAM = 1;
344                          i++;                          i++;
345                          ARG_OUTPUTFILE = argv[i];                          ARG_OUTPUTFILE = argv[i];
346                  } else if (strcmp("-vop_debug", argv[i]) == 0) {                  } else if (strcmp("-vop_debug", argv[i]) == 0) {
347                          ARG_VOPDEBUG = 1;                          ARG_VOPDEBUG = 1;
348                    }
349                    else if (strcmp("-grey", argv[i]) == 0) {
350                            ARG_GREYSCALE = 1;
351                    }
352                    else if (strcmp("-qpel", argv[i]) == 0) {
353                            ARG_QPEL = 1;
354                    } else if (strcmp("-gmc", argv[i]) == 0) {
355                            ARG_GMC = 1;
356                    } else if (strcmp("-interlaced", argv[i]) == 0) {
357                            ARG_INTERLACING = 1;
358                    } else if (strcmp("-closed_gop", argv[i]) == 0) {
359                            ARG_CLOSED_GOP = 1;
360                  } else if (strcmp("-help", argv[i])) {                  } else if (strcmp("-help", argv[i])) {
361                          usage();                          usage();
362                          return (0);                          return (0);
# Line 351  Line 371 
371   *                            Arguments checking   *                            Arguments checking
372   ****************************************************************************/   ****************************************************************************/
373    
374          if (XDIM <= 0 || XDIM >= 2048 || YDIM <= 0 || YDIM >= 2048) {          if (XDIM <= 0 || XDIM >= 4096 || YDIM <= 0 || YDIM >= 4096) {
375                  fprintf(stderr,                  fprintf(stderr,
376                                  "Trying to retreive width and height from PGM header\n");                                  "Trying to retreive width and height from PGM header\n");
377                  ARG_INPUTTYPE = 1;              /* pgm */                  ARG_INPUTTYPE = 1;              /* pgm */
# Line 535  Line 555 
555   ****************************************************************************/   ****************************************************************************/
556    
557                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {                  if (m4v_size > 0 && ARG_SAVEMPEGSTREAM) {
558    
559                          /* Save single files */                          /* Save single files */
560                          if (out_file == NULL) {                          if (ARG_SAVEINDIVIDUAL) {
561                                    FILE *out;
562                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
563                                  out_file = fopen(filename, "wb");                                  out = fopen(filename, "w+b");
564                                  fwrite(mp4_buffer, m4v_size, 1, out_file);                                  fwrite(mp4_buffer, m4v_size, 1, out);
565                                  fclose(out_file);                                  fclose(out);
                                 out_file = NULL;  
566                                  output_num++;                                  output_num++;
567                          } else {                          }
568    
569                                  /* Write mp4 data */                          /* Save ES stream */
570                            if (ARG_OUTPUTFILE && out_file)
571                                  fwrite(mp4_buffer, 1, m4v_size, out_file);                                  fwrite(mp4_buffer, 1, m4v_size, out_file);
   
                         }  
572                  }                  }
573    
574                  input_num++;                  input_num++;
# Line 657  Line 677 
677          fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");          fprintf(stderr, " -type    integer: input data type (yuv=0, pgm=1)\n");
678          fprintf(stderr, " -w       integer: frame width ([1.2048])\n");          fprintf(stderr, " -w       integer: frame width ([1.2048])\n");
679          fprintf(stderr, " -h       integer: frame height ([1.2048])\n");          fprintf(stderr, " -h       integer: frame height ([1.2048])\n");
680          fprintf(stderr, " -nframes integer: number of frames to encode\n");          fprintf(stderr, " -frames integer: number of frames to encode\n");
681          fprintf(stderr, "\n");          fprintf(stderr, "\n");
682          fprintf(stderr, "Output options:\n");          fprintf(stderr, "Output options:\n");
683          fprintf(stderr, " -dump    : save decoder output\n");          fprintf(stderr, " -dump    : save decoder output\n");
684          fprintf(stderr, " -save    : save mpeg4 raw stream\n");          fprintf(stderr, " -save    : save an Elementary Stream file per frame\n");
685          fprintf(stderr, " -o string: output filename\n");          fprintf(stderr, " -o string: save an Elementary Stream for the complete sequence\n");
686          fprintf(stderr, "\n");          fprintf(stderr, "\n");
687          fprintf(stderr, "BFrames options:\n");          fprintf(stderr, "BFrames options:\n");
688          fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");          fprintf(stderr, " -max_bframes   integer: max bframes (default=0)\n");
# Line 682  Line 702 
702          fprintf(stderr, "Other options\n");          fprintf(stderr, "Other options\n");
703          fprintf(stderr, " -asm            : use assembly optmized code\n");          fprintf(stderr, " -asm            : use assembly optmized code\n");
704          fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1);          fprintf(stderr, " -quality integer: quality ([0..%d])\n", ME_ELEMENTS - 1);
705            fprintf(stderr, " -qpel           : use quarter pixel ME\n");
706            fprintf(stderr, " -gmc            : use global motion compensation\n");
707            fprintf(stderr, " -interlaced     : use interlaced encoding (this is NOT a deinterlacer!)\n");
708          fprintf(stderr, " -packed         : packed mode\n");          fprintf(stderr, " -packed         : packed mode\n");
709            fprintf(stderr, " -closed_gop     : closed GOP mode\n");
710            fprintf(stderr, " -grey           : grey scale coding (chroma is discarded)\n");
711          fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");          fprintf(stderr, " -lumimasking    : use lumimasking algorithm\n");
712          fprintf(stderr, " -stats          : print stats about encoded frames\n");          fprintf(stderr, " -stats          : print stats about encoded frames\n");
713          fprintf(stderr, " -debug          : activates xvidcore internal debugging output\n");          fprintf(stderr, " -debug          : activates xvidcore internal debugging output\n");
# Line 714  Line 739 
739                  return (1);                  return (1);
740    
741          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
742          if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) {          if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) {
743                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
744                  return (2);                  return (2);
745          }          }
# Line 910  Line 935 
935          /* Width and Height of input frames */          /* Width and Height of input frames */
936          xvid_enc_create.width = XDIM;          xvid_enc_create.width = XDIM;
937          xvid_enc_create.height = YDIM;          xvid_enc_create.height = YDIM;
938            xvid_enc_create.profile = XVID_PROFILE_AS_L4;
939    
940          /* init plugins  */          /* init plugins  */
941      xvid_enc_create.zones = ZONES;      xvid_enc_create.zones = ZONES;
# Line 934  Line 960 
960                  rc2pass2.filename = ARG_PASS2;                  rc2pass2.filename = ARG_PASS2;
961                  rc2pass2.bitrate = ARG_BITRATE;                  rc2pass2.bitrate = ARG_BITRATE;
962    
963    /*              An example of activating VBV could look like this
964                    rc2pass2.vbv_size     =  3145728;
965                    rc2pass2.vbv_initial  =  2359296;
966                    rc2pass2.vbv_maxrate  =  4000000;
967                    rc2pass2.vbv_peakrate = 10000000;
968    */
969    
970                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
971                  plugins[xvid_enc_create.num_plugins].param = &rc2pass2;                  plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
972                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
# Line 1002  Line 1035 
1035          if (ARG_PACKED)          if (ARG_PACKED)
1036                  xvid_enc_create.global |=XVID_GLOBAL_PACKED;                  xvid_enc_create.global |=XVID_GLOBAL_PACKED;
1037    
1038            if (ARG_CLOSED_GOP)
1039                    xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
1040    
1041          if (ARG_STATS)          if (ARG_STATS)
1042                  xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;                  xvid_enc_create.global |=XVID_GLOBAL_EXTRASTATS_ENABLE;
1043    
# Line 1065  Line 1101 
1101          }          }
1102    
1103          /* Set up core's general features */          /* Set up core's general features */
1104          xvid_enc_frame.vol_flags = XVID_VOL_GMC;          xvid_enc_frame.vol_flags = 0;
1105          if (ARG_STATS)          if (ARG_STATS)
1106                  xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS;                  xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS;
1107            if (ARG_QPEL)
1108                    xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL;
1109            if (ARG_GMC)
1110                    xvid_enc_frame.vol_flags |= XVID_VOL_GMC;
1111            if (ARG_INTERLACING)
1112                    xvid_enc_frame.vol_flags |= XVID_VOL_INTERLACING;
1113    
1114          /* Set up core's general features */          /* Set up core's general features */
1115          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
1116    
1117      if (ARG_VOPDEBUG) {      if (ARG_VOPDEBUG) {
1118          xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG;          xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG;
1119      }      }
1120    
1121        if (ARG_GREYSCALE) {
1122            xvid_enc_frame.vop_flags |= XVID_VOP_GREYSCALE;
1123        }
1124    
1125          /* Frame type -- let core decide for us */          /* Frame type -- let core decide for us */
1126          xvid_enc_frame.type = XVID_TYPE_AUTO;          xvid_enc_frame.type = XVID_TYPE_AUTO;
1127    
# Line 1084  Line 1131 
1131          /* Set up motion estimation flags */          /* Set up motion estimation flags */
1132          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];
1133    
1134            if (ARG_GMC)
1135                    xvid_enc_frame.motion |= XVID_ME_GME_REFINE;
1136    
1137            if (ARG_QPEL)
1138                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16;
1139            if (ARG_QPEL && (xvid_enc_frame.vop_flags & XVID_VOP_INTER4V))
1140                    xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8;
1141    
1142          /* We don't use special matrices */          /* We don't use special matrices */
1143          xvid_enc_frame.quant_intra_matrix = NULL;          xvid_enc_frame.quant_intra_matrix = NULL;
1144          xvid_enc_frame.quant_inter_matrix = NULL;          xvid_enc_frame.quant_inter_matrix = NULL;
1145    
1146          /* Encode the frame */          /* Encode the frame */
1147          ret =          ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
                 xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame,  
1148                                          &xvid_enc_stats);                                          &xvid_enc_stats);
1149    
1150          *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);          *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);

Legend:
Removed from v.1.11.2.31  
changed lines
  Added in v.1.17

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