[svn] / trunk / xvidcore / examples / odivx_enc_dec.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/examples/odivx_enc_dec.c

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

revision 684, Wed Nov 27 21:09:10 2002 UTC revision 860, Sun Feb 16 05:11:39 2003 UTC
# Line 47  Line 47 
47  #define ARG_BITRATE 900  #define ARG_BITRATE 900
48    
49  int QUALITY =5;  int QUALITY =5;
50  int QUANTI = 0;         /* used for fixed-quantizer encoding  */  int QUANTI = 0;         // used for fixed-quantizer encoding
51    
52  int XDIM=0;  int XDIM=0;
53  int YDIM=0;     /* will be set when reading first image */  int YDIM=0;     // will be set when reading first image
54  int filenr = 0;  int filenr = 0;
55    
56  int save_m4v_flag = 0;          /* save MPEG4-bytestream? */  int save_m4v_flag = 0;          // save MPEG4-bytestream?
57  int save_dec_flag = 0;          /* save decompressed bytestream? */  int save_dec_flag = 0;          // save decompressed bytestream?
58  char filepath[256] = ".";       /* path where to save  */  char filepath[256] = ".";       // path where to save
59    
60  void *enchandle = NULL;         /* enchandle is a void*, written by encore */  void *enchandle = NULL;         // enchandle is a void*, written by encore
61  const long dechandle = 0x0815;  /* dechandle is a unique constant!!!  */  const long dechandle = 0x0815;  // dechandle is a unique constant!!!
62    
63  /*********************************************************************/  /*********************************************************************/
64  /*      Routines for file input/output, nothing specific to XviD     */  /*      Routines for file input/output, nothing specific to XviD     */
# Line 102  Line 102 
102                  fread(buff1_ptr3,XDIM/2,1,stdin);                  fread(buff1_ptr3,XDIM/2,1,stdin);
103                  buff1_ptr3 += XDIM/2;                  buff1_ptr3 += XDIM/2;
104          }          }
105          fread(&dummy,1,1,handle);                               /* should be EOF */          fread(&dummy,1,1,handle);                               // should be EOF
106          return 0;          return 0;
107  }  }
108    
# Line 119  Line 119 
119    
120          enc_param.x_dim = XDIM;          enc_param.x_dim = XDIM;
121          enc_param.y_dim = YDIM;          enc_param.y_dim = YDIM;
122          enc_param.framerate = ARG_FRAMERATE;            /* a float */          enc_param.framerate = ARG_FRAMERATE;            // a float
123          enc_param.bitrate = ARG_BITRATE*1000;          enc_param.bitrate = ARG_BITRATE*1000;
124    
125          enc_param.rc_period = 2000;          enc_param.rc_period = 2000;
# Line 131  Line 131 
131    
132          enc_param.quality = QUALITY;          enc_param.quality = QUALITY;
133    
134          enc_param.use_bidirect = 0;     /* use bidirectional coding */          enc_param.use_bidirect = 0;     // use bidirectional coding
135          enc_param.deinterlace = 0;      /* fast deinterlace */          enc_param.deinterlace = 0;      // fast deinterlace
136          enc_param.obmc = 0;             /* flag to enable overlapped block motion compensation mode */          enc_param.obmc = 0;             // flag to enable overlapped block motion compensation mode
137    
138          enc_param.max_key_interval = (int)ARG_FRAMERATE*10;          enc_param.max_key_interval = (int)ARG_FRAMERATE*10;
139          enc_param.handle = NULL;        /*will be filled by encore */          enc_param.handle = NULL;        //will be filled by encore
140    
141          status = encore(enchandle, ENC_OPT_INIT, &enc_param, NULL);          status = encore(enchandle, ENC_OPT_INIT, &enc_param, NULL);
142          enchandle = enc_param.handle;          enchandle = enc_param.handle;
143    
144  /*      if (status)     */  //      if (status)
145                  printf("Encore INIT return %d, handle=%lx\n", status, enchandle);                  printf("Encore INIT return %d, handle=%lx\n", status, enchandle);
146    
147          return status;          return status;
# Line 151  Line 151 
151  {       int status;  {       int status;
152    
153          status = encore(enchandle, ENC_OPT_RELEASE, NULL, NULL);          status = encore(enchandle, ENC_OPT_RELEASE, NULL, NULL);
154  /*      if (status)  */  //      if (status)
155                  printf("Encore RELEASE return %d\n", status);                  printf("Encore RELEASE return %d\n", status);
156    
157          return status;          return status;
# Line 165  Line 165 
165    
166          enc_frame.image = (void *) image;          enc_frame.image = (void *) image;
167          enc_frame.bitstream = (void *) bitstream;          enc_frame.bitstream = (void *) bitstream;
168          enc_frame.length = 0;                   /* filled by encore */          enc_frame.length = 0;                   // filled by encore
169          enc_frame.colorspace = ENC_CSP_YV12;    /* input is YUV */          enc_frame.colorspace = ENC_CSP_YV12;    // input is YUV
170          enc_frame.mvs = NULL;           /* unsupported */          enc_frame.mvs = NULL;           // unsupported
171    
172          if (QUANTI==0)          if (QUANTI==0)
173          {          {
# Line 175  Line 175 
175          }          }
176          else          else
177          {       enc_frame.quant = QUANTI;          {       enc_frame.quant = QUANTI;
178                  enc_frame.intra = -1;           /* let encoder decide if frame is INTER/INTRA */                  enc_frame.intra = -1;           // let encoder decide if frame is INTER/INTRA
179                  status = encore(enchandle, ENC_OPT_ENCODE_VBR, &enc_frame, &enc_result);                  status = encore(enchandle, ENC_OPT_ENCODE_VBR, &enc_frame, &enc_result);
180          }          }
181    
# Line 198  Line 198 
198          int status;          int status;
199    
200          DEC_PARAM dec_param;          DEC_PARAM dec_param;
201            DEC_SET dec_set;
202    
203          dec_param.x_dim = XDIM;          dec_param.x_dim = XDIM;
204          dec_param.y_dim = YDIM;          dec_param.y_dim = YDIM;
205          dec_param.output_format = DEC_RGB24;    /*   output color format, , see <decore.h> */          dec_param.output_format = DEC_RGB24;    //   output color format, , see <decore.h>
206    
207          dec_param.time_incr = 20;          dec_param.time_incr = 20;
208    
209          status = decore(dechandle, DEC_OPT_INIT, &dec_param, NULL);          status = decore(dechandle, DEC_OPT_INIT, &dec_param, NULL);
210  /*      if (status)  */  //      if (status)
211                  printf("Decore INIT return %d\n", status);                  printf("Decore INIT return %d\n", status);
212    
213  /* We don't do any postprocessing here...  */  // We don't do any postprocessing here...
214    
215  /*      dec_set.postproc_level = 0;  /*      dec_set.postproc_level = 0;
216          status = decore(dechandle, DEC_OPT_SETPP, &dec_set, NULL);          status = decore(dechandle, DEC_OPT_SETPP, &dec_set, NULL);
# Line 230  Line 231 
231          dec_frame.length = m4v_size;          dec_frame.length = m4v_size;
232          dec_frame.bitstream = m4v_buffer;          dec_frame.bitstream = m4v_buffer;
233          dec_frame.bmp = rgb_buffer;          dec_frame.bmp = rgb_buffer;
234          dec_frame.render_flag = 1;              /* 0 means: skip this frame */          dec_frame.render_flag = 1;              // 0 means: skip this frame
235          dec_frame.stride = XDIM;          dec_frame.stride = XDIM;
236    
237          status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info);          status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info);
# Line 244  Line 245 
245  {  {
246          int status;          int status;
247          status = decore(dechandle, DEC_OPT_RELEASE, NULL, NULL);          status = decore(dechandle, DEC_OPT_RELEASE, NULL, NULL);
248  /*      if (status)  */  //      if (status)
249                  printf("Decore RELEASE return %d\n", status);                  printf("Decore RELEASE return %d\n", status);
250          return status;          return status;
251  }  }
# Line 261  Line 262 
262    unsigned char *rgb_buffer = NULL;    unsigned char *rgb_buffer = NULL;
263    
264    int status;    int status;
265      int frame_size;
266    int m4v_size;    int m4v_size;
267    
268    char filename[256];    char filename[256];
# Line 277  Line 279 
279  /* now we know the sizes, so allocate memory */  /* now we know the sizes, so allocate memory */
280    yuv_buffer = (unsigned char *) malloc(XDIM*YDIM);    yuv_buffer = (unsigned char *) malloc(XDIM*YDIM);
281    if (!yuv_buffer)    if (!yuv_buffer)
282      goto free_all_memory;       /* goto is one of the most underestimated instructions in C !!! */      goto free_all_memory;       // goto is one of the most underestimated instructions in C !!!
283    divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2);  /* this should really be enough! */    divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2);  // this should really be enough!
284    if (!divx_buffer)    if (!divx_buffer)
285      goto free_all_memory;       /* actually, every program should contain a goto  */      goto free_all_memory;       // actually, every program should contain a goto
286    
287    YDIM = YDIM*2/3; /* PGM is YUV 4:2:0 format, so height is *3/2 too much */    YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so height is *3/2 too much
288    
289    rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4);    rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4);
290    if (!rgb_buffer)    if (!rgb_buffer)
291      goto free_all_memory;       /* the more, the better! */      goto free_all_memory;       // the more, the better!
292    
293  /*********************************************************************/  /*********************************************************************/
294  /*                         DIVX PART  Start                          */  /*                         DIVX PART  Start                          */
295  /*********************************************************************/  /*********************************************************************/
296    
297    status = enc_init();    status = enc_init();
298  /*       if (status)     */  //       if (status)
299            printf("Encore INIT return %d, handle=%lx\n", status, enchandle);            printf("Encore INIT return %d, handle=%lx\n", status, enchandle);
300    
301    status = dec_init();    status = dec_init();
302  /*      if (status)  */  //      if (status)
303            printf("Decore INIT return %d\n", status);            printf("Decore INIT return %d\n", status);
304    
305    
# Line 307  Line 309 
309    
310    do    do
311      {      {
312        status = read_pgmdata(stdin, yuv_buffer); /* read PGM data (YUV-format) */        status = read_pgmdata(stdin, yuv_buffer); // read PGM data (YUV-format)
313        if (status)        if (status)
314          {          {
315            fprintf(stderr, "PGM-Data-Error: %d\n", status);      /* this should not happen */            fprintf(stderr, "PGM-Data-Error: %d\n", status);      /* this should not happen */
# Line 341  Line 343 
343                  filehandle=fopen(filename,"wb");                  filehandle=fopen(filename,"wb");
344                  if (filehandle)                  if (filehandle)
345                  {                  {
346                          fprintf(filehandle,"P6\n");             /* rgb24 in PPM format */                          fprintf(filehandle,"P6\n");             // rgb24 in PPM format
347                          fprintf(filehandle,"%d %d 255\n",XDIM,YDIM);                          fprintf(filehandle,"%d %d 255\n",XDIM,YDIM);
348                          fwrite(rgb_buffer,XDIM,YDIM*3,filehandle);                          fwrite(rgb_buffer,XDIM,YDIM*3,filehandle);
349                          fclose(filehandle);                          fclose(filehandle);
# Line 349  Line 351 
351          }          }
352    
353        filenr++;        filenr++;
354        status = read_pgmheader(stdin);           /* if it was the last PGM, stop after it */        status = read_pgmheader(stdin);           // if it was the last PGM, stop after it
355        if (status)        if (status)
356          {          {
357            fprintf(stderr, "PGM-Header-Error: %d\n", status); /* normally, just end of file */            fprintf(stderr, "PGM-Header-Error: %d\n", status); /* normally, just end of file */
# Line 366  Line 368 
368  /* Stop XviD */  /* Stop XviD */
369    
370          dec_stop();          dec_stop();
371  /*       if (status)     */  //       if (status)
372          printf("Encore RELEASE return %d\n", status);          printf("Encore RELEASE return %d\n", status);
373    
374          enc_stop();          enc_stop();
375  /*       if (status)     */  //       if (status)
376          printf("Decore RELEASE return %d\n", status);          printf("Decore RELEASE return %d\n", status);
377    
378  free_all_memory:  free_all_memory:

Legend:
Removed from v.684  
changed lines
  Added in v.860

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