[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 3, Fri Mar 8 02:46:11 2002 UTC revision 684, Wed Nov 27 21:09:10 2002 UTC
# Line 41  Line 41 
41  #include <stdio.h>  #include <stdio.h>
42  #include <malloc.h>  #include <malloc.h>
43    
44  #include "encore2.h"  #include "divx4.h"
 #include "decore.h"             /* these come with XviD */  
45    
46  #define ARG_FRAMERATE 25  #define ARG_FRAMERATE 25
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 103  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 120  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 132  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 152  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 166  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 176  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 199  Line 198 
198          int status;          int status;
199    
200          DEC_PARAM dec_param;          DEC_PARAM dec_param;
         DEC_SET dec_set;  
201    
202          dec_param.x_dim = XDIM;          dec_param.x_dim = XDIM;
203          dec_param.y_dim = YDIM;          dec_param.y_dim = YDIM;
204          dec_param.output_format = DEC_RGB24;    //   output color format, , see <decore.h>          dec_param.output_format = DEC_RGB24;    /*   output color format, , see <decore.h> */
205    
206          dec_param.time_incr = 20;          dec_param.time_incr = 20;
207    
208          status = decore(dechandle, DEC_OPT_INIT, &dec_param, NULL);          status = decore(dechandle, DEC_OPT_INIT, &dec_param, NULL);
209  //      if (status)  /*      if (status)  */
210                  printf("Decore INIT return %d\n", status);                  printf("Decore INIT return %d\n", status);
211    
212  // We don't do any postprocessing here...  /* We don't do any postprocessing here...  */
213    
214  /*      dec_set.postproc_level = 0;  /*      dec_set.postproc_level = 0;
215          status = decore(dechandle, DEC_OPT_SETPP, &dec_set, NULL);          status = decore(dechandle, DEC_OPT_SETPP, &dec_set, NULL);
# Line 232  Line 230 
230          dec_frame.length = m4v_size;          dec_frame.length = m4v_size;
231          dec_frame.bitstream = m4v_buffer;          dec_frame.bitstream = m4v_buffer;
232          dec_frame.bmp = rgb_buffer;          dec_frame.bmp = rgb_buffer;
233          dec_frame.render_flag = 1;              // 0 means: skip this frame          dec_frame.render_flag = 1;              /* 0 means: skip this frame */
234          dec_frame.stride = XDIM;          dec_frame.stride = XDIM;
235    
236          status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info);          status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info);
# Line 246  Line 244 
244  {  {
245          int status;          int status;
246          status = decore(dechandle, DEC_OPT_RELEASE, NULL, NULL);          status = decore(dechandle, DEC_OPT_RELEASE, NULL, NULL);
247  //      if (status)  /*      if (status)  */
248                  printf("Decore RELEASE return %d\n", status);                  printf("Decore RELEASE return %d\n", status);
249          return status;          return status;
250  }  }
# Line 263  Line 261 
261    unsigned char *rgb_buffer = NULL;    unsigned char *rgb_buffer = NULL;
262    
263    int status;    int status;
   int frame_size;  
264    int m4v_size;    int m4v_size;
265    
266    char filename[256];    char filename[256];
# Line 280  Line 277 
277  /* now we know the sizes, so allocate memory */  /* now we know the sizes, so allocate memory */
278    yuv_buffer = (unsigned char *) malloc(XDIM*YDIM);    yuv_buffer = (unsigned char *) malloc(XDIM*YDIM);
279    if (!yuv_buffer)    if (!yuv_buffer)
280      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 !!! */
281    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! */
282    if (!divx_buffer)    if (!divx_buffer)
283      goto free_all_memory;       // actually, every program should contain a goto      goto free_all_memory;       /* actually, every program should contain a goto  */
284    
285    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 */
286    
287    rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4);    rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4);
288    if (!rgb_buffer)    if (!rgb_buffer)
289      goto free_all_memory;       // the more, the better!      goto free_all_memory;       /* the more, the better! */
290    
291  /*********************************************************************/  /*********************************************************************/
292  /*                         DIVX PART  Start                          */  /*                         DIVX PART  Start                          */
293  /*********************************************************************/  /*********************************************************************/
294    
295    status = enc_init();    status = enc_init();
296  //       if (status)  /*       if (status)     */
297            printf("Encore INIT return %d, handle=%lx\n", status, enchandle);            printf("Encore INIT return %d, handle=%lx\n", status, enchandle);
298    
299    status = dec_init();    status = dec_init();
300  //      if (status)  /*      if (status)  */
301            printf("Decore INIT return %d\n", status);            printf("Decore INIT return %d\n", status);
302    
303    
# Line 310  Line 307 
307    
308    do    do
309      {      {
310        status = read_pgmdata(stdin, yuv_buffer); // read PGM data (YUV-format)        status = read_pgmdata(stdin, yuv_buffer); /* read PGM data (YUV-format) */
311        if (status)        if (status)
312          {          {
313            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 344  Line 341 
341                  filehandle=fopen(filename,"wb");                  filehandle=fopen(filename,"wb");
342                  if (filehandle)                  if (filehandle)
343                  {                  {
344                          fprintf(filehandle,"P6\n");             // rgb24 in PPM format                          fprintf(filehandle,"P6\n");             /* rgb24 in PPM format */
345                          fprintf(filehandle,"%d %d 255\n",XDIM,YDIM);                          fprintf(filehandle,"%d %d 255\n",XDIM,YDIM);
346                          fwrite(rgb_buffer,XDIM,YDIM*3,filehandle);                          fwrite(rgb_buffer,XDIM,YDIM*3,filehandle);
347                          fclose(filehandle);                          fclose(filehandle);
# Line 352  Line 349 
349          }          }
350    
351        filenr++;        filenr++;
352        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 */
353        if (status)        if (status)
354          {          {
355            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 369  Line 366 
366  /* Stop XviD */  /* Stop XviD */
367    
368          dec_stop();          dec_stop();
369  //       if (status)  /*       if (status)     */
370          printf("Encore RELEASE return %d\n", status);          printf("Encore RELEASE return %d\n", status);
371    
372          enc_stop();          enc_stop();
373  //       if (status)  /*       if (status)     */
374          printf("Decore RELEASE return %d\n", status);          printf("Decore RELEASE return %d\n", status);
375    
376  free_all_memory:  free_all_memory:

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

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