[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 909, Sun Mar 9 00:28:09 2003 UTC revision 918, Tue Mar 11 23:39:47 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.1 2003-03-09 00:28:09 edgomez Exp $   * $Id: xvid_encraw.c,v 1.11.2.4 2003-03-11 23:39:47 edgomez Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
26  /*****************************************************************************  /*****************************************************************************
27   *  Application notes :   *  Application notes :
28   *   *
29   *  A sequence of YUV pics in PGM file format is encoded and decoded   *  A sequence of raw YUV I420 pics or YUV I420 PGM file format is encoded
30   *  The speed is measured and PSNR of decoded picture is calculated.   *  The speed is measured and frames' PSNR are taken from core.
31   *   *
32   *  The program is plain C and needs no libraries except for libxvidcore,   *  The program is plain C and needs no libraries except for libxvidcore,
33   *  and maths-lib.   *  and maths-lib.
# Line 56  Line 56 
56          PMV_HALFPELREFINE16,          PMV_HALFPELREFINE16,
57          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8,          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8,
58          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16,          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16,
59          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16,          PMV_HALFPELREFINE16 | PMV_HALFPELREFINE8 | PMV_EXTSEARCH16 | PMV_USESQUARES16 | PMV_CHROMA16 | PMV_CHROMA8,
60  };  };
61    
62  static xvid_vol_t const vol_presets[] = {  static xvid_vol_t const vol_presets[] = {
# Line 84  Line 84 
84  /* Maximum number of frames to encode */  /* Maximum number of frames to encode */
85  #define ABS_MAXFRAMENR 9999  #define ABS_MAXFRAMENR 9999
86    
87    static int   ARG_STATS = 0;
88  static int   ARG_BITRATE = 900;  static int   ARG_BITRATE = 900;
89  static int   ARG_QUANTI = 0;  static int   ARG_QUANTI = 0;
90  static int   ARG_QUALITY = 5;  static int   ARG_QUALITY = 5;
# Line 140  Line 141 
141  static int enc_stop();  static int enc_stop();
142  static int enc_main(unsigned char* image,  static int enc_main(unsigned char* image,
143                                          unsigned char* bitstream,                                          unsigned char* bitstream,
144                                          long *frametype);                                          long *frametype,
145                                            int stats[3]);
146    
147  /*****************************************************************************  /*****************************************************************************
148   *               Main function   *               Main function
# Line 216  Line 218 
218                          i++;                          i++;
219                          ARG_INPUTFILE = argv[i];                          ARG_INPUTFILE = argv[i];
220                  }                  }
221                    else if (strcmp("-s", argv[i]) == 0) {
222                            ARG_STATS = 1;
223                    }
224                  else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-t", argv[i]) == 0 && i < argc - 1 ) {
225                          i++;                          i++;
226                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
# Line 228  Line 233 
233                          i++;                          i++;
234                          ARG_QUANTI = atoi(argv[i]);                          ARG_QUANTI = atoi(argv[i]);
235                  }                  }
236                  else if (strcmp("-m", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-m", argv[i]) == 0) {
237                          i++;                          ARG_SAVEMPEGSTREAM = 1;
                         ARG_SAVEMPEGSTREAM = atoi(argv[i]);  
238                  }                  }
239                  else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-o", argv[i]) == 0 && i < argc - 1 ) {
240                          i++;                          i++;
# Line 341  Line 345 
345    
346          do {          do {
347    
348                  if (ARG_INPUTTYPE)                  char *type;
349                          status = read_pgmdata(in_file, in_buffer);      /* read PGM data (YUV-format) */                  int stats[3];
                 else  
                         status = read_yuvdata(in_file, in_buffer);      /* read raw data (YUV-format) */  
350    
351                  if (status)                  if(ARG_INPUTTYPE) {
352                  {                          /* read PGM data (YUV-format) */
353                            status = read_pgmdata(in_file, in_buffer);
354                    } else {
355                            /* read raw data (YUV-format) */
356                            status = read_yuvdata(in_file, in_buffer);
357                    }
358    
359                    if(status) {
360                          /* Couldn't read image, most likely end-of-file */                          /* Couldn't read image, most likely end-of-file */
361                          continue;                          continue;
362                  }                  }
# Line 357  Line 366 
366   ****************************************************************************/   ****************************************************************************/
367    
368                  enctime = msecond();                  enctime = msecond();
369                  m4v_size = enc_main(in_buffer, mp4_buffer, &frame_type);                  m4v_size = enc_main(in_buffer, mp4_buffer, &frame_type, stats);
370                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
371    
372                  /* Not coded frames return 0 */                  /* Not coded frames return 0 */
373                  if(m4v_size == 0) goto next_frame;                  if(m4v_size == 0) goto next_frame;
374    
375                  {                  /* Write the Frame statistics */
                         char *type;  
   
376                          switch(frame_type) {                          switch(frame_type) {
377                          case XVID_TYPE_IVOP:                          case XVID_TYPE_IVOP:
378                                  type = "I";                                  type = "I";
# Line 379  Line 386 
386                          case XVID_TYPE_SVOP:                          case XVID_TYPE_SVOP:
387                                  type = "S";                                  type = "S";
388                                  break;                                  break;
389                    case XVID_TYPE_NOTHING:
390                            type = "N";
391                            break;
392                          default:                          default:
393                                  type = "Unknown";                          type = "U";
394                                  break;                                  break;
395                          }                          }
396    
397                          printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d\n",                  printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d",
398                                     (int)filenr, type, (float)enctime, (int)m4v_size);                             (int)filenr,
399                               type,
400                               (float)enctime,
401                               (int)m4v_size);
402    
403                    if(ARG_STATS) {
404                            printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f",
405                                       (stats[0] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[0]/((float)(XDIM)*(YDIM))),
406                                       (stats[1] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[1]/((float)(XDIM)*(YDIM)/4)),
407                                       (stats[2] == 0)? 0.0f: 48.131f - 10*(float)log10((float)stats[2]/((float)(XDIM)*(YDIM)/4)));
408                  }                  }
409    
410                    printf("\n");
411    
412                  /* Update encoding time stats */                  /* Update encoding time stats */
413                  totalenctime += enctime;                  totalenctime += enctime;
414                  totalsize += m4v_size;                  totalsize += m4v_size;
# Line 415  Line 435 
435                          }                          }
436                  }                  }
437    
438                    filenr++;
439    
440          next_frame:          next_frame:
441                  /* Read the header if it's pgm stream */                  /* Read the header if it's pgm stream */
442                  if (ARG_INPUTTYPE)                  if (ARG_INPUTTYPE)
443                          status = read_pgmheader(in_file);                          status = read_pgmheader(in_file);
444    
                 if(frame_type != 5) filenr++;  
   
445          } while ( (!status) && (filenr<ARG_MAXFRAMENR) );          } while ( (!status) && (filenr<ARG_MAXFRAMENR) );
446    
447    
# Line 436  Line 456 
456          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",
457                     totalenctime, 1000/totalenctime, (int)totalsize);                     totalenctime, 1000/totalenctime, (int)totalsize);
458    
459    
460  /*****************************************************************************  /*****************************************************************************
461   *                            XviD PART  Stop   *                            XviD PART  Stop
462   ****************************************************************************/   ****************************************************************************/
# Line 503  Line 524 
524          fprintf(stderr, " -bqo integer   : bframe quantizer offset (default=100)\n");          fprintf(stderr, " -bqo integer   : bframe quantizer offset (default=100)\n");
525          fprintf(stderr, " -f float       : target framerate (>0)\n");          fprintf(stderr, " -f float       : target framerate (>0)\n");
526          fprintf(stderr, " -i string      : input filename (default=stdin)\n");          fprintf(stderr, " -i string      : input filename (default=stdin)\n");
527            fprintf(stderr, " -s             : print stats about encoded frames\n");
528          fprintf(stderr, " -t integer     : input data type (yuv=0, pgm=1)\n");          fprintf(stderr, " -t integer     : input data type (yuv=0, pgm=1)\n");
529          fprintf(stderr, " -n integer     : number of frames to encode\n");          fprintf(stderr, " -n integer     : number of frames to encode\n");
530          fprintf(stderr, " -q integer     : quality ([0..5])\n");          fprintf(stderr, " -q integer     : quality ([0..5])\n");
531          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");          fprintf(stderr, " -d boolean     : save decoder output (0 False*, !=0 True)\n");
532          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");          fprintf(stderr, " -m             : save mpeg4 raw stream\n");
533          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");
534          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");
535          fprintf(stderr, "                  When this option is used : save to 'string' file\n");          fprintf(stderr, "                  When this option is used : save to 'string' file\n");
# Line 662  Line 684 
684          xvid_enc_create.frame_drop_ratio = 0;          xvid_enc_create.frame_drop_ratio = 0;
685    
686          /* Global encoder options */          /* Global encoder options */
687          xvid_enc_create.global = 0;          xvid_enc_create.global = (ARG_STATS)?XVID_EXTRASTATS_ENABLE:0;
688    
689          /* 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 */
690          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
# Line 685  Line 707 
707    
708  static int enc_main(unsigned char* image,  static int enc_main(unsigned char* image,
709                                          unsigned char* bitstream,                                          unsigned char* bitstream,
710                                          long *frametype)                                          long *frametype,
711                                            int stats[3])
712  {  {
713          int ret;          int ret;
714    
# Line 726  Line 749 
749          xvid_enc_frame.quant_intra_matrix = NULL;          xvid_enc_frame.quant_intra_matrix = NULL;
750          xvid_enc_frame.quant_inter_matrix = NULL;          xvid_enc_frame.quant_inter_matrix = NULL;
751    
752            /* Foll proof */
753            xvid_enc_stats[0].sse_y = 0;
754            xvid_enc_stats[0].sse_v = 0;
755            xvid_enc_stats[0].sse_u = 0;
756    
757            /* Encode the frame */
758            xvid_enc_frame.vop_flags |= (ARG_STATS)?XVID_EXTRASTATS:0;
759          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);
760    
761          *frametype = xvid_enc_stats[0].type;          *frametype = xvid_enc_stats[0].type;
762            stats[0]   = xvid_enc_stats[0].sse_y;
763            stats[1]   = xvid_enc_stats[0].sse_u;
764            stats[2]   = xvid_enc_stats[0].sse_v;
765    
766          return(ret);          return(ret);
767  }  }

Legend:
Removed from v.909  
changed lines
  Added in v.918

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