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

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

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

revision 793, Sun Jan 19 12:03:16 2003 UTC revision 794, Sun Jan 19 15:10:11 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Console based test application  -   *  - Console based test application  -
5   *   *
6   *  Copyright(C) 2002 Christoph Lampert   *  Copyright(C) 2002-2003 Christoph Lampert
7   *   *
8   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
9   *  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 19  Line 19 
19   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: xvid_encraw.c,v 1.1.2.2 2003-01-13 00:36:27 edgomez Exp $   * $Id: xvid_encraw.c,v 1.1.2.3 2003-01-19 15:10:11 edgomez Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 96  Line 96 
96  static char *ARG_INPUTFILE = NULL;  static char *ARG_INPUTFILE = NULL;
97  static int   ARG_INPUTTYPE = 0;  static int   ARG_INPUTTYPE = 0;
98  static int   ARG_SAVEMPEGSTREAM = 0;  static int   ARG_SAVEMPEGSTREAM = 0;
 static int   ARG_OUTPUTTYPE = 0;  
99  static char *ARG_OUTPUTFILE = NULL;  static char *ARG_OUTPUTFILE = NULL;
100  static int   ARG_HINTMODE = HINT_MODE_NONE;  static int   ARG_HINTMODE = HINT_MODE_NONE;
101  static int   XDIM = 0;  static int   XDIM = 0;
102  static int   YDIM = 0;  static int   YDIM = 0;
103  static int   ARG_BQRATIO = 150;  static int   ARG_BQRATIO = 120;
104  static int   ARG_BQOFFSET = 100;  static int   ARG_BQOFFSET = 0;
105  static int   ARG_MAXBFRAMES = 0;  static int   ARG_MAXBFRAMES = 0;
106  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)  #define IMAGE_SIZE(x,y) ((x)*(y)*3/2)
107    
108  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )  #define MAX(A,B) ( ((A)>(B)) ? (A) : (B) )
109  #define SMALL_EPS 1e-10  #define SMALL_EPS 1e-10
110    
 #define LONG_PACK(a,b,c,d) ((long) (((long)(a))<<24) | (((long)(b))<<16) | \  
                                    (((long)(c))<<8)  |((long)(d)))  
   
111  #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \  #define SWAP(a) ( (((a)&0x000000ff)<<24) | (((a)&0x0000ff00)<<8) | \
112                    (((a)&0x00ff0000)>>8)  | (((a)&0xff000000)>>24) )                    (((a)&0x00ff0000)>>8)  | (((a)&0xff000000)>>24) )
113    
# Line 180  Line 176 
176          FILE *hints_file = NULL;          FILE *hints_file = NULL;
177    
178          printf("xvid_encraw - raw mpeg4 bitstream encoder ");          printf("xvid_encraw - raw mpeg4 bitstream encoder ");
179          printf("written by Christoph Lampert 2002\n\n");          printf("written by Christoph Lampert 2002-2003\n\n");
180    
181  /*****************************************************************************  /*****************************************************************************
182   *                            Command line parsing   *                            Command line parsing
# Line 243  Line 239 
239                          i++;                          i++;
240                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);                          ARG_SAVEMPEGSTREAM = atoi(argv[i]);
241                  }                  }
                 else if (strcmp("-mt", argv[i]) == 0 && i < argc - 1 ) {  
                         i++;  
                         ARG_OUTPUTTYPE = atoi(argv[i]);  
                 }  
242                  else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) {                  else if (strcmp("-mv", argv[i]) == 0 && i < argc - 1 ) {
243                          i++;                          i++;
244                          ARG_HINTMODE = atoi(argv[i]);                          ARG_HINTMODE = atoi(argv[i]);
# Line 346  Line 338 
338          }          }
339    
340          /* now we know the sizes, so allocate memory */          /* now we know the sizes, so allocate memory */
   
341          in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM));          in_buffer = (unsigned char *) malloc(IMAGE_SIZE(XDIM,YDIM));
342          if (!in_buffer)          if (!in_buffer)
343                  goto free_all_memory;                  goto free_all_memory;
# Line 372  Line 363 
363   *                            Main loop   *                            Main loop
364   ****************************************************************************/   ****************************************************************************/
365    
366          totalsize = LONG_PACK('M','P','4','U');          if (ARG_SAVEMPEGSTREAM && ARG_OUTPUTFILE) {
         if(*((char *)(&totalsize)) == 'M')  
                 bigendian = 1;  
         else  
                 bigendian = 0;  
   
         if (ARG_SAVEMPEGSTREAM && (ARG_OUTPUTTYPE || ARG_OUTPUTFILE)) {  
   
                 if (ARG_OUTPUTFILE == NULL && ARG_OUTPUTTYPE)  
                         ARG_OUTPUTFILE = "stream.mp4u";  
                 else if(ARG_OUTPUTFILE == NULL && !ARG_OUTPUTTYPE)  
                         ARG_OUTPUTFILE = "stream.m4v";  
367    
368                  if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) {                  if((out_file = fopen(ARG_OUTPUTFILE, "w+b")) == NULL) {
369                          fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE);                          fprintf(stderr, "Error opening output file %s\n", ARG_OUTPUTFILE);
370                          goto release_all;                          goto release_all;
371                  }                  }
372    
                 /* Write header */  
                 if (ARG_OUTPUTTYPE) {  
   
                         long test = LONG_PACK('M','P','4','U');  
   
                         test = (!bigendian)?SWAP(test):test;  
   
                         fwrite(&test, sizeof(test), 1, out_file);  
   
                 }  
   
373          }          }
374          else {          else {
375                  out_file = NULL;                  out_file = NULL;
# Line 444  Line 413 
413                                                    &m4v_size, &frame_type, &hints_size);                                                    &m4v_size, &frame_type, &hints_size);
414                  enctime = msecond() - enctime;                  enctime = msecond() - enctime;
415    
416                  totalenctime += enctime;                  /* if it's a not coded VOP (aka NVOP) then we write nothing */
417                  totalsize += m4v_size;                  if(frame_type == 5) goto next_frame;
418    
419                  {                  {
420                          char *type;                          char *type[] = {"P", "I", "B", "S", "Packed", "N", "Unknown"};
421    
422                          switch(frame_type) {                          if(frame_type<0 || frame_type>5) frame_type = 6;
                         case 0: type = "P"; break;  
                         case 1: type = "I"; break;  
                         case 2: type = "B"; break;  
                         default: type = "N"; break;  
                         }  
423    
424                          printf("Frame %5d: type %s, enctime=%6.1f ms, size=%6d bytes\n",                          printf("Frame %5d: type = %s, enctime(ms) =%6.1f, length(bytes) =%7d\n",
425                                     (int)filenr, type, (float)enctime, (int)m4v_size);                                     (int)filenr, type[frame_type], (float)enctime, (int)m4v_size);
426    
427                  }                  }
428    
429                    /* Update encoding time stats */
430                    totalenctime += enctime;
431                    totalsize += m4v_size;
432    
433  /*****************************************************************************  /*****************************************************************************
434   *                       Save hints to file   *                       Save hints to file
435   ****************************************************************************/   ****************************************************************************/
# Line 488  Line 456 
456                                  out_file = NULL;                                  out_file = NULL;
457                          }                          }
458                          else {                          else {
                                 /* Using mp4u container */  
                                 if (ARG_OUTPUTTYPE) {  
                                         long size = m4v_size;  
                                         size = (!bigendian)?SWAP(size):size;  
                                         fwrite(&size, sizeof(size), 1, out_file);  
                                 }  
459    
460                                  /* Write mp4 data */                                  /* Write mp4 data */
461                                  fwrite(mp4_buffer, m4v_size, 1, out_file);                                  fwrite(mp4_buffer, 1, m4v_size, out_file);
462    
463                          }                          }
464                  }                  }
465    
466            next_frame:
467                  /* Read the header if it's pgm stream */                  /* Read the header if it's pgm stream */
468                  if (ARG_INPUTTYPE)                  if (ARG_INPUTTYPE)
469                          status = read_pgmheader(in_file);                          status = read_pgmheader(in_file);
470    
471                  filenr++;                  if(frame_type != 5) filenr++;
472    
473          } while ( (!status) && (filenr<ARG_MAXFRAMENR) );          } while ( (!status) && (filenr<ARG_MAXFRAMENR) );
474    
# Line 518  Line 481 
481          totalsize    /= filenr;          totalsize    /= filenr;
482          totalenctime /= filenr;          totalenctime /= filenr;
483    
484          printf("Avg: enctime %5.2f ms, %5.2f fps, size %7d bytes\n",          printf("Avg: enctime(ms) =%7.2f, fps =%7.2f, length(bytes) = %7d\n",
485                     totalenctime, 1000/totalenctime, (int)totalsize);                     totalenctime, 1000/totalenctime, (int)totalsize);
486    
487  /*****************************************************************************  /*****************************************************************************
# Line 599  Line 562 
562          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");          fprintf(stderr, " -m boolean     : save mpeg4 raw stream (0 False*, !=0 True)\n");
563          fprintf(stderr, " -o string      : output container filename (only usefull when -m 1 is used) :\n");          fprintf(stderr, " -o string      : output container filename (only usefull when -m 1 is used) :\n");
564          fprintf(stderr, "                  When this option is not used : one file per encoded frame\n");          fprintf(stderr, "                  When this option is not used : one file per encoded frame\n");
565          fprintf(stderr, "                  When this option is used :\n");          fprintf(stderr, "                  When this option is used : save to 'string' (default=stream.m4v)\n");
         fprintf(stderr, "                    + stream.m4v with -mt 0\n");  
         fprintf(stderr, "                    + stream.mp4u with -mt 1\n");  
566          fprintf(stderr, " -mt integer    : output type (m4v=0, mp4u=1)\n");          fprintf(stderr, " -mt integer    : output type (m4v=0, mp4u=1)\n");
567          fprintf(stderr, " -mv integer    : Use motion vector hints (no hints=0, get hints=1, set hints=2)\n");          fprintf(stderr, " -mv integer    : Use motion vector hints (no hints=0, get hints=1, set hints=2)\n");
568          fprintf(stderr, " -help          : prints this help message\n");          fprintf(stderr, " -help          : prints this help message\n");

Legend:
Removed from v.793  
changed lines
  Added in v.794

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