[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.1.2.1, Sun Jan 12 17:21:43 2003 UTC revision 1.4, Sat Sep 28 16:01:15 2002 UTC
# Line 51  Line 51 
51   ****************************************************************************/   ****************************************************************************/
52    
53  static int const motion_presets[7] = {  static int const motion_presets[7] = {
54          0,                                                        /* Q 0 */          0,                                                        // Q 0
55          PMV_EARLYSTOP16,                                          /* Q 1 */          PMV_EARLYSTOP16,                                          // Q 1
56          PMV_EARLYSTOP16,                                          /* Q 2 */          PMV_EARLYSTOP16,                                          // Q 2
57          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    /* Q 3 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    // Q 3
58          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    /* Q 4 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16,                    // Q 4
59          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |  /* Q 5 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 |  // Q 5
60          PMV_HALFPELREFINE8,          PMV_HALFPELREFINE8,
61          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | /* Q 6 */          PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | // Q 6
62          PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8          PMV_USESQUARES16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8
63  };  };
64    
65  static int const general_presets[7] = {  static int const general_presets[7] = {
66          XVID_H263QUANT,                               /* Q 0 */          XVID_H263QUANT,                               // Q 0
67          XVID_MPEGQUANT,                               /* Q 1 */          XVID_MPEGQUANT,                               // Q 1
68          XVID_H263QUANT,                               /* Q 2 */          XVID_H263QUANT,                               // Q 2
69          XVID_H263QUANT | XVID_HALFPEL,                /* Q 3 */          XVID_H263QUANT | XVID_HALFPEL,                // Q 3
70          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 4 */          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 4
71          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, /* Q 5 */          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V, // Q 5
72          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V  /* Q 6 */          XVID_H263QUANT | XVID_HALFPEL | XVID_INTER4V  // Q 6
73  };  };
74    
75    
# Line 80  Line 80 
80  /* Maximum number of frames to encode */  /* Maximum number of frames to encode */
81  #define ABS_MAXFRAMENR 9999  #define ABS_MAXFRAMENR 9999
82    
 /* HINTMODEs */  
 #define HINT_MODE_NONE 0  
 #define HINT_MODE_GET  1  
 #define HINT_MODE_SET  2  
 #define HINT_FILE "hints.mv"  
   
83  static int   ARG_BITRATE = 900;  static int   ARG_BITRATE = 900;
84  static int   ARG_QUANTI = 0;  static int   ARG_QUANTI = 0;
85  static int   ARG_QUALITY = 6;  static int   ARG_QUALITY = 6;
# Line 98  Line 92 
92  static int   ARG_SAVEMPEGSTREAM = 0;  static int   ARG_SAVEMPEGSTREAM = 0;
93  static int   ARG_OUTPUTTYPE = 0;  static int   ARG_OUTPUTTYPE = 0;
94  static char *ARG_OUTPUTFILE = NULL;  static char *ARG_OUTPUTFILE = NULL;
 static int   ARG_HINTMODE = HINT_MODE_NONE;  
95  static int   XDIM = 0;  static int   XDIM = 0;
96  static int   YDIM = 0;  static int   YDIM = 0;
97  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
# Line 143  Line 136 
136  static int enc_init(int use_assembler);  static int enc_init(int use_assembler);
137  static int enc_stop();  static int enc_stop();
138  static int enc_main(unsigned char* image, unsigned char* bitstream,  static int enc_main(unsigned char* image, unsigned char* bitstream,
139                                          unsigned char *hints_buffer,                                          int *streamlength, int* frametype);
                                         long *streamlength, long* frametype, long *hints_size);  
140    
141  /*****************************************************************************  /*****************************************************************************
142   *               Main function   *               Main function
# Line 156  Line 148 
148          unsigned char *mp4_buffer = NULL;          unsigned char *mp4_buffer = NULL;
149          unsigned char *in_buffer = NULL;          unsigned char *in_buffer = NULL;
150          unsigned char *out_buffer = NULL;          unsigned char *out_buffer = NULL;
         unsigned char *hints_buffer = NULL;  
151    
152          double enctime;          double enctime;
153          double totalenctime=0.;          double totalenctime=0.;
154    
155          long totalsize;          long totalsize;
         long hints_size;  
156          int status;          int status;
157          long frame_type;          int frame_type;
158          long bigendian;          int bigendian;
159    
160          long m4v_size;          int m4v_size;
161          int use_assembler=0;          int use_assembler=0;
162    
163          char filename[256];          char filename[256];
164    
165          FILE *in_file = stdin;          FILE *in_file = stdin;
166          FILE *out_file = NULL;          FILE *out_file = NULL;
         FILE *hints_file = NULL;  
167    
168          printf("xvid_encraw - raw mpeg4 bitstream encoder ");          printf("xvid_decraw - raw mpeg4 bitstream encoder ");
169          printf("written by Christoph Lampert 2002\n\n");          printf("written by Christoph Lampert 2002\n\n");
170    
171  /*****************************************************************************  /*****************************************************************************
# Line 232  Line 221 
221                          i++;                          i++;
222                          ARG_OUTPUTTYPE = atoi(argv[i]);                          ARG_OUTPUTTYPE = atoi(argv[i]);
223                  }                  }
                 else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) {  
                         i++;  
                         ARG_HINTMODE = atoi(argv[i]);  
                 }  
224                  else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) {
225                          i++;                          i++;
226                          ARG_OUTPUTFILE = argv[i];                          ARG_OUTPUTFILE = argv[i];
# Line 280  Line 265 
265                  return -1;                  return -1;
266          }          }
267    
         if ( ARG_HINTMODE != HINT_MODE_NONE &&  
                  ARG_HINTMODE != HINT_MODE_GET &&  
                  ARG_HINTMODE != HINT_MODE_SET)  
                 ARG_HINTMODE = HINT_MODE_NONE;  
   
         if( ARG_HINTMODE != HINT_MODE_NONE) {  
                 char *rights = "rb";  
   
                 /*  
                  * If we are getting hints from core, we will have to write them to  
                  * hint file  
                  */  
                 if(ARG_HINTMODE == HINT_MODE_GET)  
                         rights = "w+b";  
   
                 /* Open the hint file */  
                 hints_file = fopen(HINT_FILE, rights);  
                 if(hints_file == NULL) {  
                         fprintf(stderr, "Error opening input file %s\n", HINT_FILE);  
                         return -1;  
                 }  
   
                 /* Allocate hint memory space, we will be using rawhints */  
                 /* NB : Hope 1Mb is enough */  
                 if((hints_buffer = malloc(1024*1024)) == NULL) {  
                         fprintf(stderr, "Memory allocation error\n");  
                         return -1;  
                 }  
   
         }  
   
268          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if ( ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
269                  in_file = stdin;                  in_file = stdin;
270          }          }
# Line 400  Line 354 
354          do {          do {
355    
356                  if (ARG_INPUTTYPE)                  if (ARG_INPUTTYPE)
357                          status = read_pgmdata(in_file, in_buffer);      /* read PGM data (YUV-format) */                          status = read_pgmdata(in_file, in_buffer);      // read PGM data (YUV-format)
358                  else                  else
359                          status = read_yuvdata(in_file, in_buffer);      /* read raw data (YUV-format) */                          status = read_yuvdata(in_file, in_buffer);      // read raw data (YUV-format)
360    
361                  if (status)                  if (status)
362                  {                  {
# Line 411  Line 365 
365                  }                  }
366    
367  /*****************************************************************************  /*****************************************************************************
  *                       Read hints from file  
  ****************************************************************************/  
   
                 if(ARG_HINTMODE == HINT_MODE_SET) {  
                         fread(&hints_size, 1, sizeof(long), hints_file);  
                         hints_size = (!bigendian)?SWAP(hints_size):hints_size;  
                         fread(hints_buffer, 1, hints_size, hints_file);  
                 }  
   
 /*****************************************************************************  
368   *                       Encode and decode this frame   *                       Encode and decode this frame
369   ****************************************************************************/   ****************************************************************************/
370    
371                  enctime = msecond();                  enctime = msecond();
372                  status = enc_main(in_buffer, mp4_buffer, hints_buffer,                  status = enc_main(in_buffer, mp4_buffer, &m4v_size, &frame_type);
                                                   &m4v_size, &frame_type, &hints_size);  
373                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
374    
375                  totalenctime += enctime;                  totalenctime += enctime;
# Line 435  Line 378 
378                  printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6dbytes\n",                  printf("Frame %5d: intra %1d, enctime=%6.1f ms, size=%6dbytes\n",
379                             (int)filenr, (int)frame_type, (float)enctime, (int)m4v_size);                             (int)filenr, (int)frame_type, (float)enctime, (int)m4v_size);
380    
 /*****************************************************************************  
  *                       Save hints to file  
  ****************************************************************************/  
   
                 if(ARG_HINTMODE == HINT_MODE_GET) {  
                         hints_size = (!bigendian)?SWAP(hints_size):hints_size;  
                         fwrite(&hints_size, 1, sizeof(long), hints_file);  
                         hints_size = (!bigendian)?SWAP(hints_size):hints_size;  
                         fwrite(hints_buffer, 1, hints_size, hints_file);  
                 }  
   
 /*****************************************************************************  
  *                       Save stream to file  
  ****************************************************************************/  
   
381                  if (ARG_SAVEMPEGSTREAM)                  if (ARG_SAVEMPEGSTREAM)
382                  {                  {
383                          /* Save single files */                          /* Save single files */
# Line 507  Line 435 
435                          fprintf(stderr, "Encore RELEASE problem return value %d\n", status);                          fprintf(stderr, "Encore RELEASE problem return value %d\n", status);
436          }          }
437    
         if(in_file)  
438                  fclose(in_file);                  fclose(in_file);
439          if(out_file)          if(out_file)
440                  fclose(out_file);                  fclose(out_file);
         if(hints_file)  
                 fclose(hints_file);  
441    
442   free_all_memory:   free_all_memory:
443          free(out_buffer);          free(out_buffer);
444          free(mp4_buffer);          free(mp4_buffer);
445          free(in_buffer);          free(in_buffer);
         if(hints_buffer) free(hints_buffer);  
446    
447          return 0;          return 0;
448    
# Line 572  Line 496 
496          fprintf(stderr, "                    + stream.m4v with -mt 0\n");          fprintf(stderr, "                    + stream.m4v with -mt 0\n");
497          fprintf(stderr, "                    + stream.mp4u with -mt 1\n");          fprintf(stderr, "                    + stream.mp4u with -mt 1\n");
498          fprintf(stderr, " -mt integer    : output type (m4v=0, mp4u=1)\n");          fprintf(stderr, " -mt integer    : output type (m4v=0, mp4u=1)\n");
         fprintf(stderr, " -mv integer    : Use motion vector hints (no hints=0, get hints=1, set hints=2)\n");  
499          fprintf(stderr, " -help          : prints this help message\n");          fprintf(stderr, " -help          : prints this help message\n");
500          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");          fprintf(stderr, " -quant integer : fixed quantizer (disables -b setting)\n");
501          fprintf(stderr, " (* means default)\n");          fprintf(stderr, " (* means default)\n");
# Line 699  Line 622 
622          xparam.min_quantizer = ARG_MINQUANT;          xparam.min_quantizer = ARG_MINQUANT;
623          xparam.max_quantizer = ARG_MAXQUANT;          xparam.max_quantizer = ARG_MAXQUANT;
624          xparam.max_key_interval = (int)ARG_FRAMERATE*10;          xparam.max_key_interval = (int)ARG_FRAMERATE*10;
         xparam.bquant_ratio = 150;  
         xparam.bquant_offset = 100;  
         xparam.max_bframes = 0;  
         xparam.global = 0;  
625    
626          /* I use a small value here, since will not encode whole movies, but short clips */          /* I use a small value here, since will not encode whole movies, but short clips */
627    
# Line 722  Line 641 
641  }  }
642    
643  static int enc_main(unsigned char* image, unsigned char* bitstream,  static int enc_main(unsigned char* image, unsigned char* bitstream,
644                                          unsigned char* hints_buffer,                                          int *streamlength, int* frametype)
                                         long *streamlength, long *frametype, long *hints_size)  
645  {  {
646          int xerr;          int xerr;
647    
# Line 731  Line 649 
649          XVID_ENC_STATS xstats;          XVID_ENC_STATS xstats;
650    
651          xframe.bitstream = bitstream;          xframe.bitstream = bitstream;
652          xframe.length = -1;     /* this is written by the routine */          xframe.length = -1;     // this is written by the routine
653    
654          xframe.image = image;          xframe.image = image;
655          xframe.colorspace = XVID_CSP_YV12;      /* defined in <xvid.h> */          xframe.colorspace = XVID_CSP_YV12;      // defined in <xvid.h>
656    
657          xframe.intra = -1; /* let the codec decide between I-frame (1) and P-frame (0) */          xframe.intra = -1; // let the codec decide between I-frame (1) and P-frame (0)
658    
659          xframe.quant = ARG_QUANTI;      /* is quant != 0, use a fixed quant (and ignore bitrate) */          xframe.quant = ARG_QUANTI;      // is quant != 0, use a fixed quant (and ignore bitrate)
         xframe.bquant = 0;  
660    
661          xframe.motion = motion_presets[ARG_QUALITY];          xframe.motion = motion_presets[ARG_QUALITY];
662          xframe.general = general_presets[ARG_QUALITY];          xframe.general = general_presets[ARG_QUALITY];
663          xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;          xframe.quant_intra_matrix = xframe.quant_inter_matrix = NULL;
         xframe.stride = XDIM;  
   
         xframe.hint.hintstream = hints_buffer;  
   
         if(ARG_HINTMODE == HINT_MODE_SET) {  
                 xframe.hint.hintlength = *hints_size;  
                 xframe.hint.rawhints = 0;  
                 xframe.general |= XVID_HINTEDME_SET;  
         }  
   
         if(ARG_HINTMODE == HINT_MODE_GET) {  
                 xframe.hint.rawhints = 0;  
                 xframe.general |= XVID_HINTEDME_GET;  
         }  
664    
665          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);          xerr = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xframe, &xstats);
666    
         if(ARG_HINTMODE == HINT_MODE_GET)  
                 *hints_size = xframe.hint.hintlength;  
   
667          /*          /*
668           * This is statictical data, e.g. for 2-pass. If you are not           * This is statictical data, e.g. for 2-pass. If you are not
669           * interested in any of this, you can use NULL instead of &xstats           * interested in any of this, you can use NULL instead of &xstats

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.4

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