[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 926, Sun Mar 16 12:05:09 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.8 2003-03-16 12:04:13 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_LUMIMASKING = 0;
91  static int   ARG_BITRATE = 900;  static int   ARG_BITRATE = 900;
92  static int   ARG_QUANTI = 0;  static int   ARG_QUANTI = 0;
93  static int   ARG_QUALITY = 5;  static int   ARG_QUALITY = 5;
# Line 114  Line 117 
117   *                     Nasty global vars ;-)   *                     Nasty global vars ;-)
118   ***************************************************************************/   ***************************************************************************/
119    
120  static int i,filenr = 0;  static int i;
121    
122  /* the path where to save output */  /* the path where to save output */
123  static char filepath[256] = "./";  static char filepath[256] = "./";
# Line 163  Line 166 
166          double totalenctime=0.;          double totalenctime=0.;
167    
168          int totalsize;          int totalsize;
169          int status;          int result;
170          int m4v_size;          int m4v_size;
171      int key;      int key;
172          int stats_type;          int stats_type;
# Line 171  Line 174 
174      int stats_length;      int stats_length;
175          int use_assembler=0;          int use_assembler=0;
176    
177        int input_num;
178        int output_num;
179    
180          char filename[256];          char filename[256];
181    
182          FILE *in_file = stdin;          FILE *in_file = stdin;
# Line 230  Line 236 
236                  else if (strcmp("-s", argv[i]) == 0) {                  else if (strcmp("-s", argv[i]) == 0) {
237                          ARG_STATS = 1;                          ARG_STATS = 1;
238                  }                  }
239                    else if (strcmp("-dump", argv[i]) == 0) {
240                            ARG_DUMP = 1;
241                    }
242                    else if (strcmp("-lumimasking", argv[i]) == 0) {
243                            ARG_LUMIMASKING = 1;
244                    }
245                  else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {
246                          i++;                          i++;
247                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
# Line 323  Line 335 
335   ****************************************************************************/   ****************************************************************************/
336    
337    
338          status = enc_init(use_assembler);          result = enc_init(use_assembler);
339          if (status)          if (result)
340          {          {
341                  fprintf(stderr, "Encore INIT problem, return value %d\n", status);                  fprintf(stderr, "Encore INIT problem, return value %d\n", result);
342                  goto release_all;                  goto release_all;
343          }          }
344    
# Line 352  Line 364 
364    
365          totalsize = 0;          totalsize = 0;
366    
367        result = 0;
368    
369        input_num = 0;  /* input frame counter */
370        output_num = 0; /* output frame counter */
371    
372          do {          do {
373    
374                  char *type;                  char *type;
375                  int stats[3];                  int stats[3];
376    
377            if (input_num >= ARG_MAXFRAMENR)
378            {
379                result = 1;
380            }
381    
382            if (!result)
383            {
384                  if(ARG_INPUTTYPE) {                  if(ARG_INPUTTYPE) {
385                          /* read PGM data (YUV-format) */                          /* read PGM data (YUV-format) */
386                          status = read_pgmdata(in_file, in_buffer);                              result = read_pgmdata(in_file, in_buffer);
387                  } else {                  } else {
388                          /* read raw data (YUV-format) */                          /* read raw data (YUV-format) */
389                          status = read_yuvdata(in_file, in_buffer);                              result = read_yuvdata(in_file, in_buffer);
390                  }                  }
   
                 if(status) {  
                         /* Couldn't read image, most likely end-of-file */  
                         continue;  
391                  }                  }
392    
393  /*****************************************************************************  /*****************************************************************************
# Line 375  Line 395 
395   ****************************************************************************/   ****************************************************************************/
396    
397                  enctime = msecond();                  enctime = msecond();
398                  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);
399                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
400    
401                  /* Write the Frame statistics */                  /* Write the Frame statistics */
402    
403                  printf("Frame %5d: key=%i, time(ms)=%6.1f, length=%7d",                  printf("%5d: key=%i, time(ms)=%6.1f, length=%7d",
404                             (int)filenr,              !result?input_num:-1,
405                             key,                             key,
406                             (float)enctime,                             (float)enctime,
407                             (int)m4v_size);                             (int)m4v_size);
# Line 414  Line 434 
434                                     (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)),
435                                     (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)));
436              }              }
437    
438                  }                  }
439    
440                  printf("\n");                  printf("\n");
441    
442            if (m4v_size < 0) {
443                break;
444            }
445    
446                  /* Update encoding time stats */                  /* Update encoding time stats */
447                  totalenctime += enctime;                  totalenctime += enctime;
448                  totalsize += m4v_size;                  totalsize += m4v_size;
449    
         /* Not coded frames return 0 */  
                 if(m4v_size == 0) goto next_frame;  
   
   
450  /*****************************************************************************  /*****************************************************************************
451   *                       Save stream to file   *                       Save stream to file
452   ****************************************************************************/   ****************************************************************************/
453    
454                  if (ARG_SAVEMPEGSTREAM)                  if (m4v_size>0 && ARG_SAVEMPEGSTREAM)
455                  {                  {
456                          /* Save single files */                          /* Save single files */
457                          if (out_file == NULL) {                          if (out_file == NULL) {
458                                  sprintf(filename, "%sframe%05d.m4v", filepath, filenr);                                  sprintf(filename, "%sframe%05d.m4v", filepath, output_num);
459                                  out_file = fopen(filename, "wb");                                  out_file = fopen(filename, "wb");
460                                  fwrite(mp4_buffer, m4v_size, 1, out_file);                                  fwrite(mp4_buffer, m4v_size, 1, out_file);
461                                  fclose(out_file);                                  fclose(out_file);
462                                  out_file = NULL;                                  out_file = NULL;
463                    output_num++;
464                          }                          }
465                          else {                          else {
466    
# Line 449  Line 470 
470                          }                          }
471                  }                  }
472    
473                  filenr++;                  input_num++;
474    
         next_frame:  
475                  /* Read the header if it's pgm stream */                  /* Read the header if it's pgm stream */
476                  if (ARG_INPUTTYPE)          if (!result && ARG_INPUTTYPE)
477                          status = read_pgmheader(in_file);                          result = read_pgmheader(in_file);
478    
479          } while ( (!status) && (filenr<ARG_MAXFRAMENR) );          } while (1);
480    
481    
482    
# Line 464  Line 484 
484   *         Calculate totals and averages for output, print results   *         Calculate totals and averages for output, print results
485   ****************************************************************************/   ****************************************************************************/
486    
487          totalsize    /= filenr;          printf("Tot: enctime(ms) =%7.2f,               length(bytes) = %7d\n",
488          totalenctime /= filenr;                     totalenctime, (int)totalsize);
489    
490        if (input_num > 0) {
491                totalsize    /= input_num;
492                totalenctime /= input_num;
493        }else{
494            totalsize = -1;
495            totalenctime = -1;
496        }
497    
498          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",
499                     totalenctime, 1000/totalenctime, (int)totalsize);                     totalenctime, 1000/totalenctime, (int)totalsize);
# Line 479  Line 507 
507    
508          if (enc_handle)          if (enc_handle)
509          {          {
510                  status = enc_stop();                  result = enc_stop();
511                  if (status)                  if (result)
512                          fprintf(stderr, "Encore RELEASE problem return value %d\n", status);                          fprintf(stderr, "Encore RELEASE problem return value %d\n", result);
513          }          }
514    
515          if(in_file)          if(in_file)
# Line 543  Line 571 
571          fprintf(stderr, " -t integer     : input data type (yuv=0, pgm=1)\n");          fprintf(stderr, " -t integer     : input data type (yuv=0, pgm=1)\n");
572          fprintf(stderr, " -n integer     : number of frames to encode\n");          fprintf(stderr, " -n integer     : number of frames to encode\n");
573          fprintf(stderr, " -q integer     : quality ([0..5])\n");          fprintf(stderr, " -q integer     : quality ([0..5])\n");
574          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -dump          : save decoder output\n");
575          fprintf(stderr, " -m             : save mpeg4 raw stream\n");          fprintf(stderr, " -m             : save mpeg4 raw stream\n");
576          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");
577          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 638  Line 666 
666      switch(opt)      switch(opt)
667      {      {
668      case XVID_PLG_INFO :      case XVID_PLG_INFO :
669            {
670            xvid_plg_info_t * info = (xvid_plg_info_t*)param1;
671            info->flags = XVID_REQDQUANTS;
672            return 0;
673            }
674    
675      case XVID_PLG_CREATE :      case XVID_PLG_CREATE :
676      case XVID_PLG_DESTROY :      case XVID_PLG_DESTROY :
677      case XVID_PLG_BEFORE :      case XVID_PLG_BEFORE :
# Line 646  Line 680 
680      case XVID_PLG_AFTER :      case XVID_PLG_AFTER :
681         {         {
682         xvid_plg_data_t * data = (xvid_plg_data_t*)param1;         xvid_plg_data_t * data = (xvid_plg_data_t*)param1;
683         printf("type=%i, quant=%i, length=%i\n", data->type, data->quant, data->length);          int i,j;
684    
685            printf("---[ frame: %5i   quant: %2i   length: %6i ]---\n", data->frame_num, data->quant, data->length);
686            for (j=0; j<data->mb_height; j++) {
687                for (i = 0; i<data->mb_width; i++)
688                    printf("%2i ",  data->dquant[j*data->dquant_stride + i]);
689                printf("\n");
690            }
691    
692         return 0;         return 0;
693         }         }
694      }      }
# Line 662  Line 704 
704  {  {
705          int xerr;          int xerr;
706    
707      /* xvid_enc_plugin_t plugins[1]; */      xvid_enc_plugin_t plugins[2];
708    
709          xvid_gbl_init_t   xvid_gbl_init;          xvid_gbl_init_t   xvid_gbl_init;
710          xvid_enc_create_t xvid_enc_create;          xvid_enc_create_t xvid_enc_create;
# Line 704  Line 746 
746          xvid_enc_create.width = XDIM;          xvid_enc_create.width = XDIM;
747          xvid_enc_create.height = YDIM;          xvid_enc_create.height = YDIM;
748    
749      /* init plugins      /* init plugins  */
750      plugins[0].func =  rawenc_debug;  
751      plugins[0].param = NULL;      xvid_enc_create.plugins = plugins;
752      xvid_enc_create.num_plugins = 1;      xvid_enc_create.num_plugins = 0;
753      xvid_enc_create.plugins = plugins; */  
754        if (ARG_LUMIMASKING) {
755            plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
756            plugins[xvid_enc_create.num_plugins].param = NULL;
757            xvid_enc_create.num_plugins++;
758        }
759    
760        if (ARG_DUMP) {
761            plugins[xvid_enc_create.num_plugins].func = xvid_plugin_dump;
762            plugins[xvid_enc_create.num_plugins].param = NULL;
763            xvid_enc_create.num_plugins++;
764        }
765    
766    /*   plugins[xvid_enc_create.num_plugins].func = rawenc_debug;
767         plugins[xvid_enc_create.num_plugins].param = NULL;
768         xvid_enc_create.num_plugins++; */
769    
770          /* No fancy thread tests */          /* No fancy thread tests */
771          xvid_enc_create.num_threads = 0;          xvid_enc_create.num_threads = 0;
# Line 735  Line 792 
792    
793          /* Global encoder options */          /* Global encoder options */
794          xvid_enc_create.global = 0;          xvid_enc_create.global = 0;
     if (ARG_STATS) xvid_enc_create.global |= XVID_EXTRASTATS_ENABLE;  
795      if (ARG_PACKED) xvid_enc_create.global |= XVID_PACKED;      if (ARG_PACKED) xvid_enc_create.global |= XVID_PACKED;
796        if (ARG_STATS) xvid_enc_create.global |= XVID_EXTRASTATS_ENABLE;
797    
798          /* 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 */
799          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 839 
839          xvid_enc_frame.length = -1;          xvid_enc_frame.length = -1;
840    
841          /* Initialize input image fields */          /* Initialize input image fields */
842        if (image) {
843          xvid_enc_frame.input.plane[0]  = image;          xvid_enc_frame.input.plane[0]  = image;
844          xvid_enc_frame.input.csp       = XVID_CSP_I420;          xvid_enc_frame.input.csp       = XVID_CSP_I420;
845          xvid_enc_frame.input.stride[0] = XDIM;          xvid_enc_frame.input.stride[0] = XDIM;
846        }else{
847            xvid_enc_frame.input.csp       = XVID_CSP_NULL;
848        }
849    
850          /* Set up core's general features */          /* Set up core's general features */
851          xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY];          xvid_enc_frame.vol_flags = vol_presets[ARG_QUALITY];
852        if (ARG_STATS) xvid_enc_frame.vol_flags |= XVID_EXTRASTATS;
853    
854          /* Set up core's general features */          /* Set up core's general features */
855          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];          xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY];
# Line 797  Line 859 
859    
860          /* Force the right quantizer */          /* Force the right quantizer */
861          xvid_enc_frame.quant  = ARG_QUANTI;          xvid_enc_frame.quant  = ARG_QUANTI;
         xvid_enc_frame.bquant = 0;  
862    
863          /* Set up motion estimation flags */          /* Set up motion estimation flags */
864          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];          xvid_enc_frame.motion = motion_presets[ARG_QUALITY];
# Line 807  Line 868 
868          xvid_enc_frame.quant_inter_matrix = NULL;          xvid_enc_frame.quant_inter_matrix = NULL;
869    
870          /* Encode the frame */          /* Encode the frame */
         xvid_enc_frame.vop_flags |= (ARG_STATS)?XVID_EXTRASTATS:0;  
871          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);
872    
873      *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.926

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