[svn] / branches / dev-api-4 / xvidcore / examples / xvid_encraw.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/examples/xvid_encraw.c

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

revision 919, Thu Mar 13 11:07:20 2003 UTC revision 923, Sat Mar 15 16:41:32 2003 UTC
# Line 19  Line 19 
19   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: xvid_encraw.c,v 1.11.2.5 2003-03-13 11:07:20 suxen_drol Exp $   * $Id: xvid_encraw.c,v 1.11.2.7 2003-03-15 16:41:32 suxen_drol Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 46  Line 46 
46    
47  #include "xvid.h"  #include "xvid.h"
48    
49    
50  /*****************************************************************************  /*****************************************************************************
51   *                            Quality presets   *                            Quality presets
52   ****************************************************************************/   ****************************************************************************/
# Line 85  Line 86 
86  #define ABS_MAXFRAMENR 9999  #define ABS_MAXFRAMENR 9999
87    
88  static int   ARG_STATS = 0;  static int   ARG_STATS = 0;
89    static int   ARG_DUMP = 0;
90  static int   ARG_BITRATE = 900;  static int   ARG_BITRATE = 900;
91  static int   ARG_QUANTI = 0;  static int   ARG_QUANTI = 0;
92  static int   ARG_QUALITY = 5;  static int   ARG_QUALITY = 5;
# Line 114  Line 116 
116   *                     Nasty global vars ;-)   *                     Nasty global vars ;-)
117   ***************************************************************************/   ***************************************************************************/
118    
119  static int i,filenr = 0;  static int i;
120    
121  /* the path where to save output */  /* the path where to save output */
122  static char filepath[256] = "./";  static char filepath[256] = "./";
# Line 163  Line 165 
165          double totalenctime=0.;          double totalenctime=0.;
166    
167          int totalsize;          int totalsize;
168          int status;          int result;
169          int m4v_size;          int m4v_size;
170      int key;      int key;
171          int stats_type;          int stats_type;
# Line 171  Line 173 
173      int stats_length;      int stats_length;
174          int use_assembler=0;          int use_assembler=0;
175    
176        int input_num;
177        int output_num;
178    
179          char filename[256];          char filename[256];
180    
181          FILE *in_file = stdin;          FILE *in_file = stdin;
# Line 230  Line 235 
235                  else if (strcmp("-s", argv[i]) == 0) {                  else if (strcmp("-s", argv[i]) == 0) {
236                          ARG_STATS = 1;                          ARG_STATS = 1;
237                  }                  }
238                    else if (strcmp("-dump", argv[i]) == 0) {
239                            ARG_DUMP = 1;
240                    }
241                  else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {
242                          i++;                          i++;
243                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
# Line 323  Line 331 
331   ****************************************************************************/   ****************************************************************************/
332    
333    
334          status = enc_init(use_assembler);          result = enc_init(use_assembler);
335          if (status)          if (result)
336          {          {
337                  fprintf(stderr, "Encore INIT problem, return value %d\n", status);                  fprintf(stderr, "Encore INIT problem, return value %d\n", result);
338                  goto release_all;                  goto release_all;
339          }          }
340    
# Line 352  Line 360 
360    
361          totalsize = 0;          totalsize = 0;
362    
363        result = 0;
364    
365        input_num = 0;  /* input frame counter */
366        output_num = 0; /* output frame counter */
367    
368          do {          do {
369    
370                  char *type;                  char *type;
371                  int stats[3];                  int stats[3];
372    
373            if (input_num >= ARG_MAXFRAMENR)
374            {
375                result = 1;
376            }
377    
378            if (!result)
379            {
380                  if(ARG_INPUTTYPE) {                  if(ARG_INPUTTYPE) {
381                          /* read PGM data (YUV-format) */                          /* read PGM data (YUV-format) */
382                          status = read_pgmdata(in_file, in_buffer);                              result = read_pgmdata(in_file, in_buffer);
383                  } else {                  } else {
384                          /* read raw data (YUV-format) */                          /* read raw data (YUV-format) */
385                          status = read_yuvdata(in_file, in_buffer);                              result = read_yuvdata(in_file, in_buffer);
386                  }                  }
   
                 if(status) {  
                         /* Couldn't read image, most likely end-of-file */  
                         continue;  
387                  }                  }
388    
389  /*****************************************************************************  /*****************************************************************************
# Line 375  Line 391 
391   ****************************************************************************/   ****************************************************************************/
392    
393                  enctime = msecond();                  enctime = msecond();
394                  m4v_size = enc_main(in_buffer, mp4_buffer, &key, &stats_type, &stats_quant, &stats_length, stats);          m4v_size = enc_main(!result?in_buffer:0, mp4_buffer, &key, &stats_type, &stats_quant, &stats_length, stats);
395                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
396    
397                  /* Write the Frame statistics */                  /* Write the Frame statistics */
398    
399                  printf("Frame %5d: key=%i, time(ms)=%6.1f, length=%7d",                  printf("%5d: key=%i, time(ms)=%6.1f, length=%7d",
400                             (int)filenr,              !result?input_num:-1,
401                             key,                             key,
402                             (float)enctime,                             (float)enctime,
403                             (int)m4v_size);                             (int)m4v_size);
# Line 414  Line 430 
430                                     (stats[1] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[1]/((float)(XDIM)*(YDIM)/4)),                                     (stats[1] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[1]/((float)(XDIM)*(YDIM)/4)),
431                                     (stats[2] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[2]/((float)(XDIM)*(YDIM)/4)));                                     (stats[2] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[2]/((float)(XDIM)*(YDIM)/4)));
432              }              }
433    
434                  }                  }
435    
436                  printf("\n");                  printf("\n");
437    
438            if (m4v_size < 0) {
439                break;
440            }
441    
442                  /* Update encoding time stats */                  /* Update encoding time stats */
443                  totalenctime += enctime;                  totalenctime += enctime;
444                  totalsize += m4v_size;                  totalsize += m4v_size;
445    
         /* Not coded frames return 0 */  
                 if(m4v_size == 0) goto next_frame;  
   
   
446  /*****************************************************************************  /*****************************************************************************
447   *                       Save stream to file   *                       Save stream to file
448   ****************************************************************************/   ****************************************************************************/
449    
450                  if (ARG_SAVEMPEGSTREAM)                  if (m4v_size>0 && ARG_SAVEMPEGSTREAM)
451                  {                  {
452                          /* Save single files */                          /* Save single files */
453                          if (out_file == NULL) {                          if (out_file == NULL) {
454                                  sprintf(filename, "%sframe%05d.m4v", filepath, filenr);                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
455                                  out_file = fopen(filename, "wb");                                  out_file = fopen(filename, "wb");
456                                  fwrite(mp4_buffer, m4v_size, 1, out_file);                                  fwrite(mp4_buffer, m4v_size, 1, out_file);
457                                  fclose(out_file);                                  fclose(out_file);
458                                  out_file = NULL;                                  out_file = NULL;
459                    output_num++;
460                          }                          }
461                          else {                          else {
462    
# Line 449  Line 466 
466                          }                          }
467                  }                  }
468    
469                  filenr++;                  input_num++;
470    
         next_frame:  
471                  /* Read the header if it's pgm stream */                  /* Read the header if it's pgm stream */
472                  if (ARG_INPUTTYPE)          if (!result && ARG_INPUTTYPE)
473                          status = read_pgmheader(in_file);                          result = read_pgmheader(in_file);
474    
475          } while ( (!status) && (filenr<ARG_MAXFRAMENR) );          } while (1);
476    
477    
478    
# Line 464  Line 480 
480   *         Calculate totals and averages for output, print results   *         Calculate totals and averages for output, print results
481   ****************************************************************************/   ****************************************************************************/
482    
483          totalsize    /= filenr;      if (input_num > 0) {
484          totalenctime /= filenr;              totalsize    /= input_num;
485                totalenctime /= input_num;
486        }else{
487            totalsize = -1;
488            totalenctime = -1;
489        }
490    
491          printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n",          printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n",
492                     totalenctime, 1000/totalenctime, (int)totalsize);                     totalenctime, 1000/totalenctime, (int)totalsize);
# Line 479  Line 500 
500    
501          if (enc_handle)          if (enc_handle)
502          {          {
503                  status = enc_stop();                  result = enc_stop();
504                  if (status)                  if (result)
505                          fprintf(stderr, "Encore RELEASE problem return value %d\n", status);                          fprintf(stderr, "Encore RELEASE problem return value %d\n", result);
506          }          }
507    
508          if(in_file)          if(in_file)
# Line 543  Line 564 
564          fprintf(stderr, " -t integer     : input data type (yuv=0, pgm=1)\n");          fprintf(stderr, " -t integer     : input data type (yuv=0, pgm=1)\n");
565          fprintf(stderr, " -n integer     : number of frames to encode\n");          fprintf(stderr, " -n integer     : number of frames to encode\n");
566          fprintf(stderr, " -q integer     : quality ([0..5])\n");          fprintf(stderr, " -q integer     : quality ([0..5])\n");
567          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -dump          : save decoder output\n");
568          fprintf(stderr, " -m             : save mpeg4 raw stream\n");          fprintf(stderr, " -m             : save mpeg4 raw stream\n");
569          fprintf(stderr, " -o string      : output container filename (only usefull when -m 1 is used) :\n");          fprintf(stderr, " -o string      : output container filename (only usefull when -m 1 is used) :\n");
570          fprintf(stderr, "                  When this option is not used : one file per encoded frame\n");          fprintf(stderr, "                  When this option is not used : one file per encoded frame\n");
# Line 662  Line 683 
683  {  {
684          int xerr;          int xerr;
685    
686      /* xvid_enc_plugin_t plugins[1]; */      xvid_enc_plugin_t plugins[1];
687    
688          xvid_gbl_init_t   xvid_gbl_init;          xvid_gbl_init_t   xvid_gbl_init;
689          xvid_enc_create_t xvid_enc_create;          xvid_enc_create_t xvid_enc_create;
# Line 704  Line 725 
725          xvid_enc_create.width = XDIM;          xvid_enc_create.width = XDIM;
726          xvid_enc_create.height = YDIM;          xvid_enc_create.height = YDIM;
727    
728      /* init plugins      /* init plugins  */
729      plugins[0].func =  rawenc_debug;  
730      plugins[0].param = NULL;      xvid_enc_create.plugins = plugins;
731      xvid_enc_create.num_plugins = 1;      xvid_enc_create.num_plugins = 0;
732      xvid_enc_create.plugins = plugins; */      if (ARG_DUMP) {
733            plugins[xvid_enc_create.num_plugins].func = xvid_plugin_dump;
734            plugins[xvid_enc_create.num_plugins].param = NULL;
735            xvid_enc_create.num_plugins++;
736        }
737    
738          /* No fancy thread tests */          /* No fancy thread tests */
739          xvid_enc_create.num_threads = 0;          xvid_enc_create.num_threads = 0;
# Line 735  Line 760 
760    
761          /* Global encoder options */          /* Global encoder options */
762          xvid_enc_create.global = 0;          xvid_enc_create.global = 0;
     if (ARG_STATS) xvid_enc_create.global |= XVID_EXTRASTATS_ENABLE;  
763      if (ARG_PACKED) xvid_enc_create.global |= XVID_PACKED;      if (ARG_PACKED) xvid_enc_create.global |= XVID_PACKED;
764        if (ARG_STATS) xvid_enc_create.global |= XVID_EXTRASTATS_ENABLE;
765    
766          /* 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 */
767          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
# Line 782  Line 807 
807          xvid_enc_frame.length = -1;          xvid_enc_frame.length = -1;
808    
809          /* Initialize input image fields */          /* Initialize input image fields */
810        if (image) {
811          xvid_enc_frame.input.plane[0]  = image;          xvid_enc_frame.input.plane[0]  = image;
812          xvid_enc_frame.input.csp       = XVID_CSP_I420;          xvid_enc_frame.input.csp       = XVID_CSP_I420;
813          xvid_enc_frame.input.stride[0] = XDIM;          xvid_enc_frame.input.stride[0] = XDIM;
814        }else{
815            xvid_enc_frame.input.csp       = XVID_CSP_NULL;
816        }
817    
818          /* Set up core's general features */          /* Set up core's general features */
819          xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY];          xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY];
820        if (ARG_STATS) xvid_enc_frame.vol_flags |= XVID_EXTRASTATS;
821    
822          /* Set up core's general features */          /* Set up core's general features */
823          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
# Line 807  Line 837 
837          xvid_enc_frame.quant_inter_matrix = NULL;          xvid_enc_frame.quant_inter_matrix = NULL;
838    
839          /* Encode the frame */          /* Encode the frame */
         xvid_enc_frame.vop_flags |= (ARG_STATS)?XVID_EXTRASTATS:0;  
840          ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats);          ret = xvid_encore(enc_handle, XVID_ENC_ENCODE, &xvid_enc_frame, &xvid_enc_stats);
841    
842      *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);      *key = (xvid_enc_frame.out_flags & XVID_KEYFRAME);

Legend:
Removed from v.919  
changed lines
  Added in v.923

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