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

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

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