[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 1757, Wed Nov 8 06:55:27 2006 UTC revision 1909, Sun Nov 28 15:19:07 2010 UTC
# Line 6  Line 6 
6   *  Copyright(C) 2002-2003 Christoph Lampert <gruel@web.de>   *  Copyright(C) 2002-2003 Christoph Lampert <gruel@web.de>
7   *               2002-2003 Edouard Gomez <ed.gomez@free.fr>   *               2002-2003 Edouard Gomez <ed.gomez@free.fr>
8   *               2003      Peter Ross <pross@xvid.org>   *               2003      Peter Ross <pross@xvid.org>
9     *               2003-2010 Michael Militzer <isibaar@xvid.org>
10   *   *
11   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
12   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# Line 21  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.33 2006-11-08 06:55:27 Skal Exp $   * $Id: xvid_encraw.c,v 1.45 2010-11-28 15:19:07 Isibaar Exp $
26   *   *
27   ****************************************************************************/   ****************************************************************************/
28    
# Line 54  Line 55 
55  #endif  #endif
56    
57  #include "xvid.h"  #include "xvid.h"
58    #include "portab.h" /* for pthread */
59    
60  #ifdef XVID_MKV_OUTPUT  #ifdef XVID_MKV_OUTPUT
61  #include "matroska.cpp"  #include "matroska.cpp"
# Line 61  Line 63 
63    
64  #undef READ_PNM  #undef READ_PNM
65    
66    //#define USE_APP_LEVEL_THREADING /* Should xvid_encraw app use multi-threading? */
67    
68  /*****************************************************************************  /*****************************************************************************
69   *                            Quality presets   *                            Quality presets
70   ****************************************************************************/   ****************************************************************************/
# Line 121  Line 125 
125   ****************************************************************************/   ****************************************************************************/
126    
127  #define MAX_ZONES   64  #define MAX_ZONES   64
128    #define MAX_ENC_INSTANCES 4
129  #define DEFAULT_QUANT 400  #define DEFAULT_QUANT 400
130    
131  typedef struct  typedef struct
# Line 145  Line 149 
149          int quants[32];          int quants[32];
150  } frame_stats_t;  } frame_stats_t;
151    
152    typedef struct
153    {
154            pthread_t handle;       /* thread's handle */
155    
156            int start_num;          /* begin/end of sequence */
157            int stop_num;
158    
159            char *outfilename;      /* output filename */
160            char *statsfilename1;   /* pass1 statsfile */
161    
162            int input_num;
163    
164            int totalsize;          /* encoder stats */
165            double totalenctime;
166            float totalPSNR[3];
167            frame_stats_t framestats[7];
168    } enc_sequence_data_t;
169    
170  /* Maximum number of frames to encode */  /* Maximum number of frames to encode */
171  #define ABS_MAXFRAMENR -1 /* no limit */  #define ABS_MAXFRAMENR -1 /* no limit */
172    
# Line 162  Line 184 
184    
185  static zone_t ZONES[MAX_ZONES];  static zone_t ZONES[MAX_ZONES];
186  static  int NUM_ZONES = 0;  static  int NUM_ZONES = 0;
 static  frame_stats_t framestats[7];  
187    
188    static  int ARG_NUM_APP_THREADS = 1;
189    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 187  Line 211 
211  static  int ARG_SAVEMPEGSTREAM = 0;  static  int ARG_SAVEMPEGSTREAM = 0;
212  static  int ARG_SAVEINDIVIDUAL = 0;  static  int ARG_SAVEINDIVIDUAL = 0;
213  static  char *ARG_OUTPUTFILE = NULL;  static  char *ARG_OUTPUTFILE = NULL;
 #ifdef XVID_AVI_OUTPUT  
214  static  char *ARG_AVIOUTPUTFILE = NULL;  static  char *ARG_AVIOUTPUTFILE = NULL;
 #endif  
 #ifdef XVID_MKV_OUTPUT  
215  static  char *ARG_MKVOUTPUTFILE = NULL;  static  char *ARG_MKVOUTPUTFILE = NULL;
 #endif  
 #ifdef XVID_AVI_INPUT  
 static  PAVISTREAM avi_stream = NULL;  
 static  PAVIFILE avi_file = NULL;  
 static  LPBITMAPINFOHEADER info_header = NULL;  
 static  PGETFRAME get_frame = NULL;  
 #else  
 #define get_frame NULL  
 #endif  
216  static  char *ARG_TIMECODEFILE = NULL;  static  char *ARG_TIMECODEFILE = NULL;
217  static  int XDIM = 0;  static  int XDIM = 0;
218  static  int YDIM = 0;  static  int YDIM = 0;
# Line 219  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 249  Line 262 
262  static  int ARG_COLORSPACE = XVID_CSP_YV12;  static  int ARG_COLORSPACE = XVID_CSP_YV12;
263          /* the path where to save output */          /* the path where to save output */
264  static char filepath[256] = "./";  static char filepath[256] = "./";
265          /* Internal structures (handles) for encoding and decoding */  
 static  void *enc_handle = NULL;  
266  static  unsigned char qmatrix_intra[64];  static  unsigned char qmatrix_intra[64];
267  static  unsigned char qmatrix_inter[64];  static  unsigned char qmatrix_inter[64];
268    
# Line 292  Line 304 
304                                                  unsigned char *image);                                                  unsigned char *image);
305    
306  /* Encoder related functions */  /* Encoder related functions */
307  static int enc_init(int use_assembler);  static void enc_gbl(int use_assembler);
308    static int  enc_init(void **enc_handle, char *stats_pass1, int start_num);
309  static int enc_info();  static int enc_info();
310  static int enc_stop();  static int  enc_stop(void *enc_handle);
311  static int enc_main(unsigned char *image,  static int  enc_main(void *enc_handle,
312                                             unsigned char *image,
313                                          unsigned char *bitstream,                                          unsigned char *bitstream,
314                                          int *key,                                          int *key,
315                                          int *stats_type,                                          int *stats_type,
# Line 303  Line 317 
317                                          int *stats_length,                                          int *stats_length,
318                                          int stats[3],                                          int stats[3],
319                                          int framenum);                                          int framenum);
320    static void encode_sequence(enc_sequence_data_t *h);
321    
322  /* Zone Related Functions */  /* Zone Related Functions */
323  static void apply_zone_modifiers(xvid_enc_frame_t * frame, int framenum);  static void apply_zone_modifiers(xvid_enc_frame_t * frame, int framenum);
# Line 321  Line 336 
336  main(int argc,  main(int argc,
337           char *argv[])           char *argv[])
338  {  {
   
         unsigned char *mp4_buffer = NULL;  
         unsigned char *in_buffer = NULL;  
         unsigned char *out_buffer = NULL;  
   
         double enctime;  
339          double totalenctime = 0.;          double totalenctime = 0.;
340          float totalPSNR[3] = {0., 0., 0.};          float totalPSNR[3] = {0., 0., 0.};
341    
342          FILE *statsfile;          FILE *statsfile;
343            frame_stats_t framestats[7];
344    
345          int totalsize;          int input_num = 0;
346          int result;          int totalsize = 0;
         int m4v_size;  
         int key;  
         int stats_type;  
         int stats_quant;  
         int stats_length;  
347          int use_assembler = 1;          int use_assembler = 1;
         int fakenvop = 0;  
348          int i;          int i;
         int nvop_counter;  
   
         int input_num;  
         int output_num;  
   
         char filename[256];  
   
         FILE *in_file = stdin;  
         FILE *out_file = NULL;  
         FILE *time_file = NULL;  
   
 #ifdef XVID_AVI_OUTPUT  
         int avierr;  
         PAVIFILE myAVIFile=NULL;  
         PAVISTREAM myAVIStream=NULL;  
         AVISTREAMINFO myAVIStreamInfo;  
         BITMAPINFOHEADER myBitmapInfoHeader;  
         AVIFileInit();  
 #endif  
 #ifdef XVID_MKV_OUTPUT  
         PMKVFILE myMKVFile=NULL;  
         PMKVSTREAM myMKVStream=NULL;  
         MKVSTREAMINFO myMKVStreamInfo;  
 #endif  
349    
350          printf("xvid_encraw - raw mpeg4 bitstream encoder ");          printf("xvid_encraw - raw mpeg4 bitstream encoder ");
351          printf("written by Christoph Lampert 2002-2003\n\n");          printf("written by Christoph Lampert\n\n");
352    
353          /* Is there a dumb XviD coder ? */          /* Is there a dumb Xvid coder ? */
354          if(ME_ELEMENTS != VOP_ELEMENTS) {          if(ME_ELEMENTS != VOP_ELEMENTS) {
355                  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 fill a bug to xvid-devel@xvid.org\n");
356                  return(-1);                  return(-1);
357          }          }
358    
359            /* Clear framestats */
360            memset(framestats, 0, sizeof(framestats));
361    
362  /*****************************************************************************  /*****************************************************************************
363   *                            Command line parsing   *                            Command line parsing
364   ****************************************************************************/   ****************************************************************************/
# Line 391  Line 375 
375                  } else if (strcmp("-h", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-h", argv[i]) == 0 && i < argc - 1) {
376                          i++;                          i++;
377                          YDIM = atoi(argv[i]);                          YDIM = atoi(argv[i]);
378                    } else if (strcmp("-csp",argv[i]) == 0 && i < argc - 1) {
379                            i++;
380                            if (strcmp(argv[i],"i420") == 0){
381                                    ARG_COLORSPACE = XVID_CSP_I420;
382                            } else if(strcmp(argv[i],"yv12") == 0){
383                                    ARG_COLORSPACE = XVID_CSP_YV12;
384                            } else {
385                                    printf("Invalid colorspace\n");
386                                    return 0;
387                            }
388          } else if (strcmp("-bitrate", argv[i]) == 0) {          } else if (strcmp("-bitrate", argv[i]) == 0) {
389                          if (i < argc - 1)                          if (i < argc - 1)
390                                  ARG_BITRATE = atoi(argv[i+1]);                                  ARG_BITRATE = atoi(argv[i+1]);
391                          if (ARG_BITRATE) {                          if (ARG_BITRATE) {
392                                  i++;                                  i++;
393                                  if (ARG_BITRATE <= 10000)                                  if (ARG_BITRATE <= 20000)
394                                          /* if given parameter is <= 10000, assume it means kbps */                                          /* if given parameter is <= 20000, assume it means kbps */
395                                          ARG_BITRATE *= 1000;                                          ARG_BITRATE *= 1000;
396                          }                          }
397                          else                          else
# Line 558  Line 552 
552                  } else if (strcmp("-vhqmode", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-vhqmode", argv[i]) == 0 && i < argc - 1) {
553                          i++;                          i++;
554                          ARG_VHQMODE = atoi(argv[i]);                          ARG_VHQMODE = atoi(argv[i]);
555                    } else if (strcmp("-metric", argv[i]) == 0 && i < argc - 1) {
556                            i++;
557                            ARG_QMETRIC = atoi(argv[i]);
558                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) {
559                          int exponent;                          int exponent;
560                          i++;                          i++;
# Line 586  Line 583 
583                                  i++;                                  i++;
584                                  ARG_SSIM = atoi(argv[i]);                                  ARG_SSIM = atoi(argv[i]);
585                          }                          }
586                    } else if (strcmp("-psnrhvsm", argv[i]) == 0) {
587                            ARG_PSNRHVSM = 1;
588                  } else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) {
589                          i++;                          i++;
590                          ARG_SSIM_PATH = argv[i];                          ARG_SSIM_PATH = argv[i];
# Line 594  Line 593 
593                          ARG_TIMECODEFILE = argv[i];                          ARG_TIMECODEFILE = argv[i];
594                  } else if (strcmp("-dump", argv[i]) == 0) {                  } else if (strcmp("-dump", argv[i]) == 0) {
595                          ARG_DUMP = 1;                          ARG_DUMP = 1;
596                  } else if (strcmp("-lumimasking", argv[i]) == 0) {                  } else if (strcmp("-masking", argv[i]) == 0 && i < argc -1) {
597                          ARG_LUMIMASKING = 1;                          i++;
598                            ARG_LUMIMASKING = atoi(argv[i]);
599                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {                  } else if (strcmp("-type", argv[i]) == 0 && i < argc - 1) {
600                          i++;                          i++;
601                          ARG_INPUTTYPE = atoi(argv[i]);                          ARG_INPUTTYPE = atoi(argv[i]);
# Line 704  Line 704 
704                          ARG_VBVMAXRATE = atoi(argv[i]);                          ARG_VBVMAXRATE = atoi(argv[i]);
705                  } else if (strcmp("-vbvpeak", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-vbvpeak", argv[i]) == 0 && i < argc -1) {
706                          i++;                          i++;
707                          ARG_VBVPEAKRATE = atoi(argv[i])*3;                          ARG_VBVPEAKRATE = atoi(argv[i]);
708                  } else if (strcmp("-reaction", argv[i]) == 0 && i < argc -1) {                  } else if (strcmp("-reaction", argv[i]) == 0 && i < argc -1) {
709                          i++;                          i++;
710                          ARG_REACTION = atoi(argv[i]);                          ARG_REACTION = atoi(argv[i]);
# Line 819  Line 819 
819                  return (-1);                  return (-1);
820          }          }
821    
822          if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {          if (ARG_INPUTFILE != NULL) {
823                  in_file = stdin;  #if defined(XVID_AVI_INPUT)
         } else {  
 #ifdef XVID_AVI_INPUT  
824        if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 ||        if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 ||
825            strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 ||            strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 ||
826                    ARG_INPUTTYPE==2)                    ARG_INPUTTYPE==2)
827        {        {
828                      PAVIFILE avi_in = NULL;
829                      PAVISTREAM avi_in_stream = NULL;
830                      PGETFRAME get_frame = NULL;
831                      BITMAPINFOHEADER myBitmapInfoHeader;
832                    AVISTREAMINFO avi_info;                    AVISTREAMINFO avi_info;
 #ifndef XVID_AVI_OUTPUT  
                   AVIFileInit();  
 #endif  
833                    FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");                    FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");
834    
835                      AVIFileInit();
836    
837                    if (avi_fp == NULL) {                    if (avi_fp == NULL) {
838                            fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);                            fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);
839                            return (-1);                            return (-1);
840                    }                    }
841                    fclose(avi_fp);                    fclose(avi_fp);
842    
843                    if (AVIFileOpen(&avi_file, ARG_INPUTFILE, OF_READ, NULL) != AVIERR_OK) {                    if (AVIFileOpen(&avi_in, ARG_INPUTFILE, OF_READ, NULL) != AVIERR_OK) {
844                            fprintf(stderr, "Can't open avi/avs file %s\n", ARG_INPUTFILE);                            fprintf(stderr, "Can't open avi/avs file %s\n", ARG_INPUTFILE);
845                            AVIFileExit();                            AVIFileExit();
846                            return(-1);                            return(-1);
847                    }                    }
848    
849                    if (AVIFileGetStream(avi_file, &avi_stream, streamtypeVIDEO, 0) != AVIERR_OK) {                    if (AVIFileGetStream(avi_in, &avi_in_stream, streamtypeVIDEO, 0) != AVIERR_OK) {
850                            fprintf(stderr, "Can't open stream from file '%s'!\n", ARG_INPUTFILE);                            fprintf(stderr, "Can't open stream from file '%s'!\n", ARG_INPUTFILE);
851                            AVIFileRelease(avi_file);                            AVIFileRelease(avi_in);
852                            AVIFileExit();                            AVIFileExit();
853                            return (-1);                            return (-1);
854                    }                    }
855    
856                    AVIFileRelease(avi_file);                    AVIFileRelease(avi_in);
857    
858                    if(AVIStreamInfo(avi_stream, &avi_info, sizeof(AVISTREAMINFO)) != AVIERR_OK) {                    if(AVIStreamInfo(avi_in_stream, &avi_info, sizeof(AVISTREAMINFO)) != AVIERR_OK) {
859                            fprintf(stderr, "Can't get stream info from file '%s'!\n", ARG_INPUTFILE);                            fprintf(stderr, "Can't get stream info from file '%s'!\n", ARG_INPUTFILE);
860                            AVIStreamRelease(avi_stream);                            AVIStreamRelease(avi_in_stream);
861                            AVIFileExit();                            AVIFileExit();
862                            return (-1);                            return (-1);
863                    }                    }
# Line 866  Line 868 
868                                    avi_info.fccHandler%256, (avi_info.fccHandler>>8)%256, (avi_info.fccHandler>>16)%256,                                    avi_info.fccHandler%256, (avi_info.fccHandler>>8)%256, (avi_info.fccHandler>>16)%256,
869                                    (avi_info.fccHandler>>24)%256);                                    (avi_info.fccHandler>>24)%256);
870                            size = sizeof(myBitmapInfoHeader);                            size = sizeof(myBitmapInfoHeader);
871                            AVIStreamReadFormat(avi_stream, 0, &myBitmapInfoHeader, &size);                            AVIStreamReadFormat(avi_in_stream, 0, &myBitmapInfoHeader, &size);
872                            if (size==0)                            if (size==0)
873                                    fprintf(stderr, "AVIStreamReadFormat read 0 bytes.\n");                                    fprintf(stderr, "AVIStreamReadFormat read 0 bytes.\n");
874                            else {                            else {
# Line 881  Line 883 
883                                    myBitmapInfoHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');                                    myBitmapInfoHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');
884                                    myBitmapInfoHeader.biBitCount = 12;                                    myBitmapInfoHeader.biBitCount = 12;
885                                    myBitmapInfoHeader.biSizeImage = (myBitmapInfoHeader.biWidth*myBitmapInfoHeader.biHeight)*3/2;                                    myBitmapInfoHeader.biSizeImage = (myBitmapInfoHeader.biWidth*myBitmapInfoHeader.biHeight)*3/2;
886                                    get_frame = AVIStreamGetFrameOpen(avi_stream, &myBitmapInfoHeader);                                    get_frame = AVIStreamGetFrameOpen(avi_in_stream, &myBitmapInfoHeader);
887                            }                            }
888                            if (get_frame == NULL) {                            if (get_frame == NULL) {
889                                  AVIStreamRelease(avi_stream);                                  AVIStreamRelease(avi_in_stream);
890                                  AVIFileExit();                                  AVIFileExit();
891                                  return (-1);                                  return (-1);
892                            }                            }
# Line 921  Line 923 
923                    }                    }
924    
925                    ARG_INPUTTYPE = 2;                    ARG_INPUTTYPE = 2;
926    
927                      if (get_frame) AVIStreamGetFrameClose(get_frame);
928                      if (avi_in_stream) AVIStreamRelease(avi_in_stream);
929                      AVIFileExit();
930      }      }
931      else      else
932  #endif  #endif
933                  {                  {
934                          in_file = fopen(ARG_INPUTFILE, "rb");                          FILE *in_file = fopen(ARG_INPUTFILE, "rb");
935                            int pos = 0;
936                          if (in_file == NULL) {                          if (in_file == NULL) {
937                                  fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);                                  fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
938                                  return (-1);                                  return (-1);
939                          }                          }
940                  }  #ifdef USE_APP_LEVEL_THREADING
941          }                          fseek(in_file, 0, SEEK_END); /* Determine input size */
942                            pos = ftell(in_file);
943          // This should be after the avi input opening stuff                          ARG_MAXFRAMENR = pos / IMAGE_SIZE(XDIM, YDIM); /* PGM, header size ?? */
944          if (ARG_TIMECODEFILE != NULL) {  #endif
945                  time_file = fopen(ARG_TIMECODEFILE, "r");                          fclose(in_file);
                 if (time_file==NULL) {  
                         fprintf(stderr, "Couldn't open timecode file '%s'!\n", ARG_TIMECODEFILE);  
                         return(-1);  
                 }  
                 else {  
                         fscanf(time_file, "# timecode format v2\n");  
946                  }                  }
947          }          }
948    
# Line 965  Line 966 
966          if (ARG_SINGLE && (!ARG_BITRATE) && (!ARG_CQ))          if (ARG_SINGLE && (!ARG_BITRATE) && (!ARG_CQ))
967                          ARG_CQ = DEFAULT_QUANT;                          ARG_CQ = DEFAULT_QUANT;
968    
969                    /* Init xvidcore */
970        enc_gbl(use_assembler);
971    
972    #ifdef USE_APP_LEVEL_THREADING
973            if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0 ||
974                ARG_NUM_APP_THREADS <= 1 || ARG_THREADS != 0 ||
975                ARG_TIMECODEFILE != NULL || ARG_AVIOUTPUTFILE != NULL ||
976                ARG_INPUTTYPE == 1 || ARG_MKVOUTPUTFILE != NULL)            /* TODO: PGM input */
977    #endif /* Spawn just one encoder instance */
978            {
979                    enc_sequence_data_t enc_data;
980                    memset(&enc_data, 0, sizeof(enc_sequence_data_t));
981    
982                    if (!ARG_THREADS) ARG_THREADS = ARG_NUM_APP_THREADS;
983                    ARG_NUM_APP_THREADS = 1;
984    
985                    enc_data.outfilename = ARG_OUTPUTFILE;
986                    enc_data.statsfilename1 = ARG_PASS1;
987                    enc_data.start_num = ARG_STARTFRAMENR;
988                    enc_data.stop_num = ARG_MAXFRAMENR;
989    
990                            /* Encode input */
991                    encode_sequence(&enc_data);
992    
993                            /* Copy back stats */
994                    input_num = enc_data.input_num;
995                    totalsize = enc_data.totalsize;
996                    totalenctime = enc_data.totalenctime;
997                    for (i=0; i < 3; i++) totalPSNR[i] = enc_data.totalPSNR[i];
998                    memcpy(framestats, enc_data.framestats, sizeof(framestats));
999            }
1000    #ifdef USE_APP_LEVEL_THREADING
1001            else { /* Split input into sequences and create multiple encoder instances */
1002                    int k;
1003                    void *status;
1004                    FILE *f_out = NULL, *f_stats = NULL;
1005    
1006                    enc_sequence_data_t enc_data[MAX_ENC_INSTANCES];
1007                    char outfile[MAX_ENC_INSTANCES][256];
1008                    char statsfilename[MAX_ENC_INSTANCES][256];
1009    
1010                    for (k = 0; k < MAX_ENC_INSTANCES; k++)
1011                            memset(&enc_data[k], 0, sizeof(enc_sequence_data_t));
1012    
1013                            /* Overwrite internal encoder threading */
1014                    if (ARG_NUM_APP_THREADS > MAX_ENC_INSTANCES) {
1015                            ARG_THREADS = (int) (ARG_NUM_APP_THREADS / MAX_ENC_INSTANCES);
1016                            ARG_NUM_APP_THREADS = MAX_ENC_INSTANCES;
1017                    }
1018                    else
1019                            ARG_THREADS = -1;
1020    
1021                    enc_data[0].outfilename = ARG_OUTPUTFILE;
1022                    enc_data[0].statsfilename1 = ARG_PASS1;
1023                    enc_data[0].start_num = ARG_STARTFRAMENR;
1024                    enc_data[0].stop_num = (ARG_MAXFRAMENR-ARG_STARTFRAMENR)/ARG_NUM_APP_THREADS;
1025    
1026                    for (k = 1; k < ARG_NUM_APP_THREADS; k++) {
1027                            sprintf(outfile[k], "%s.%03d", ARG_OUTPUTFILE, k);
1028                            enc_data[k].outfilename = outfile[k];
1029                            if (ARG_PASS1) {
1030                                    sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k);
1031                                    enc_data[k].statsfilename1 = statsfilename[k];
1032                            }
1033                            enc_data[k].start_num = (k*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS;
1034                            enc_data[k].stop_num = ((k+1)*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS;
1035                    }
1036    
1037                            /* Start multiple encoder threads in parallel */
1038                    for (k = 1; k < ARG_NUM_APP_THREADS; k++) {
1039                            pthread_create(&enc_data[k].handle, NULL, (void*)encode_sequence, (void*)&enc_data[k]);
1040                    }
1041    
1042                            /* Encode first sequence in this thread */
1043                    encode_sequence(&enc_data[0]);
1044    
1045                            /* Wait until encoder threads have finished */
1046                    for (k = 1; k < ARG_NUM_APP_THREADS; k++) {
1047                            pthread_join(enc_data[k].handle, &status);
1048                    }
1049    
1050                            /* Join encoder stats and encoder output files */
1051                    if (ARG_OUTPUTFILE)
1052                            f_out = fopen(enc_data[0].outfilename, "ab+");
1053                    if (ARG_PASS1)
1054                            f_stats = fopen(enc_data[0].statsfilename1, "ab+");
1055    
1056                    for (k = 0; k < ARG_NUM_APP_THREADS; k++) {
1057                                    /* Join stats */
1058                            input_num += enc_data[k].input_num;
1059                            totalsize += enc_data[k].totalsize;
1060                            totalenctime = MAX(totalenctime, enc_data[k].totalenctime);
1061    
1062                            for (i=0; i < 3; i++) totalPSNR[i] += enc_data[k].totalPSNR[i];
1063                            for (i=0; i < 8; i++) {
1064                                    int l;
1065                                    framestats[i].count += enc_data[k].framestats[i].count;
1066                                    framestats[i].size += enc_data[k].framestats[i].size;
1067                                    for (l=0; l < 32; l++)
1068                                            framestats[i].quants[l] += enc_data[k].framestats[i].quants[l];
1069                            }
1070                                    /* Join output files */
1071                            if ((k > 0) && (f_out != NULL)) {
1072                                    int ch;
1073                                    FILE *f = fopen(enc_data[k].outfilename, "rb");
1074                                    while((ch = fgetc(f)) != EOF) { fputc(ch, f_out); }
1075                                    fclose(f);
1076                                    remove(enc_data[k].outfilename);
1077                            }
1078                                    /* Join first pass stats files */
1079                            if ((k > 0) && (f_stats != NULL)) {
1080                                    char str[256];
1081                                    FILE *f = fopen(enc_data[k].statsfilename1, "r");
1082                                    while(fgets(str, sizeof(str), f) != NULL) {
1083                                            if (str[0] != '#' && strlen(str) > 3)
1084                                                    fputs(str, f_stats);
1085                                    }
1086                                    fclose(f);
1087                                    remove(enc_data[k].statsfilename1);
1088                            }
1089                    }
1090                    if (f_out) fclose(f_out);
1091                    if (f_stats) fclose(f_stats);
1092            }
1093    #endif
1094    
1095    /*****************************************************************************
1096     *         Calculate totals and averages for output, print results
1097     ****************************************************************************/
1098    
1099     printf("\n");
1100            printf("Tot: enctime(ms) =%7.2f,               length(bytes) = %7d\n",
1101                       totalenctime, (int) totalsize);
1102    
1103            if (input_num > 0) {
1104                    totalsize /= input_num;
1105                    totalenctime /= input_num;
1106                    totalPSNR[0] /= input_num;
1107                    totalPSNR[1] /= input_num;
1108                    totalPSNR[2] /= input_num;
1109            } else {
1110                    totalsize = -1;
1111                    totalenctime = -1;
1112            }
1113    
1114            printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d",
1115                       totalenctime, 1000 / totalenctime, (int) totalsize);
1116       if (ARG_STATS) {
1117           printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f",
1118                      totalPSNR[0],totalPSNR[1],totalPSNR[2]);
1119            }
1120            printf("\n");
1121            if (framestats[XVID_TYPE_IVOP].count) {
1122                    printf("I frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \
1123                            framestats[XVID_TYPE_IVOP].count, framestats[XVID_TYPE_IVOP].size/framestats[XVID_TYPE_IVOP].count, \
1124                            framestats[XVID_TYPE_IVOP].size, minquant(framestats[XVID_TYPE_IVOP].quants), \
1125                            avgquant(framestats[XVID_TYPE_IVOP]), maxquant(framestats[XVID_TYPE_IVOP].quants));
1126            }
1127            if (framestats[XVID_TYPE_PVOP].count) {
1128                    printf("P frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \
1129                            framestats[XVID_TYPE_PVOP].count, framestats[XVID_TYPE_PVOP].size/framestats[XVID_TYPE_PVOP].count, \
1130                            framestats[XVID_TYPE_PVOP].size, minquant(framestats[XVID_TYPE_PVOP].quants), \
1131                            avgquant(framestats[XVID_TYPE_PVOP]), maxquant(framestats[XVID_TYPE_PVOP].quants));
1132            }
1133            if (framestats[XVID_TYPE_BVOP].count) {
1134                    printf("B frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \
1135                            framestats[XVID_TYPE_BVOP].count, framestats[XVID_TYPE_BVOP].size/framestats[XVID_TYPE_BVOP].count, \
1136                            framestats[XVID_TYPE_BVOP].size, minquant(framestats[XVID_TYPE_BVOP].quants), \
1137                            avgquant(framestats[XVID_TYPE_BVOP]), maxquant(framestats[XVID_TYPE_BVOP].quants));
1138            }
1139            if (framestats[XVID_TYPE_SVOP].count) {
1140                    printf("S frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \
1141                            framestats[XVID_TYPE_SVOP].count, framestats[XVID_TYPE_SVOP].size/framestats[XVID_TYPE_SVOP].count, \
1142                            framestats[XVID_TYPE_SVOP].size, minquant(framestats[XVID_TYPE_SVOP].quants), \
1143                            avgquant(framestats[XVID_TYPE_SVOP]), maxquant(framestats[XVID_TYPE_SVOP].quants));
1144            }
1145            if (framestats[5].count) {
1146                    printf("N frames: %6d frames, size = %7d/%7d\n", \
1147                            framestats[5].count, framestats[5].size/framestats[5].count, \
1148                            framestats[5].size);
1149            }
1150    
1151    
1152    /*****************************************************************************
1153     *                            Xvid PART  Stop
1154     ****************************************************************************/
1155    
1156      release_all:
1157    
1158            return (0);
1159    }
1160    
1161    /*****************************************************************************
1162     *               Encode a sequence
1163     ****************************************************************************/
1164    
1165    void encode_sequence(enc_sequence_data_t *h) {
1166    
1167            /* Internal structures (handles) for encoding */
1168            void *enc_handle = NULL;
1169    
1170            int start_num = h->start_num;
1171            int stop_num = h->stop_num;
1172            char *outfilename = h->outfilename;
1173            float *totalPSNR = h->totalPSNR;
1174    
1175            int input_num;
1176            int totalsize;
1177            double totalenctime = 0.;
1178    
1179            unsigned char *mp4_buffer = NULL;
1180            unsigned char *in_buffer = NULL;
1181            unsigned char *out_buffer = NULL;
1182    
1183            double enctime;
1184    
1185            int result;
1186            int output_num;
1187            int nvop_counter;
1188            int m4v_size;
1189            int key;
1190            int stats_type;
1191            int stats_quant;
1192            int stats_length;
1193            int fakenvop = 0;
1194    
1195            FILE *in_file = stdin;
1196            FILE *out_file = NULL;
1197            FILE *time_file = NULL;
1198    
1199            char filename[256];
1200    
1201    #ifdef XVID_MKV_OUTPUT
1202            PMKVFILE myMKVFile = NULL;
1203            PMKVSTREAM myMKVStream = NULL;
1204            MKVSTREAMINFO myMKVStreamInfo;
1205    #endif
1206    #if defined(XVID_AVI_INPUT)
1207            PAVIFILE avi_in = NULL;
1208            PAVISTREAM avi_in_stream = NULL;
1209            PGETFRAME get_frame = NULL;
1210            BITMAPINFOHEADER myBitmapInfoHeader;
1211    #else
1212    #define get_frame NULL
1213    #endif
1214    #if defined(XVID_AVI_OUTPUT)
1215            int avierr;
1216            PAVIFILE myAVIFile = NULL;
1217            PAVISTREAM myAVIStream = NULL;
1218            AVISTREAMINFO myAVIStreamInfo;
1219    #endif
1220    #if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT)
1221            if (ARG_NUM_APP_THREADS > 1)
1222                    CoInitializeEx(0, COINIT_MULTITHREADED);
1223            AVIFileInit();
1224    #endif
1225    
1226            if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) {
1227                    in_file = stdin;
1228            } else {
1229    #ifdef XVID_AVI_INPUT
1230          if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 ||
1231              strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 ||
1232                      ARG_INPUTTYPE==2)
1233          {
1234                      AVISTREAMINFO avi_info;
1235                      FILE *avi_fp = fopen(ARG_INPUTFILE, "rb");
1236    
1237                      if (avi_fp == NULL) {
1238                              fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE);
1239                              return;
1240                      }
1241                      fclose(avi_fp);
1242    
1243                      if (AVIFileOpen(&avi_in, ARG_INPUTFILE, OF_READ, NULL) != AVIERR_OK) {
1244                              fprintf(stderr, "Can't open avi/avs file %s\n", ARG_INPUTFILE);
1245                              AVIFileExit();
1246                              return;
1247                      }
1248    
1249                      if (AVIFileGetStream(avi_in, &avi_in_stream, streamtypeVIDEO, 0) != AVIERR_OK) {
1250                              fprintf(stderr, "Can't open stream from file '%s'!\n", ARG_INPUTFILE);
1251                              AVIFileRelease(avi_in);
1252                              AVIFileExit();
1253                              return;
1254                      }
1255    
1256                      AVIFileRelease(avi_in);
1257    
1258                      if(AVIStreamInfo(avi_in_stream, &avi_info, sizeof(AVISTREAMINFO)) != AVIERR_OK) {
1259                              fprintf(stderr, "Can't get stream info from file '%s'!\n", ARG_INPUTFILE);
1260                              AVIStreamRelease(avi_in_stream);
1261                              AVIFileExit();
1262                              return;
1263                      }
1264    
1265                  if (avi_info.fccHandler != MAKEFOURCC('Y', 'V', '1', '2')) {
1266                              LONG size;
1267                              fprintf(stderr, "Non YV12 input colorspace %c%c%c%c! Attempting conversion...\n",
1268                                      avi_info.fccHandler%256, (avi_info.fccHandler>>8)%256, (avi_info.fccHandler>>16)%256,
1269                                      (avi_info.fccHandler>>24)%256);
1270                              size = sizeof(myBitmapInfoHeader);
1271                              AVIStreamReadFormat(avi_in_stream, 0, &myBitmapInfoHeader, &size);
1272                              if (size==0)
1273                                      fprintf(stderr, "AVIStreamReadFormat read 0 bytes.\n");
1274                              else {
1275                                      fprintf(stderr, "AVIStreamReadFormat read %d bytes.\n", size);
1276                                      fprintf(stderr, "width = %d, height = %d, planes = %d\n", myBitmapInfoHeader.biWidth,
1277                                              myBitmapInfoHeader.biHeight, myBitmapInfoHeader.biPlanes);
1278                                      fprintf(stderr, "Compression = %c%c%c%c, %d\n",
1279                                              myBitmapInfoHeader.biCompression%256, (myBitmapInfoHeader.biCompression>>8)%256,
1280                                              (myBitmapInfoHeader.biCompression>>16)%256, (myBitmapInfoHeader.biCompression>>24)%256,
1281                                              myBitmapInfoHeader.biCompression);
1282                                      fprintf(stderr, "Bits Per Pixel = %d\n", myBitmapInfoHeader.biBitCount);
1283                                      myBitmapInfoHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');
1284                                      myBitmapInfoHeader.biBitCount = 12;
1285                                      myBitmapInfoHeader.biSizeImage = (myBitmapInfoHeader.biWidth*myBitmapInfoHeader.biHeight)*3/2;
1286                                      get_frame = AVIStreamGetFrameOpen(avi_in_stream, &myBitmapInfoHeader);
1287                              }
1288                              if (get_frame == NULL) {
1289                                    AVIStreamRelease(avi_in_stream);
1290                                    AVIFileExit();
1291                                    return;
1292                              }
1293                              else {
1294                                    unsigned char *temp;
1295                                    fprintf(stderr, "AVIStreamGetFrameOpen successful.\n");
1296                                    temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0);
1297                                    if (temp != NULL) {
1298                                            int i;
1299                                            for (i = 0; i < ((DWORD*)temp)[0]; i++) {
1300                                                    fprintf(stderr, "%2d ", temp[i]);
1301                                            }
1302                                            fprintf(stderr, "\n");
1303                                    }
1304                              }
1305                              if (avi_info.fccHandler == MAKEFOURCC('D', 'I', 'B', ' ')) {
1306                                      AVIStreamGetFrameClose(get_frame);
1307                                      get_frame = NULL;
1308                                      ARG_COLORSPACE = XVID_CSP_BGR | XVID_CSP_VFLIP;
1309                              }
1310                      }
1311        }
1312        else
1313    #endif
1314                    {
1315                            in_file = fopen(ARG_INPUTFILE, "rb");
1316                            if (in_file == NULL) {
1317                                    fprintf(stderr, "Error opening input file %s\n", ARG_INPUTFILE);
1318                                    return;
1319                            }
1320                    }
1321            }
1322    
1323            // This should be after the avi input opening stuff
1324            if (ARG_TIMECODEFILE != NULL) {
1325                    time_file = fopen(ARG_TIMECODEFILE, "r");
1326                    if (time_file==NULL) {
1327                            fprintf(stderr, "Couldn't open timecode file '%s'!\n", ARG_TIMECODEFILE);
1328                            return;
1329                    }
1330                    else {
1331                            fscanf(time_file, "# timecode format v2\n");
1332                    }
1333            }
1334    
1335          if (ARG_INPUTTYPE==1) {          if (ARG_INPUTTYPE==1) {
1336  #ifndef READ_PNM  #ifndef READ_PNM
1337                  if (read_pgmheader(in_file)) {                  if (read_pgmheader(in_file)) {
# Line 973  Line 1340 
1340  #endif  #endif
1341                          fprintf(stderr,                          fprintf(stderr,
1342                                          "Wrong input format, I want YUV encapsulated in PGM\n");                                          "Wrong input format, I want YUV encapsulated in PGM\n");
1343                          return (-1);                          return;
1344                  }                  }
1345          }          }
1346    
1347          /* Jump to the starting frame */          /* Jump to the starting frame */
1348          if (ARG_INPUTTYPE == 0)          if (ARG_INPUTTYPE == 0) /* TODO: Other input formats ??? */
1349                  fseek(in_file, ARG_STARTFRAMENR*IMAGE_SIZE(XDIM, YDIM), SEEK_SET);                  fseek(in_file, start_num*IMAGE_SIZE(XDIM, YDIM), SEEK_SET);
1350    
1351    
1352          /* now we know the sizes, so allocate memory */          /* now we know the sizes, so allocate memory */
1353          if (get_frame == NULL)          if (get_frame == NULL)
# Line 995  Line 1363 
1363                  goto free_all_memory;                  goto free_all_memory;
1364    
1365  /*****************************************************************************  /*****************************************************************************
1366   *                            XviD PART  Start   *                            Xvid PART  Start
1367   ****************************************************************************/   ****************************************************************************/
1368    
1369    
1370          result = enc_init(use_assembler);          result = enc_init(&enc_handle, h->statsfilename1, h->start_num);
1371          if (result) {          if (result) {
1372                  fprintf(stderr, "Encore INIT problem, return value %d\n", result);                  fprintf(stderr, "Encore INIT problem, return value %d\n", result);
1373                  goto release_all;                  goto release_all;
# Line 1011  Line 1379 
1379    
1380          if (ARG_SAVEMPEGSTREAM) {          if (ARG_SAVEMPEGSTREAM) {
1381    
1382                  if (ARG_OUTPUTFILE) {                  if (outfilename) {
1383                          if ((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) {                          if ((out_file = fopen(outfilename, "w+b")) == NULL) {
1384                                  fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE);                                  fprintf(stderr, "Error opening output file %s\n", outfilename);
1385                                  goto release_all;                                  goto release_all;
1386                          }                          }
1387                  }                  }
# Line 1109  Line 1477 
1477          result = 0;          result = 0;
1478    
1479          input_num = 0;                          /* input frame counter */          input_num = 0;                          /* input frame counter */
1480          output_num = 0;                         /* output frame counter */          output_num = start_num;             /* output frame counter */
1481    
1482          nvop_counter = 0;          nvop_counter = 0;
1483    
# Line 1118  Line 1486 
1486                  char *type;                  char *type;
1487                  int sse[3];                  int sse[3];
1488    
1489                  if (input_num >= ARG_MAXFRAMENR && ARG_MAXFRAMENR > 0) {                  if ((input_num+start_num) >= stop_num && stop_num > 0) {
1490                          result = 1;                          result = 1;
1491                  }                  }
1492    
# Line 1127  Line 1495 
1495                          if (ARG_INPUTTYPE==2) {                          if (ARG_INPUTTYPE==2) {
1496                                  /* read avs/avi data (YUV-format) */                                  /* read avs/avi data (YUV-format) */
1497                                  if (get_frame != NULL) {                                  if (get_frame != NULL) {
1498                                          in_buffer = (unsigned char*)AVIStreamGetFrame(get_frame, input_num+ARG_STARTFRAMENR);                                          in_buffer = (unsigned char*)AVIStreamGetFrame(get_frame, input_num+start_num);
1499                                          if (in_buffer == NULL)                                          if (in_buffer == NULL)
1500                                                  result = 1;                                                  result = 1;
1501                                          else                                          else
1502                                                  in_buffer += ((DWORD*)in_buffer)[0];                                                  in_buffer += ((DWORD*)in_buffer)[0];
1503                                  } else {                                  } else {
1504                                          if(AVIStreamRead(avi_stream, input_num+ARG_STARTFRAMENR, 1, in_buffer, 4*XDIM*YDIM, NULL, NULL ) != AVIERR_OK)                                          if(AVIStreamRead(avi_in_stream, input_num+start_num, 1, in_buffer, 4*XDIM*YDIM, NULL, NULL ) != AVIERR_OK)
1505                                                  result = 1;                                                  result = 1;
1506                                  }                                  }
1507                          } else                          } else
# Line 1155  Line 1523 
1523   *                       Encode and decode this frame   *                       Encode and decode this frame
1524   ****************************************************************************/   ****************************************************************************/
1525    
1526                  if (input_num >= (unsigned int)ARG_MAXFRAMENR-1 && ARG_MAXBFRAMES) {                  if ((input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) {
1527                          stats_type = XVID_TYPE_PVOP;                          stats_type = XVID_TYPE_PVOP;
1528                  }                  }
1529                  else                  else
# Line 1163  Line 1531 
1531    
1532                  enctime = msecond();                  enctime = msecond();
1533                  m4v_size =                  m4v_size =
1534                          enc_main(!result ? in_buffer : 0, mp4_buffer, &key, &stats_type,                          enc_main(enc_handle, !result ? in_buffer : 0, mp4_buffer, &key, &stats_type,
1535                                           &stats_quant, &stats_length, sse, input_num);                                           &stats_quant, &stats_length, sse, input_num);
1536                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
1537    
# Line 1191  Line 1559 
1559                          }                          }
1560    
1561                          if (stats_length > 8) {                          if (stats_length > 8) {
1562                                  framestats[stats_type].count++;                                  h->framestats[stats_type].count++;
1563                                  framestats[stats_type].quants[stats_quant]++;                                  h->framestats[stats_type].quants[stats_quant]++;
1564                                  framestats[stats_type].size += stats_length;                                  h->framestats[stats_type].size += stats_length;
1565                          }                          }
1566                          else {                          else {
1567                                  framestats[5].count++;                                  h->framestats[5].count++;
1568                                  framestats[5].quants[stats_quant]++;                                  h->framestats[5].quants[stats_quant]++;
1569                                  framestats[5].size += stats_length;                                  h->framestats[5].size += stats_length;
1570                          }                          }
1571    
1572  #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height)))))  #define SSE2PSNR(sse, width, height) ((!(sse))?0.0f : 48.131f - 10*(float)log10((float)(sse)/((float)((width)*(height)))))
1573    
1574                          if (ARG_PROGRESS == 0) {                          if (ARG_PROGRESS == 0) {
1575                                  printf("%5d: key=%i, time= %6.0f, len= %7d", !result ? input_num : -1,                                  printf("%5d: key=%i, time= %6.0f, len= %7d", !result ? (input_num+start_num) : -1,
1576                                          key, (float) enctime, (int) m4v_size);                                          key, (float) enctime, (int) m4v_size);
1577                                  printf(" | type=%s, quant= %2d, len= %7d", type, stats_quant,                                  printf(" | type=%s, quant= %2d, len= %7d", type, stats_quant,
1578                                     stats_length);                                     stats_length);
# Line 1217  Line 1585 
1585                                  }                                  }
1586                                  printf("\n");                                  printf("\n");
1587                          } else {                          } else {
1588                                  if (input_num % ARG_PROGRESS == 1) {                                  if ((input_num) % ARG_PROGRESS == 1) {
1589                                          if (ARG_MAXFRAMENR > 0) {                                          if (stop_num > 0) {
1590                                                  fprintf(stderr, "\r%7d frames(%3d%%) encoded, %6.2f fps, Average Bitrate = %5.0fkbps", \                                                  fprintf(stderr, "\r%7d frames(%3d%%) encoded, %6.2f fps, Average Bitrate = %5.0fkbps", \
1591                                                          input_num, input_num*100/ARG_MAXFRAMENR, input_num*1000/totalenctime, \                                                          (ARG_NUM_APP_THREADS*input_num), (input_num)*100/(stop_num-start_num), (ARG_NUM_APP_THREADS*input_num)*1000/(totalenctime), \
1592                                                          (((totalsize/1000)*ARG_FRAMERATE)*8)/input_num);                                                          ((((totalsize)/1000)*ARG_FRAMERATE)*8)/(input_num));
1593                                          } else {                                          } else {
1594                                                  fprintf(stderr, "\r%7d frames encoded, %6.2f fps, Average Bitrate = %5.0fkbps", \                                                  fprintf(stderr, "\r%7d frames encoded, %6.2f fps, Average Bitrate = %5.0fkbps", \
1595                                                          input_num, input_num*1000/totalenctime, \                                                          (ARG_NUM_APP_THREADS*input_num), (ARG_NUM_APP_THREADS*input_num)*1000/(totalenctime), \
1596                                                          (((totalsize/1000)*ARG_FRAMERATE)*8)/input_num);                                                          ((((totalsize)/1000)*ARG_FRAMERATE)*8)/(input_num));
1597                                          }                                          }
1598                                  }                                  }
1599                          }                          }
# Line 1289  Line 1657 
1657                                          removedivxp((char*)mp4_buffer, m4v_size);                                          removedivxp((char*)mp4_buffer, m4v_size);
1658    
1659                                  /* Save ES stream */                                  /* Save ES stream */
1660                                  if (ARG_OUTPUTFILE && out_file && !(fakenvop && m4v_size <= 8)) {                                  if (outfilename && out_file && !(fakenvop && m4v_size <= 8)) {
1661                                                  fwrite(mp4_buffer, 1, m4v_size, out_file);                                                  fwrite(mp4_buffer, 1, m4v_size, out_file);
1662                                  }                                  }
1663  #ifdef XVID_MKV_OUTPUT  #ifdef XVID_MKV_OUTPUT
# Line 1303  Line 1671 
1671                                  fakenvop=0;                                  fakenvop=0;
1672                  }                  }
1673    
1674                  input_num++;                  if (!result)
1675                            (input_num)++;
1676    
1677                  /* Read the header if it's pgm stream */                  /* Read the header if it's pgm stream */
1678                  if (!result && (ARG_INPUTTYPE==1))                  if (!result && (ARG_INPUTTYPE==1))
# Line 1315  Line 1684 
1684          } while (1);          } while (1);
1685    
1686    
   
 /*****************************************************************************  
  *         Calculate totals and averages for output, print results  
  ****************************************************************************/  
   
  printf("\n");  
         printf("Tot: enctime(ms) =%7.2f,               length(bytes) = %7d\n",  
                    totalenctime, (int) totalsize);  
   
         if (input_num > 0) {  
                 totalsize /= input_num;  
                 totalenctime /= input_num;  
                 totalPSNR[0] /= input_num;  
                 totalPSNR[1] /= input_num;  
                 totalPSNR[2] /= input_num;  
         } else {  
                 totalsize = -1;  
                 totalenctime = -1;  
         }  
   
         printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d",  
                    totalenctime, 1000 / totalenctime, (int) totalsize);  
    if (ARG_STATS) {  
        printf(", psnr y = %2.2f, psnr u = %2.2f, psnr v = %2.2f",  
                   totalPSNR[0],totalPSNR[1],totalPSNR[2]);  
         }  
         printf("\n");  
         if (framestats[XVID_TYPE_IVOP].count) {  
                 printf("I frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \  
                         framestats[XVID_TYPE_IVOP].count, framestats[XVID_TYPE_IVOP].size/framestats[XVID_TYPE_IVOP].count, \  
                         framestats[XVID_TYPE_IVOP].size, minquant(framestats[XVID_TYPE_IVOP].quants), \  
                         avgquant(framestats[XVID_TYPE_IVOP]), maxquant(framestats[XVID_TYPE_IVOP].quants));  
         }  
         if (framestats[XVID_TYPE_PVOP].count) {  
                 printf("P frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \  
                         framestats[XVID_TYPE_PVOP].count, framestats[XVID_TYPE_PVOP].size/framestats[XVID_TYPE_PVOP].count, \  
                         framestats[XVID_TYPE_PVOP].size, minquant(framestats[XVID_TYPE_PVOP].quants), \  
                         avgquant(framestats[XVID_TYPE_PVOP]), maxquant(framestats[XVID_TYPE_PVOP].quants));  
         }  
         if (framestats[XVID_TYPE_BVOP].count) {  
                 printf("B frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \  
                         framestats[XVID_TYPE_BVOP].count, framestats[XVID_TYPE_BVOP].size/framestats[XVID_TYPE_BVOP].count, \  
                         framestats[XVID_TYPE_BVOP].size, minquant(framestats[XVID_TYPE_BVOP].quants), \  
                         avgquant(framestats[XVID_TYPE_BVOP]), maxquant(framestats[XVID_TYPE_BVOP].quants));  
         }  
         if (framestats[XVID_TYPE_SVOP].count) {  
                 printf("S frames: %6d frames, size = %7d/%7d, quants = %2d / %.2f / %2d\n", \  
                         framestats[XVID_TYPE_SVOP].count, framestats[XVID_TYPE_SVOP].size/framestats[XVID_TYPE_SVOP].count, \  
                         framestats[XVID_TYPE_SVOP].size, minquant(framestats[XVID_TYPE_SVOP].quants), \  
                         avgquant(framestats[XVID_TYPE_SVOP]), maxquant(framestats[XVID_TYPE_SVOP].quants));  
         }  
         if (framestats[5].count) {  
                 printf("N frames: %6d frames, size = %7d/%7d\n", \  
                         framestats[5].count, framestats[5].size/framestats[5].count, \  
                         framestats[5].size);  
         }  
   
   
 /*****************************************************************************  
  *                            XviD PART  Stop  
  ****************************************************************************/  
   
1687    release_all:    release_all:
1688    
1689      h->input_num = input_num;
1690      h->totalenctime = totalenctime;
1691      h->totalsize = totalsize;
1692    
1693  #ifdef XVID_AVI_INPUT  #ifdef XVID_AVI_INPUT
1694          if (get_frame) AVIStreamGetFrameClose(get_frame);          if (get_frame) AVIStreamGetFrameClose(get_frame);
1695          if (avi_stream) AVIStreamRelease(avi_stream);          if (avi_in_stream) AVIStreamRelease(avi_in_stream);
 #ifndef XVID_AVI_OUTPUT  
         AVIFileExit();  
 #endif  
1696  #endif  #endif
1697    
1698          if (enc_handle) {          if (enc_handle) {
1699                  result = enc_stop();                  result = enc_stop(enc_handle);
1700                  if (result)                  if (result)
1701                          fprintf(stderr, "Encore RELEASE problem return value %d\n",                          fprintf(stderr, "Encore RELEASE problem return value %d\n",
1702                                          result);                                          result);
# Line 1398  Line 1706 
1706                  fclose(in_file);                  fclose(in_file);
1707          if (out_file)          if (out_file)
1708                  fclose(out_file);                  fclose(out_file);
1709            if (time_file)
1710                    fclose(time_file);
1711    
1712  #ifdef XVID_AVI_OUTPUT  #ifdef XVID_AVI_OUTPUT
1713          if (myAVIStream) AVIStreamRelease(myAVIStream);          if (myAVIStream) AVIStreamRelease(myAVIStream);
1714          if (myAVIFile) AVIFileRelease(myAVIFile);          if (myAVIFile) AVIFileRelease(myAVIFile);
         AVIFileExit();  
1715  #endif  #endif
1716  #ifdef XVID_MKV_OUTPUT  #ifdef XVID_MKV_OUTPUT
1717          if (myMKVStream) MKVStreamRelease(myMKVStream);          if (myMKVStream) MKVStreamRelease(myMKVStream);
1718          if (myMKVFile) MKVFileRelease(myMKVFile);          if (myMKVFile) MKVFileRelease(myMKVFile);
1719  #endif  #endif
1720    #if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT)
1721            AVIFileExit();
1722    #endif
1723    
1724    free_all_memory:    free_all_memory:
1725          free(out_buffer);          free(out_buffer);
1726          free(mp4_buffer);          free(mp4_buffer);
1727          free(in_buffer);          free(in_buffer);
   
         return (0);  
   
1728  }  }
1729    
   
1730  /*****************************************************************************  /*****************************************************************************
1731   *                        "statistical" functions   *                        "statistical" functions
1732   *   *
1733   *  these are not needed for encoding or decoding, but for measuring   *  these are not needed for encoding or decoding, but for measuring
1734   *  time and quality, there in nothing specific to XviD in these   *  time and quality, there in nothing specific to Xvid in these
1735   *   *
1736   *****************************************************************************/   *****************************************************************************/
1737    
# Line 1509  Line 1817 
1817  #endif  #endif
1818          fprintf(stderr, " -w      integer: frame width ([1.2048])\n");          fprintf(stderr, " -w      integer: frame width ([1.2048])\n");
1819          fprintf(stderr, " -h      integer: frame height ([1.2048])\n");          fprintf(stderr, " -h      integer: frame height ([1.2048])\n");
1820            fprintf(stderr, " -csp    string : colorspace of raw input file i420, yv12 (default)\n");
1821          fprintf(stderr, " -frames integer: number of frames to encode\n");          fprintf(stderr, " -frames integer: number of frames to encode\n");
1822          fprintf(stderr, "\n");          fprintf(stderr, "\n");
1823          fprintf(stderr, "Output options:\n");          fprintf(stderr, "Output options:\n");
# Line 1552  Line 1861 
1861          fprintf(stderr, "-odegrade   integer             : max overflow degradation (5)\n");          fprintf(stderr, "-odegrade   integer             : max overflow degradation (5)\n");
1862          fprintf(stderr, "-chigh      integer             : high bitrate scenes degradation (0)\n");          fprintf(stderr, "-chigh      integer             : high bitrate scenes degradation (0)\n");
1863          fprintf(stderr, "-clow       integer             : low bitrate scenes improvement (0)\n");          fprintf(stderr, "-clow       integer             : low bitrate scenes improvement (0)\n");
1864          fprintf(stderr, "-overhead   integer             : container frame overhead (24)\n");          fprintf(stderr, "-overhead   integer             : container frame overhead (0)\n");
1865          fprintf(stderr, "-vbvsize    integer             : use vbv buffer size\n");          fprintf(stderr, "-vbvsize    integer             : use vbv buffer size\n");
1866          fprintf(stderr, "-vbvmax     integer             : vbv max bitrate\n");          fprintf(stderr, "-vbvmax     integer             : vbv max bitrate\n");
1867          fprintf(stderr, "-vbvpeak    integer             : vbv peak bitrate over 1 second\n");          fprintf(stderr, "-vbvpeak    integer             : vbv peak bitrate over 1 second\n");
# Line 1563  Line 1872 
1872          fprintf(stderr, " -quality integer               : quality ([0..%d]) (6)\n", ME_ELEMENTS - 1);          fprintf(stderr, " -quality integer               : quality ([0..%d]) (6)\n", ME_ELEMENTS - 1);
1873          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");
1874          fprintf(stderr, " -bvhq                          : use R-D optimizations for B-frames\n");          fprintf(stderr, " -bvhq                          : use R-D optimizations for B-frames\n");
1875            fprintf(stderr, " -metric integer                : distortion metric for R-D opt (PSNR:0, PSNRHVSM: 1)\n");
1876          fprintf(stderr, " -qpel                          : use quarter pixel ME\n");          fprintf(stderr, " -qpel                          : use quarter pixel ME\n");
1877          fprintf(stderr, " -gmc                           : use global motion compensation\n");          fprintf(stderr, " -gmc                           : use global motion compensation\n");
1878          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 1570  Line 1880 
1880          fprintf(stderr, " -interlaced [integer]          : interlaced encoding (BFF:1, TFF:2) (1)\n");          fprintf(stderr, " -interlaced [integer]          : interlaced encoding (BFF:1, TFF:2) (1)\n");
1881          fprintf(stderr, " -nopacked                      : Disable packed mode\n");          fprintf(stderr, " -nopacked                      : Disable packed mode\n");
1882          fprintf(stderr, " -noclosed_gop                  : Disable closed GOP mode\n");          fprintf(stderr, " -noclosed_gop                  : Disable closed GOP mode\n");
1883          fprintf(stderr, " -lumimasking                   : use lumimasking algorithm\n");          fprintf(stderr, " -masking [integer]             : HVS masking mode (None:0, Lumi:1, Variance:2) (0)\n");
1884          fprintf(stderr, " -stats                         : print stats about encoded frames\n");          fprintf(stderr, " -stats                         : print stats about encoded frames\n");
1885          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");
1886          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");
1887            fprintf(stderr, " -psnrhvsm                      : prints PSNRHVSM metric for every frame\n");
1888          fprintf(stderr, " -debug                         : activates xvidcore internal debugging output\n");          fprintf(stderr, " -debug                         : activates xvidcore internal debugging output\n");
1889          fprintf(stderr, " -vop_debug                     : print some info directly into encoded frames\n");          fprintf(stderr, " -vop_debug                     : print some info directly into encoded frames\n");
1890          fprintf(stderr, " -nochromame                    : Disable chroma motion estimation\n");          fprintf(stderr, " -nochromame                    : Disable chroma motion estimation\n");
# Line 1604  Line 1915 
1915   *                       Input and output functions   *                       Input and output functions
1916   *   *
1917   *      the are small and simple routines to read and write PGM and YUV   *      the are small and simple routines to read and write PGM and YUV
1918   *      image. It's just for convenience, again nothing specific to XviD   *      image. It's just for convenience, again nothing specific to Xvid
1919   *   *
1920   *****************************************************************************/   *****************************************************************************/
1921    
# Line 1766  Line 2077 
2077    
2078  #define FRAMERATE_INCR 1001  #define FRAMERATE_INCR 1001
2079    
2080    /* Gobal encoder init, once per process */
2081  /* Initialize encoder for first use, pass all needed parameters to the codec */  void
2082  static int  enc_gbl(int use_assembler)
 enc_init(int use_assembler)  
2083  {  {
         int xerr;  
         //xvid_plugin_cbr_t cbr;  
     xvid_plugin_single_t single;  
         xvid_plugin_2pass1_t rc2pass1;  
         xvid_plugin_2pass2_t rc2pass2;  
         xvid_plugin_ssim_t ssim;  
         //xvid_plugin_fixed_t rcfixed;  
         xvid_enc_plugin_t plugins[8];  
2084          xvid_gbl_init_t xvid_gbl_init;          xvid_gbl_init_t xvid_gbl_init;
         xvid_enc_create_t xvid_enc_create;  
         int i;  
2085    
2086          /*------------------------------------------------------------------------          /*------------------------------------------------------------------------
2087           * XviD core initialization           * Xvid core initialization
2088           *----------------------------------------------------------------------*/           *----------------------------------------------------------------------*/
2089    
2090          /* Set version -- version checking will done by xvidcore */          /* Set version -- version checking will done by xvidcore */
# Line 1805  Line 2105 
2105                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;                  xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
2106          }          }
2107    
2108          /* Initialize XviD core -- Should be done once per __process__ */          /* Initialize Xvid core -- Should be done once per __process__ */
2109          xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);          xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
2110        ARG_CPU_FLAGS = xvid_gbl_init.cpu_flags;
2111          enc_info();          enc_info();
2112    }
2113    
2114    /* Initialize encoder for first use, pass all needed parameters to the codec */
2115    static int
2116    enc_init(void **enc_handle, char *stats_pass1, int start_num)
2117    {
2118            int xerr;
2119            //xvid_plugin_cbr_t cbr;
2120        xvid_plugin_single_t single;
2121            xvid_plugin_2pass1_t rc2pass1;
2122            xvid_plugin_2pass2_t rc2pass2;
2123            xvid_plugin_ssim_t ssim;
2124        xvid_plugin_lumimasking_t masking;
2125            //xvid_plugin_fixed_t rcfixed;
2126            xvid_enc_plugin_t plugins[8];
2127            xvid_enc_create_t xvid_enc_create;
2128            int i;
2129    
2130          /*------------------------------------------------------------------------          /*------------------------------------------------------------------------
2131           * XviD encoder initialization           * Xvid encoder initialization
2132           *----------------------------------------------------------------------*/           *----------------------------------------------------------------------*/
2133    
2134          /* Version again */          /* Version again */
# Line 1865  Line 2183 
2183                  rc2pass2.vbv_size     =  ARG_VBVSIZE;                  rc2pass2.vbv_size     =  ARG_VBVSIZE;
2184                  rc2pass2.vbv_initial  =  (ARG_VBVSIZE*3)/4;                  rc2pass2.vbv_initial  =  (ARG_VBVSIZE*3)/4;
2185                  rc2pass2.vbv_maxrate  =  ARG_VBVMAXRATE;                  rc2pass2.vbv_maxrate  =  ARG_VBVMAXRATE;
2186                  rc2pass2.vbv_peakrate =  ARG_VBVPEAKRATE*3;                  rc2pass2.vbv_peakrate =  ARG_VBVPEAKRATE;
2187    
2188    
2189                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
# Line 1873  Line 2191 
2191                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
2192          }          }
2193    
2194          if (ARG_PASS1) {          if (stats_pass1) {
2195                  memset(&rc2pass1, 0, sizeof(xvid_plugin_2pass1_t));                  memset(&rc2pass1, 0, sizeof(xvid_plugin_2pass1_t));
2196                  rc2pass1.version = XVID_VERSION;                  rc2pass1.version = XVID_VERSION;
2197                  rc2pass1.filename = ARG_PASS1;                  rc2pass1.filename = stats_pass1;
2198                  if (ARG_FULL1PASS)                  if (ARG_FULL1PASS)
2199                          prepare_full1pass_zones();                          prepare_full1pass_zones();
2200                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass1;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass1;
# Line 1896  Line 2214 
2214    
2215    
2216          if (ARG_LUMIMASKING) {          if (ARG_LUMIMASKING) {
2217                    memset(&masking, 0, sizeof(xvid_plugin_lumimasking_t));
2218                    masking.method = (ARG_LUMIMASKING==2);
2219                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
2220                  plugins[xvid_enc_create.num_plugins].param = NULL;                  plugins[xvid_enc_create.num_plugins].param = &masking;
2221                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
2222          }          }
2223    
# Line 1908  Line 2228 
2228          }          }
2229    
2230          if (ARG_SSIM>=0 || ARG_SSIM_PATH != NULL) {          if (ARG_SSIM>=0 || ARG_SSIM_PATH != NULL) {
2231            memset(&ssim, 0, sizeof(xvid_plugin_ssim_t));
2232    
2233                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim;                  plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim;
2234    
2235                    if( ARG_SSIM >=0){
2236                  ssim.b_printstat = 1;                  ssim.b_printstat = 1;
2237                            ssim.acc = ARG_SSIM;
2238                    } else {
2239                            ssim.b_printstat = 0;
2240                            ssim.acc = 2;
2241                    }
2242    
2243                    if(ARG_SSIM_PATH != NULL){
2244                  ssim.stat_path = ARG_SSIM_PATH;                  ssim.stat_path = ARG_SSIM_PATH;
2245                    }
2246    
2247            ssim.cpu_flags = ARG_CPU_FLAGS;
2248                  ssim.b_visualize = 0;                  ssim.b_visualize = 0;
                 ssim.acc = (ARG_SSIM_PATH != NULL && ARG_SSIM < 0) ? 2 : ARG_SSIM;  
2249                  plugins[xvid_enc_create.num_plugins].param = &ssim;                  plugins[xvid_enc_create.num_plugins].param = &ssim;
2250                  xvid_enc_create.num_plugins++;                  xvid_enc_create.num_plugins++;
2251          }          }
2252    
2253            if (ARG_PSNRHVSM>0) {
2254            plugins[xvid_enc_create.num_plugins].func = xvid_plugin_psnrhvsm;
2255                    plugins[xvid_enc_create.num_plugins].param = NULL;
2256                    xvid_enc_create.num_plugins++;
2257            }
2258    
2259  #if 0  #if 0
2260          if (ARG_DEBUG) {          if (ARG_DEBUG) {
2261                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;                  plugins[xvid_enc_create.num_plugins].func = rawenc_debug;
# Line 1953  Line 2292 
2292          /* Frame drop ratio */          /* Frame drop ratio */
2293          xvid_enc_create.frame_drop_ratio = ARG_FRAMEDROP;          xvid_enc_create.frame_drop_ratio = ARG_FRAMEDROP;
2294    
2295            /* Start frame number */
2296            xvid_enc_create.start_frame_num = start_num;
2297    
2298          /* Global encoder options */          /* Global encoder options */
2299          xvid_enc_create.global = 0;          xvid_enc_create.global = 0;
2300    
# Line 1969  Line 2311 
2311          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);          xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
2312    
2313          /* Retrieve the encoder instance from the structure */          /* Retrieve the encoder instance from the structure */
2314          enc_handle = xvid_enc_create.handle;          *enc_handle = xvid_enc_create.handle;
2315    
2316          free(xvid_enc_create.zones);          free(xvid_enc_create.zones);
2317    
# Line 2000  Line 2342 
2342                  fprintf(stderr, "SSE ");                  fprintf(stderr, "SSE ");
2343          if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE2)          if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE2)
2344                  fprintf(stderr, "SSE2 ");                  fprintf(stderr, "SSE2 ");
2345            if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE3)
2346                    fprintf(stderr, "SSE3 ");
2347            if (xvid_gbl_info.cpu_flags & XVID_CPU_SSE41)
2348                    fprintf(stderr, "SSE41 ");
2349          if (xvid_gbl_info.cpu_flags & XVID_CPU_3DNOW)          if (xvid_gbl_info.cpu_flags & XVID_CPU_3DNOW)
2350                  fprintf(stderr, "3DNOW ");                  fprintf(stderr, "3DNOW ");
2351          if (xvid_gbl_info.cpu_flags & XVID_CPU_3DNOWEXT)          if (xvid_gbl_info.cpu_flags & XVID_CPU_3DNOWEXT)
# Line 2008  Line 2354 
2354                  fprintf(stderr, "TSC ");                  fprintf(stderr, "TSC ");
2355          fprintf(stderr, "\n");          fprintf(stderr, "\n");
2356          fprintf(stderr, "Detected %d cpus,", xvid_gbl_info.num_threads);          fprintf(stderr, "Detected %d cpus,", xvid_gbl_info.num_threads);
2357          if (!ARG_THREADS)          ARG_NUM_APP_THREADS = xvid_gbl_info.num_threads;
2358                  ARG_THREADS = xvid_gbl_info.num_threads;          fprintf(stderr, " using %d threads.\n", (!ARG_THREADS) ? ARG_NUM_APP_THREADS : ARG_THREADS);
         fprintf(stderr, " using %d threads.\n", ARG_THREADS);  
2359          return ret;          return ret;
2360  }  }
2361    
2362  static int  static int
2363  enc_stop()  enc_stop(void *enc_handle)
2364  {  {
2365          int xerr;          int xerr;
2366    
# Line 2026  Line 2371 
2371  }  }
2372    
2373  static int  static int
2374  enc_main(unsigned char *image,  enc_main(void *enc_handle,
2375                     unsigned char *image,
2376                   unsigned char *bitstream,                   unsigned char *bitstream,
2377                   int *key,                   int *key,
2378                   int *stats_type,                   int *stats_type,
# Line 2055  Line 2401 
2401          if (image) {          if (image) {
2402                  xvid_enc_frame.input.plane[0] = image;                  xvid_enc_frame.input.plane[0] = image;
2403  #ifndef READ_PNM  #ifndef READ_PNM
                 if (ARG_INPUTTYPE==2)  
2404                          xvid_enc_frame.input.csp = ARG_COLORSPACE;                          xvid_enc_frame.input.csp = ARG_COLORSPACE;
                 else  
                         xvid_enc_frame.input.csp = XVID_CSP_I420;  
2405                  xvid_enc_frame.input.stride[0] = XDIM;                  xvid_enc_frame.input.stride[0] = XDIM;
2406  #else  #else
2407                  xvid_enc_frame.input.csp = XVID_CSP_BGR;                  xvid_enc_frame.input.csp = XVID_CSP_BGR;
# Line 2144  Line 2487 
2487          if (ARG_BVHQ)          if (ARG_BVHQ)
2488                  xvid_enc_frame.vop_flags |= XVID_VOP_RD_BVOP;                  xvid_enc_frame.vop_flags |= XVID_VOP_RD_BVOP;
2489    
2490            if (ARG_QMETRIC == 1)
2491                    xvid_enc_frame.vop_flags |= XVID_VOP_RD_PSNRHVSM;
2492    
2493          switch (ARG_VHQMODE) /* this is the same code as for vfw */          switch (ARG_VHQMODE) /* this is the same code as for vfw */
2494          {          {
2495          case 1: /* VHQ_MODE_DECISION */          case 1: /* VHQ_MODE_DECISION */

Legend:
Removed from v.1757  
changed lines
  Added in v.1909

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