[svn] / trunk / xvidcore / examples / xvid_encraw.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/examples/xvid_encraw.c

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

revision 1883, Tue Mar 9 10:00:30 2010 UTC revision 2070, Fri Feb 7 16:00:50 2014 UTC
# Line 22  Line 22 
22   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
23   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24   *   *
25   * $Id: xvid_encraw.c,v 1.39 2010-03-09 10:00:22 Isibaar Exp $   * $Id$
26   *   *
27   ****************************************************************************/   ****************************************************************************/
28    
# Line 189  Line 189 
189  static  int ARG_CPU_FLAGS = 0;  static  int ARG_CPU_FLAGS = 0;
190  static  int ARG_STATS = 0;  static  int ARG_STATS = 0;
191  static  int ARG_SSIM = -1;  static  int ARG_SSIM = -1;
192    static  int ARG_PSNRHVSM = 0;
193  static  char* ARG_SSIM_PATH = NULL;  static  char* ARG_SSIM_PATH = NULL;
194  static  int ARG_DUMP = 0;  static  int ARG_DUMP = 0;
195  static  int ARG_LUMIMASKING = 0;  static  int ARG_LUMIMASKING = 0;
# Line 199  Line 200 
200  static  char *ARG_PASS2 = 0;  static  char *ARG_PASS2 = 0;
201  //static int ARG_QUALITY = ME_ELEMENTS - 1;  //static int ARG_QUALITY = ME_ELEMENTS - 1;
202  static  int ARG_QUALITY = 6;  static  int ARG_QUALITY = 6;
203  static  float ARG_FRAMERATE = 25.00f;  static  float ARG_FRAMERATE = 0.f;
204  static  int ARG_DWRATE = 25;  static  int ARG_DWRATE = 25;
205  static  int ARG_DWSCALE = 1;  static  int ARG_DWSCALE = 1;
206  static  int ARG_MAXFRAMENR = ABS_MAXFRAMENR;  static  int ARG_MAXFRAMENR = ABS_MAXFRAMENR;
# Line 230  Line 231 
231  static  int ARG_TURBO = 0;  static  int ARG_TURBO = 0;
232  static  int ARG_VHQMODE = 1;  static  int ARG_VHQMODE = 1;
233  static  int ARG_BVHQ = 0;  static  int ARG_BVHQ = 0;
234    static  int ARG_QMETRIC = 0;
235  static  int ARG_CLOSED_GOP = 1;  static  int ARG_CLOSED_GOP = 1;
236  static  int ARG_CHROMAME = 1;  static  int ARG_CHROMAME = 1;
237  static  int ARG_PAR = 1;  static  int ARG_PAR = 1;
# Line 255  Line 257 
257  static  int ARG_VBVMAXRATE = 0;  static  int ARG_VBVMAXRATE = 0;
258  static  int ARG_VBVPEAKRATE = 0;  static  int ARG_VBVPEAKRATE = 0;
259  static  int ARG_THREADS = 0;  static  int ARG_THREADS = 0;
260    static  int ARG_SLICES = 1;
261  static  int ARG_VFR = 0;  static  int ARG_VFR = 0;
262  static  int ARG_PROGRESS = 0;  static  int ARG_PROGRESS = 0;
263  static  int ARG_COLORSPACE = XVID_CSP_YV12;  static  int ARG_COLORSPACE = XVID_CSP_YV12;
# Line 345  Line 348 
348          int use_assembler = 1;          int use_assembler = 1;
349          int i;          int i;
350    
 #if defined(XVID_AVI_INPUT)  
         PAVIFILE avi_in = NULL;  
         PAVISTREAM avi_in_stream = NULL;  
         PGETFRAME get_frame = NULL;  
 #else  
 #define get_frame NULL  
 #endif  
 #if defined(XVID_AVI_OUTPUT)  
         PAVIFILE myAVIFile = NULL;  
         PAVISTREAM myAVIStream = NULL;  
         BITMAPINFOHEADER myBitmapInfoHeader;  
 #endif  
 #if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT)  
         AVIFileInit();  
 #endif  
 #ifdef XVID_MKV_OUTPUT  
         PMKVFILE myMKVFile=NULL;  
         PMKVSTREAM myMKVStream=NULL;  
         MKVSTREAMINFO myMKVStreamInfo;  
 #endif  
   
351          printf("xvid_encraw - raw mpeg4 bitstream encoder ");          printf("xvid_encraw - raw mpeg4 bitstream encoder ");
352          printf("written by Christoph Lampert\n\n");          printf("written by Christoph Lampert\n\n");
353    
354          /* Is there a dumb Xvid coder ? */          /* Is there a dumb Xvid coder ? */
355          if(ME_ELEMENTS != VOP_ELEMENTS) {          if(ME_ELEMENTS != VOP_ELEMENTS) {
356                  fprintf(stderr, "Presets' arrays should have the same number of elements -- Please fill a bug to xvid-devel@xvid.org\n");                  fprintf(stderr, "Presets' arrays should have the same number of elements -- Please file a bug to xvid-devel@xvid.org\n");
357                  return(-1);                  return(-1);
358          }          }
359    
# Line 409  Line 391 
391                                  ARG_BITRATE = atoi(argv[i+1]);                                  ARG_BITRATE = atoi(argv[i+1]);
392                          if (ARG_BITRATE) {                          if (ARG_BITRATE) {
393                                  i++;                                  i++;
394                                  if (ARG_BITRATE <= 10000)                                  if (ARG_BITRATE <= 20000)
395                                          /* if given parameter is <= 10000, assume it means kbps */                                          /* if given parameter is <= 20000, assume it means kbps */
396                                          ARG_BITRATE *= 1000;                                          ARG_BITRATE *= 1000;
397                          }                          }
398                          else                          else
# Line 466  Line 448 
448                  } else if (strcmp("-threads", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-threads", argv[i]) == 0 && i < argc -1) {
449                          i++;                          i++;
450                          ARG_THREADS = atoi(argv[i]);                          ARG_THREADS = atoi(argv[i]);
451                    } else if (strcmp("-slices", argv[i]) == 0 && i < argc -1) {
452                            i++;
453                            ARG_SLICES = atoi(argv[i]);
454                  } else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) {
455                          i++;                          i++;
456                          ARG_BQRATIO = atoi(argv[i]);                          ARG_BQRATIO = atoi(argv[i]);
# Line 500  Line 485 
485                                  memset(&ZONES[NUM_ZONES], 0, sizeof(zone_t));                                  memset(&ZONES[NUM_ZONES], 0, sizeof(zone_t));
486    
487                                  ZONES[NUM_ZONES].frame = startframe;                                  ZONES[NUM_ZONES].frame = startframe;
488                                  ZONES[NUM_ZONES].modifier = atof(options)*100;                                  ZONES[NUM_ZONES].modifier = (int)(atof(options)*100);
489                                  if (toupper(c)=='Q')                                  if (toupper(c)=='Q')
490                                          ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT;                                          ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT;
491                                  else if (toupper(c)=='W')                                  else if (toupper(c)=='W')
# Line 513  Line 498 
498                                  if ((frameoptions=strchr(options, ','))!=NULL) {                                  if ((frameoptions=strchr(options, ','))!=NULL) {
499                                          int readchar=0, count;                                          int readchar=0, count;
500                                          frameoptions++;                                          frameoptions++;
501                                          while (readchar<strlen(frameoptions)) {                                          while (readchar<(int)strlen(frameoptions)) {
502                                                  if (sscanf(frameoptions+readchar, "%d%n", &(ZONES[NUM_ZONES].bvop_threshold), &count)==1) {                                                  if (sscanf(frameoptions+readchar, "%d%n", &(ZONES[NUM_ZONES].bvop_threshold), &count)==1) {
503                                                          readchar += count;                                                          readchar += count;
504                                                  }                                                  }
# Line 551  Line 536 
536                          else {                          else {
537                                  ZONES[NUM_ZONES].mode = XVID_ZONE_WEIGHT;                                  ZONES[NUM_ZONES].mode = XVID_ZONE_WEIGHT;
538                          }                          }
539                          ZONES[NUM_ZONES].modifier = atof(argv[i+2])*100;                          ZONES[NUM_ZONES].modifier = (int)(atof(argv[i+2])*100);
540                          i++;                          i++;
541              ZONES[NUM_ZONES].frame = atoi(argv[i]);              ZONES[NUM_ZONES].frame = atoi(argv[i]);
542                          i++;                          i++;
# Line 571  Line 556 
556                  } else if (strcmp("-vhqmode", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-vhqmode", argv[i]) == 0 && i < argc - 1) {
557                          i++;                          i++;
558                          ARG_VHQMODE = atoi(argv[i]);                          ARG_VHQMODE = atoi(argv[i]);
559                    } else if (strcmp("-metric", argv[i]) == 0 && i < argc - 1) {
560                            i++;
561                            ARG_QMETRIC = atoi(argv[i]);
562                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {
563                          int exponent;                          int exponent;
564                          i++;                          i++;
565                          ARG_FRAMERATE = (float) atof(argv[i]);                          ARG_FRAMERATE = (float) atof(argv[i]);
566                          exponent = strcspn(argv[i], ".");                          exponent = (int)strcspn(argv[i], ".");
567                          if (exponent<strlen(argv[i]))                          if (exponent<(int)strlen(argv[i]))
568                                  exponent=pow(10.0, (int)(strlen(argv[i])-1-exponent));                                  exponent=(int)pow(10.0, (int)(strlen(argv[i])-1-exponent));
569                          else                          else
570                                  exponent=1;                                  exponent=1;
571                          ARG_DWRATE = atof(argv[i])*exponent;                          ARG_DWRATE = (int)(atof(argv[i])*exponent);
572                          ARG_DWSCALE = exponent;                          ARG_DWSCALE = exponent;
573                          exponent = gcd(ARG_DWRATE, ARG_DWSCALE);                          exponent = gcd(ARG_DWRATE, ARG_DWSCALE);
574                          ARG_DWRATE /= exponent;                          ARG_DWRATE /= exponent;
# Line 599  Line 587 
587                                  i++;                                  i++;
588                                  ARG_SSIM = atoi(argv[i]);                                  ARG_SSIM = atoi(argv[i]);
589                          }                          }
590                    } else if (strcmp("-psnrhvsm", argv[i]) == 0) {
591                            ARG_PSNRHVSM = 1;
592                  } else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) {
593                          i++;                          i++;
594                          ARG_SSIM_PATH = argv[i];                          ARG_SSIM_PATH = argv[i];
# Line 718  Line 708 
708                          ARG_VBVMAXRATE = atoi(argv[i]);                          ARG_VBVMAXRATE = atoi(argv[i]);
709                  } else if (strcmp("-vbvpeak", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-vbvpeak", argv[i]) == 0 && i < argc -1) {
710                          i++;                          i++;
711                          ARG_VBVPEAKRATE = atoi(argv[i])*3;                          ARG_VBVPEAKRATE = atoi(argv[i]);
712                  } else if (strcmp("-reaction", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-reaction", argv[i]) == 0 && i < argc -1) {
713                          i++;                          i++;
714                          ARG_REACTION = atoi(argv[i]);                          ARG_REACTION = atoi(argv[i]);
# Line 763  Line 753 
753                                  i++;                                  i++;
754                          else                          else
755                                  ARG_PROGRESS = 10;                                  ARG_PROGRESS = 10;
756                  } else if (strcmp("-help", argv[i])) {                  } else if (strcmp("-help", argv[i]) == 0) {
757                          usage();                          usage();
758                          return (0);                          return (0);
759                  } else {                  } else {
# Line 834  Line 824 
824          }          }
825    
826          if (ARG_INPUTFILE != NULL) {          if (ARG_INPUTFILE != NULL) {
827  #ifdef XVID_AVI_INPUT  #if defined(XVID_AVI_INPUT)
828        if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 ||        if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 ||
829            strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 ||            strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 ||
830                    ARG_INPUTTYPE==2)                    ARG_INPUTTYPE==2)
831        {        {
832                      PAVIFILE avi_in = NULL;
833                      PAVISTREAM avi_in_stream = NULL;
834                      PGETFRAME get_frame = NULL;
835                      BITMAPINFOHEADER myBitmapInfoHeader;
836                    AVISTREAMINFO avi_info;                    AVISTREAMINFO avi_info;
   
837                    FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");                    FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");
838    
839                      AVIFileInit();
840    
841                    if (avi_fp == NULL) {                    if (avi_fp == NULL) {
842                            fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);                            fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);
843                            return (-1);                            return (-1);
# Line 904  Line 900 
900                                  temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0);                                  temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0);
901                                  if (temp != NULL) {                                  if (temp != NULL) {
902                                          int i;                                          int i;
903                                          for (i = 0; i < ((DWORD*)temp)[0]; i++) {                                          for (i = 0; i < (int)((DWORD*)temp)[0]; i++) {
904                                                  fprintf(stderr, "%2d ", temp[i]);                                                  fprintf(stderr, "%2d ", temp[i]);
905                                          }                                          }
906                                          fprintf(stderr, "\n");                                          fprintf(stderr, "\n");
# Line 920  Line 916 
916            if (ARG_MAXFRAMENR<0)            if (ARG_MAXFRAMENR<0)
917                          ARG_MAXFRAMENR = avi_info.dwLength-ARG_STARTFRAMENR;                          ARG_MAXFRAMENR = avi_info.dwLength-ARG_STARTFRAMENR;
918                    else                    else
919                          ARG_MAXFRAMENR = min(ARG_MAXFRAMENR, avi_info.dwLength-ARG_STARTFRAMENR);                          ARG_MAXFRAMENR = min(ARG_MAXFRAMENR, (int)(avi_info.dwLength-ARG_STARTFRAMENR));
920    
921                    XDIM = avi_info.rcFrame.right - avi_info.rcFrame.left;                    XDIM = avi_info.rcFrame.right - avi_info.rcFrame.left;
922                    YDIM = avi_info.rcFrame.bottom - avi_info.rcFrame.top;                    YDIM = avi_info.rcFrame.bottom - avi_info.rcFrame.top;
# Line 934  Line 930 
930    
931                    if (get_frame) AVIStreamGetFrameClose(get_frame);                    if (get_frame) AVIStreamGetFrameClose(get_frame);
932                    if (avi_in_stream) AVIStreamRelease(avi_in_stream);                    if (avi_in_stream) AVIStreamRelease(avi_in_stream);
933                      AVIFileExit();
934        }        }
935        else        else
936  #endif  #endif
# Line 954  Line 951 
951          }          }
952    
953          if (ARG_FRAMERATE <= 0) {          if (ARG_FRAMERATE <= 0) {
954                  fprintf(stderr, "Wrong Framerate %f\n", ARG_FRAMERATE);                  ARG_FRAMERATE = 25.00f; /* default value */
                 return (-1);  
955          }          }
956    
957          if (ARG_TARGETSIZE) {          if (ARG_TARGETSIZE) {
# Line 966  Line 962 
962                                  fprintf(stderr, "Parameter conflict: Do not specify both -bitrate and -size\n");                                  fprintf(stderr, "Parameter conflict: Do not specify both -bitrate and -size\n");
963                                  goto release_all;                                  goto release_all;
964                  } else                  } else
965                          ARG_BITRATE = ((ARG_TARGETSIZE * 8) / (ARG_MAXFRAMENR / ARG_FRAMERATE)) * 1024;                          ARG_BITRATE = (int)(((ARG_TARGETSIZE * 8) / (ARG_MAXFRAMENR / ARG_FRAMERATE)) * 1024);
966          }          }
967    
968                  /* Set constant quant to default if no bitrate given for single pass */                  /* Set constant quant to default if no bitrate given for single pass */
# Line 1037  Line 1033 
1033                                  sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k);                                  sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k);
1034                                  enc_data[k].statsfilename1 = statsfilename[k];                                  enc_data[k].statsfilename1 = statsfilename[k];
1035                          }                          }
1036                          enc_data[k].start_num = (ARG_MAXFRAMENR-ARG_STARTFRAMENR)/ARG_NUM_APP_THREADS;                          enc_data[k].start_num = (k*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS;
1037                          enc_data[k].stop_num = ((k+1)*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS;                          enc_data[k].stop_num = ((k+1)*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS;
1038                  }                  }
1039    
# Line 1067  Line 1063 
1063                          totalenctime = MAX(totalenctime, enc_data[k].totalenctime);                          totalenctime = MAX(totalenctime, enc_data[k].totalenctime);
1064    
1065                          for (i=0; i < 3; i++) totalPSNR[i] += enc_data[k].totalPSNR[i];                          for (i=0; i < 3; i++) totalPSNR[i] += enc_data[k].totalPSNR[i];
1066                          for (i=0; i < 8; i++) {                          for (i=0; i < 7; i++) {
1067                                  int l;                                  int l;
1068                                  framestats[i].count += enc_data[k].framestats[i].count;                                  framestats[i].count += enc_data[k].framestats[i].count;
1069                                  framestats[i].size += enc_data[k].framestats[i].size;                                  framestats[i].size += enc_data[k].framestats[i].size;
# Line 1162  Line 1158 
1158    
1159    release_all:    release_all:
1160    
 #if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT)  
         AVIFileExit();  
 #endif  
   
1161          return (0);          return (0);
   
1162  }  }
1163    
1164  /*****************************************************************************  /*****************************************************************************
# Line 1210  Line 1201 
1201    
1202          char filename[256];          char filename[256];
1203    
1204    #ifdef XVID_MKV_OUTPUT
1205            PMKVFILE myMKVFile = NULL;
1206            PMKVSTREAM myMKVStream = NULL;
1207            MKVSTREAMINFO myMKVStreamInfo;
1208    #endif
1209  #if defined(XVID_AVI_INPUT)  #if defined(XVID_AVI_INPUT)
1210          PAVIFILE avi_in = NULL;          PAVIFILE avi_in = NULL;
1211          PAVISTREAM avi_in_stream = NULL;          PAVISTREAM avi_in_stream = NULL;
1212          PGETFRAME get_frame = NULL;          PGETFRAME get_frame = NULL;
1213            BITMAPINFOHEADER myBitmapInfoHeader;
1214  #else  #else
1215  #define get_frame NULL  #define get_frame NULL
1216  #endif  #endif
# Line 1222  Line 1219 
1219          PAVIFILE myAVIFile=NULL;          PAVIFILE myAVIFile=NULL;
1220          PAVISTREAM myAVIStream=NULL;          PAVISTREAM myAVIStream=NULL;
1221          AVISTREAMINFO myAVIStreamInfo;          AVISTREAMINFO myAVIStreamInfo;
1222          BITMAPINFOHEADER myBitmapInfoHeader;  #endif
1223    #if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT)
1224            if (ARG_NUM_APP_THREADS > 1)
1225                    CoInitializeEx(0, COINIT_MULTITHREADED);
1226            AVIFileInit();
1227  #endif  #endif
1228    
1229          if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
# Line 1236  Line 1237 
1237                    AVISTREAMINFO avi_info;                    AVISTREAMINFO avi_info;
1238                    FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");                    FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");
1239    
                   if (ARG_NUM_APP_THREADS > 1)  
                           CoInitializeEx(0, COINIT_MULTITHREADED);  
   
1240                    if (avi_fp == NULL) {                    if (avi_fp == NULL) {
1241                            fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);                            fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);
1242                            return;                            return;
# Line 1301  Line 1299 
1299                                  temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0);                                  temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0);
1300                                  if (temp != NULL) {                                  if (temp != NULL) {
1301                                          int i;                                          int i;
1302                                          for (i = 0; i < ((DWORD*)temp)[0]; i++) {                                          for (i = 0; i < (int)((DWORD*)temp)[0]; i++) {
1303                                                  fprintf(stderr, "%2d ", temp[i]);                                                  fprintf(stderr, "%2d ", temp[i]);
1304                                          }                                          }
1305                                          fprintf(stderr, "\n");                                          fprintf(stderr, "\n");
# Line 1411  Line 1409 
1409                          myAVIStreamInfo.dwRate = ARG_DWRATE;                          myAVIStreamInfo.dwRate = ARG_DWRATE;
1410                          myAVIStreamInfo.dwLength = ARG_MAXFRAMENR;                          myAVIStreamInfo.dwLength = ARG_MAXFRAMENR;
1411                          myAVIStreamInfo.dwQuality = 10000;                          myAVIStreamInfo.dwQuality = 10000;
1412                          SetRect(&myAVIStreamInfo.rcFrame, 0, 0, YDIM, XDIM);                          SetRect(&myAVIStreamInfo.rcFrame, 0, 0, XDIM, YDIM);
1413    
1414                          if (avierr=AVIFileOpen(&myAVIFile, ARG_AVIOUTPUTFILE, OF_CREATE|OF_WRITE, NULL)) {                          if (avierr=AVIFileOpen(&myAVIFile, ARG_AVIOUTPUTFILE, OF_CREATE|OF_WRITE, NULL)) {
1415                                  fprintf(stderr, "AVIFileOpen failed opening output file %s, error code %d\n", ARG_AVIOUTPUTFILE, avierr);                                  fprintf(stderr, "AVIFileOpen failed opening output file %s, error code %d\n", ARG_AVIOUTPUTFILE, avierr);
# Line 1528  Line 1526 
1526   *                       Encode and decode this frame   *                       Encode and decode this frame
1527   ****************************************************************************/   ****************************************************************************/
1528    
1529                  if ((input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) {                  if ((unsigned int)(input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) {
1530                          stats_type = XVID_TYPE_PVOP;                          stats_type = XVID_TYPE_PVOP;
1531                  }                  }
1532                  else                  else
# Line 1722  Line 1720 
1720          if (myMKVStream) MKVStreamRelease(myMKVStream);          if (myMKVStream) MKVStreamRelease(myMKVStream);
1721          if (myMKVFile) MKVFileRelease(myMKVFile);          if (myMKVFile) MKVFileRelease(myMKVFile);
1722  #endif  #endif
1723    #if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT)
1724            AVIFileExit();
1725    #endif
1726    
1727    free_all_memory:    free_all_memory:
1728          free(out_buffer);          free(out_buffer);
# Line 1829  Line 1830 
1830  #ifdef XVID_AVI_OUTPUT  #ifdef XVID_AVI_OUTPUT
1831          fprintf(stderr, " -avi string: save an AVI file for the complete sequence\n");          fprintf(stderr, " -avi string: save an AVI file for the complete sequence\n");
1832  #endif  #endif
1833    #ifdef XVID_MKV_OUTPUT
1834          fprintf(stderr, " -mkv string: save a MKV file for the complete sequence\n");          fprintf(stderr, " -mkv string: save a MKV file for the complete sequence\n");
1835    #endif
1836          fprintf(stderr, "\n");          fprintf(stderr, "\n");
1837          fprintf(stderr, "BFrames options:\n");          fprintf(stderr, "BFrames options:\n");
1838          fprintf(stderr, " -max_bframes   integer: max bframes (2)\n");          fprintf(stderr, " -max_bframes   integer: max bframes (2)\n");
# Line 1837  Line 1840 
1840          fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (100)\n");          fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (100)\n");
1841          fprintf(stderr, "\n");          fprintf(stderr, "\n");
1842          fprintf(stderr, "Rate control options:\n");          fprintf(stderr, "Rate control options:\n");
1843          fprintf(stderr, " -framerate float               : target framerate (25.0)\n");          fprintf(stderr, " -framerate float               : target framerate (auto)\n");
1844          fprintf(stderr, " -bitrate   [integer]           : target bitrate in kbps (700)\n");          fprintf(stderr, " -bitrate   [integer]           : target bitrate in kbps (700)\n");
1845          fprintf(stderr, " -size      integer                     : target size in kilobytes\n");          fprintf(stderr, " -size      integer                     : target size in kilobytes\n");
1846      fprintf(stderr,     " -single                        : single pass mode (default)\n");      fprintf(stderr,     " -single                        : single pass mode (default)\n");
# Line 1863  Line 1866 
1866          fprintf(stderr, "-odegrade   integer             : max overflow degradation (5)\n");          fprintf(stderr, "-odegrade   integer             : max overflow degradation (5)\n");
1867          fprintf(stderr, "-chigh      integer             : high bitrate scenes degradation (0)\n");          fprintf(stderr, "-chigh      integer             : high bitrate scenes degradation (0)\n");
1868          fprintf(stderr, "-clow       integer             : low bitrate scenes improvement (0)\n");          fprintf(stderr, "-clow       integer             : low bitrate scenes improvement (0)\n");
1869          fprintf(stderr, "-overhead   integer             : container frame overhead (24)\n");          fprintf(stderr, "-overhead   integer             : container frame overhead (0)\n");
1870          fprintf(stderr, "-vbvsize    integer             : use vbv buffer size\n");          fprintf(stderr, "-vbvsize    integer             : use vbv buffer size\n");
1871          fprintf(stderr, "-vbvmax     integer             : vbv max bitrate\n");          fprintf(stderr, "-vbvmax     integer             : vbv max bitrate\n");
1872          fprintf(stderr, "-vbvpeak    integer             : vbv peak bitrate over 1 second\n");          fprintf(stderr, "-vbvpeak    integer             : vbv peak bitrate over 1 second\n");
# Line 1874  Line 1877 
1877          fprintf(stderr, " -quality integer               : quality ([0..%d]) (6)\n", ME_ELEMENTS - 1);          fprintf(stderr, " -quality integer               : quality ([0..%d]) (6)\n", ME_ELEMENTS - 1);
1878          fprintf(stderr, " -vhqmode integer               : level of R-D optimizations ([0..4]) (1)\n");          fprintf(stderr, " -vhqmode integer               : level of R-D optimizations ([0..4]) (1)\n");
1879          fprintf(stderr, " -bvhq                          : use R-D optimizations for B-frames\n");          fprintf(stderr, " -bvhq                          : use R-D optimizations for B-frames\n");
1880            fprintf(stderr, " -metric integer                : distortion metric for R-D opt (PSNR:0, PSNRHVSM: 1)\n");
1881          fprintf(stderr, " -qpel                          : use quarter pixel ME\n");          fprintf(stderr, " -qpel                          : use quarter pixel ME\n");
1882          fprintf(stderr, " -gmc                           : use global motion compensation\n");          fprintf(stderr, " -gmc                           : use global motion compensation\n");
1883          fprintf(stderr, " -qtype   integer               : quantization type (H263:0, MPEG4:1) (0)\n");          fprintf(stderr, " -qtype   integer               : quantization type (H263:0, MPEG4:1) (0)\n");
# Line 1885  Line 1889 
1889          fprintf(stderr, " -stats                         : print stats about encoded frames\n");          fprintf(stderr, " -stats                         : print stats about encoded frames\n");
1890          fprintf(stderr, " -ssim [integer]                : prints ssim for every frame (accurate: 0 fast: 4) (2)\n");          fprintf(stderr, " -ssim [integer]                : prints ssim for every frame (accurate: 0 fast: 4) (2)\n");
1891          fprintf(stderr, " -ssim_file filename            : outputs the ssim stats into a file\n");          fprintf(stderr, " -ssim_file filename            : outputs the ssim stats into a file\n");
1892            fprintf(stderr, " -psnrhvsm                      : prints PSNRHVSM metric for every frame\n");
1893          fprintf(stderr, " -debug                         : activates xvidcore internal debugging output\n");          fprintf(stderr, " -debug                         : activates xvidcore internal debugging output\n");
1894          fprintf(stderr, " -vop_debug                     : print some info directly into encoded frames\n");          fprintf(stderr, " -vop_debug                     : print some info directly into encoded frames\n");
1895          fprintf(stderr, " -nochromame                    : Disable chroma motion estimation\n");          fprintf(stderr, " -nochromame                    : Disable chroma motion estimation\n");
# Line 1898  Line 1903 
1903          fprintf(stderr, " -drop    integer               : Frame Drop Ratio (0..100) (0)\n");          fprintf(stderr, " -drop    integer               : Frame Drop Ratio (0..100) (0)\n");
1904          fprintf(stderr, " -start   integer               : Starting frame number\n");          fprintf(stderr, " -start   integer               : Starting frame number\n");
1905          fprintf(stderr, " -threads integer               : Number of threads\n");          fprintf(stderr, " -threads integer               : Number of threads\n");
1906            fprintf(stderr, " -slices  integer               : Number of slices\n");
1907          fprintf(stderr, " -progress [integer]            : Show progress updates every n frames (10)\n");          fprintf(stderr, " -progress [integer]            : Show progress updates every n frames (10)\n");
1908          fprintf(stderr, " -par     integer[:integer]     : Set Pixel Aspect Ratio.\n");          fprintf(stderr, " -par     integer[:integer]     : Set Pixel Aspect Ratio.\n");
1909          fprintf(stderr, "                                  1 = 1:1\n");          fprintf(stderr, "                                  1 = 1:1\n");
# Line 1926  Line 1932 
1932          int bytes, xsize, ysize, depth;          int bytes, xsize, ysize, depth;
1933          char dummy[2];          char dummy[2];
1934    
1935          bytes = fread(dummy, 1, 2, handle);          bytes = (int) fread(dummy, 1, 2, handle);
1936    
1937          if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5'))          if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5'))
1938                  return (1);                  return (1);
1939    
1940          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);          fscanf(handle, "%d %d %d", &xsize, &ysize, &depth);
1941            fread(&dummy, 1, 1, handle);
1942          if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) {          if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) {
1943                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);                  fprintf(stderr, "%d %d %d\n", xsize, ysize, depth);
1944                  return (2);                  return (2);
# Line 1949  Line 1956 
1956                           unsigned char *image)                           unsigned char *image)
1957  {  {
1958          int i;          int i;
         char dummy;  
1959    
1960          unsigned char *y = image;          unsigned char *y = image;
1961          unsigned char *u = image + XDIM * YDIM;          unsigned char *u = image + XDIM * YDIM;
# Line 1970  Line 1976 
1976                  v += XDIM / 2;                  v += XDIM / 2;
1977          }          }
1978    
         /*  I don't know why, but this seems needed */  
         fread(&dummy, 1, 1, handle);  
   
1979          return (0);          return (0);
1980  }  }
1981  #else  #else
# Line 2183  Line 2186 
2186                  rc2pass2.vbv_size     =  ARG_VBVSIZE;                  rc2pass2.vbv_size     =  ARG_VBVSIZE;
2187                  rc2pass2.vbv_initial  =  (ARG_VBVSIZE*3)/4;                  rc2pass2.vbv_initial  =  (ARG_VBVSIZE*3)/4;
2188                  rc2pass2.vbv_maxrate  =  ARG_VBVMAXRATE;                  rc2pass2.vbv_maxrate  =  ARG_VBVMAXRATE;
2189                  rc2pass2.vbv_peakrate =  ARG_VBVPEAKRATE*3;                  rc2pass2.vbv_peakrate =  ARG_VBVPEAKRATE;
2190    
2191    
2192                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
# Line 2250  Line 2253 
2253                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
2254          }          }
2255    
2256            if (ARG_PSNRHVSM>0) {
2257            plugins[xvid_enc_create.num_plugins].func = xvid_plugin_psnrhvsm;
2258                    plugins[xvid_enc_create.num_plugins].param = NULL;
2259                    xvid_enc_create.num_plugins++;
2260            }
2261    
2262  #if 0  #if 0
2263          if (ARG_DEBUG) {          if (ARG_DEBUG) {
2264                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;
# Line 2259  Line 2268 
2268  #endif  #endif
2269    
2270          xvid_enc_create.num_threads = ARG_THREADS;          xvid_enc_create.num_threads = ARG_THREADS;
2271            xvid_enc_create.num_slices  = ARG_SLICES;
2272    
2273          /* Frame rate  */          /* Frame rate  */
2274          xvid_enc_create.fincr = ARG_DWSCALE;          xvid_enc_create.fincr = ARG_DWSCALE;
# Line 2481  Line 2491 
2491          if (ARG_BVHQ)          if (ARG_BVHQ)
2492                  xvid_enc_frame.vop_flags |= XVID_VOP_RD_BVOP;                  xvid_enc_frame.vop_flags |= XVID_VOP_RD_BVOP;
2493    
2494            if (ARG_QMETRIC == 1)
2495                    xvid_enc_frame.vop_flags |= XVID_VOP_RD_PSNRHVSM;
2496    
2497          switch (ARG_VHQMODE) /* this is the same code as for vfw */          switch (ARG_VHQMODE) /* this is the same code as for vfw */
2498          {          {
2499          case 1: /* VHQ_MODE_DECISION */          case 1: /* VHQ_MODE_DECISION */
# Line 2576  Line 2589 
2589    
2590                  ZONES[NUM_ZONES].frame = 0;                  ZONES[NUM_ZONES].frame = 0;
2591                  ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT;                  ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT;
2592                  ZONES[NUM_ZONES].modifier = ARG_CQ;                  ZONES[NUM_ZONES].modifier = (int)ARG_CQ;
2593                  ZONES[NUM_ZONES].type = XVID_TYPE_AUTO;                  ZONES[NUM_ZONES].type = XVID_TYPE_AUTO;
2594                  ZONES[NUM_ZONES].greyscale = 0;                  ZONES[NUM_ZONES].greyscale = 0;
2595                  ZONES[NUM_ZONES].chroma_opt = 0;                  ZONES[NUM_ZONES].chroma_opt = 0;
# Line 2592  Line 2605 
2605          for(i = 0; i < NUM_ZONES; i++)          for(i = 0; i < NUM_ZONES; i++)
2606                  if (ZONES[i].mode == XVID_ZONE_WEIGHT) {                  if (ZONES[i].mode == XVID_ZONE_WEIGHT) {
2607                          ZONES[i].mode = XVID_ZONE_QUANT;                          ZONES[i].mode = XVID_ZONE_QUANT;
2608                          ZONES[i].modifier = (100*ARG_CQ) / ZONES[i].modifier;                          ZONES[i].modifier = (int) ((100*ARG_CQ) / ZONES[i].modifier);
2609                  }                  }
2610  }  }
2611    
# Line 2661  Line 2674 
2674          int i;          int i;
2675          char* userdata;          char* userdata;
2676    
2677          for (i=0; i <= (bufsize-sizeof(userdata_start_code)); i++) {          for (i=0; i <= (int)(bufsize-sizeof(userdata_start_code)); i++) {
2678                  if (memcmp((void*)userdata_start_code, (void*)(buf+i), strlen(userdata_start_code))==0) {                  if (memcmp((void*)userdata_start_code, (void*)(buf+i), strlen(userdata_start_code))==0) {
2679                          if ((userdata = strstr(buf+i+4, "DivX"))!=NULL) {                          if ((userdata = strstr(buf+i+4, "DivX"))!=NULL) {
2680                                  userdata[strlen(userdata)-1] = '\0';                                  userdata[strlen(userdata)-1] = '\0';

Legend:
Removed from v.1883  
changed lines
  Added in v.2070

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