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-2003 Christoph Lampert |
* Copyright(C) 2002-2003 Christoph Lampert <gruel@web.de> |
7 |
|
* 2002-2003 Edouard Gomez <ed.gomez@free.fr> |
8 |
|
* 2003 Peter Ross <pross@xvid.org> |
9 |
* |
* |
10 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
11 |
* 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 |
21 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: xvid_encraw.c,v 1.11.2.22 2003-05-14 11:53:16 suxen_drol Exp $ |
* $Id: xvid_encraw.c,v 1.11.2.27 2003-06-09 13:49:25 edgomez Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
34 |
* The program is plain C and needs no libraries except for libxvidcore, |
* The program is plain C and needs no libraries except for libxvidcore, |
35 |
* and maths-lib. |
* and maths-lib. |
36 |
* |
* |
37 |
|
* Use ./xvid_encraw -help for a list of options |
38 |
|
* |
39 |
************************************************************************/ |
************************************************************************/ |
40 |
|
|
41 |
#include <stdio.h> |
#include <stdio.h> |
91 |
0, |
0, |
92 |
|
|
93 |
/* quality 1 */ |
/* quality 1 */ |
94 |
XVID_VOP_DYNAMIC_BFRAMES, |
0, |
95 |
|
|
96 |
/* quality 2 */ |
/* quality 2 */ |
97 |
XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL, |
XVID_VOP_HALFPEL, |
98 |
|
|
99 |
/* quality 3 */ |
/* quality 3 */ |
100 |
XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | |
XVID_VOP_HALFPEL | XVID_VOP_INTER4V, |
|
XVID_VOP_INTER4V, |
|
101 |
|
|
102 |
/* quality 4 */ |
/* quality 4 */ |
103 |
XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | |
XVID_VOP_HALFPEL | XVID_VOP_INTER4V, |
|
XVID_VOP_INTER4V, |
|
104 |
|
|
105 |
/* quality 5 */ |
/* quality 5 */ |
106 |
XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | |
XVID_VOP_HALFPEL | XVID_VOP_INTER4V | |
107 |
XVID_VOP_INTER4V | XVID_VOP_TRELLISQUANT, |
XVID_VOP_TRELLISQUANT, |
108 |
|
|
109 |
/* quality 6 */ |
/* quality 6 */ |
110 |
XVID_VOP_DYNAMIC_BFRAMES | XVID_VOP_HALFPEL | |
XVID_VOP_HALFPEL | XVID_VOP_INTER4V | |
111 |
XVID_VOP_INTER4V | XVID_VOP_TRELLISQUANT | |
XVID_VOP_TRELLISQUANT | XVID_VOP_HQACPRED, |
|
XVID_VOP_HQACPRED, |
|
112 |
|
|
113 |
}; |
}; |
114 |
#define VOP_ELEMENTS (sizeof(vop_presets)/sizeof(vop_presets[0])) |
#define VOP_ELEMENTS (sizeof(vop_presets)/sizeof(vop_presets[0])) |
132 |
static int ARG_SINGLE = 0; |
static int ARG_SINGLE = 0; |
133 |
static char *ARG_PASS1 = 0; |
static char *ARG_PASS1 = 0; |
134 |
static char *ARG_PASS2 = 0; |
static char *ARG_PASS2 = 0; |
135 |
static int ARG_QUALITY = 3; |
static int ARG_QUALITY = ME_ELEMENTS - 1; |
136 |
static float ARG_FRAMERATE = 25.00f; |
static float ARG_FRAMERATE = 25.00f; |
137 |
static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; |
static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; |
138 |
|
static int ARG_MAXKEYINTERVAL = 0; |
139 |
static char *ARG_INPUTFILE = NULL; |
static char *ARG_INPUTFILE = NULL; |
140 |
static int ARG_INPUTTYPE = 0; |
static int ARG_INPUTTYPE = 0; |
141 |
static int ARG_SAVEMPEGSTREAM = 0; |
static int ARG_SAVEMPEGSTREAM = 0; |
147 |
static int ARG_MAXBFRAMES = 0; |
static int ARG_MAXBFRAMES = 0; |
148 |
static int ARG_PACKED = 0; |
static int ARG_PACKED = 0; |
149 |
static int ARG_DEBUG = 0; |
static int ARG_DEBUG = 0; |
150 |
|
static int ARG_VOPDEBUG = 0; |
151 |
|
|
152 |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
153 |
|
|
297 |
} else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) { |
} else if (strcmp("-framerate", argv[i]) == 0 && i < argc - 1) { |
298 |
i++; |
i++; |
299 |
ARG_FRAMERATE = (float) atof(argv[i]); |
ARG_FRAMERATE = (float) atof(argv[i]); |
300 |
|
} else if (strcmp("-max_key_interval", argv[i]) == 0 && i < argc - 1) { |
301 |
|
i++; |
302 |
|
ARG_MAXKEYINTERVAL = atoi(argv[i]); |
303 |
} else if (strcmp("-i", argv[i]) == 0 && i < argc - 1) { |
} else if (strcmp("-i", argv[i]) == 0 && i < argc - 1) { |
304 |
i++; |
i++; |
305 |
ARG_INPUTFILE = argv[i]; |
ARG_INPUTFILE = argv[i]; |
318 |
} else if (strcmp("-save", argv[i]) == 0) { |
} else if (strcmp("-save", argv[i]) == 0) { |
319 |
ARG_SAVEMPEGSTREAM = 1; |
ARG_SAVEMPEGSTREAM = 1; |
320 |
} else if (strcmp("-debug", argv[i]) == 0) { |
} else if (strcmp("-debug", argv[i]) == 0) { |
321 |
ARG_DEBUG = 1; |
i++; |
322 |
|
if (sscanf(argv[i],"0x%x", &ARG_DEBUG) || sscanf(argv[i],"%d", &ARG_DEBUG)) ; |
323 |
} else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) { |
} else if (strcmp("-o", argv[i]) == 0 && i < argc - 1) { |
324 |
i++; |
i++; |
325 |
ARG_OUTPUTFILE = argv[i]; |
ARG_OUTPUTFILE = argv[i]; |
326 |
|
} else if (strcmp("-vop_debug", argv[i]) == 0) { |
327 |
|
ARG_VOPDEBUG = 1; |
328 |
} else if (strcmp("-help", argv[i])) { |
} else if (strcmp("-help", argv[i])) { |
329 |
usage(); |
usage(); |
330 |
return (0); |
return (0); |
458 |
|
|
459 |
/* Write the Frame statistics */ |
/* Write the Frame statistics */ |
460 |
|
|
461 |
printf("%5d: key=%i, time= %6.0f, length= %7d", !result ? input_num : -1, |
printf("%5d: key=%i, time= %6.0f, len= %7d", !result ? input_num : -1, |
462 |
key, (float) enctime, (int) m4v_size); |
key, (float) enctime, (int) m4v_size); |
463 |
|
|
464 |
if (stats_type > 0) { /* !XVID_TYPE_NOTHING */ |
if (stats_type > 0) { /* !XVID_TYPE_NOTHING */ |
481 |
break; |
break; |
482 |
} |
} |
483 |
|
|
484 |
printf(" | type=%s, quant= %2d, length= %7d", type, stats_quant, |
printf(" | type=%s, quant= %2d, len= %7d", type, stats_quant, |
485 |
stats_length); |
stats_length); |
486 |
|
|
487 |
#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))))) |
652 |
fprintf(stderr, " -single : single pass mode\n"); |
fprintf(stderr, " -single : single pass mode\n"); |
653 |
fprintf(stderr, " -pass1 filename : twopass mode (first pass)\n"); |
fprintf(stderr, " -pass1 filename : twopass mode (first pass)\n"); |
654 |
fprintf(stderr, " -pass2 filename : twopass mode (2nd pass)\n"); |
fprintf(stderr, " -pass2 filename : twopass mode (2nd pass)\n"); |
655 |
fprintf(stderr, " -zq frame float : bitrate zone; quant\n"); |
fprintf(stderr, " -zq starting_frame float : bitrate zone; quant\n"); |
656 |
fprintf(stderr, " -zw frame float : bitrate zone; weight\n"); |
fprintf(stderr, " -zw starting_frame float : bitrate zone; weight\n"); |
657 |
|
fprintf(stderr, " -max_key_interval integer : maximum keyframe interval\n"); |
658 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
659 |
fprintf(stderr, "Other options\n"); |
fprintf(stderr, "Other options\n"); |
660 |
fprintf(stderr, " -asm : use assembly optmized code\n"); |
fprintf(stderr, " -asm : use assembly optmized code\n"); |
662 |
fprintf(stderr, " -packed : packed mode\n"); |
fprintf(stderr, " -packed : packed mode\n"); |
663 |
fprintf(stderr, " -lumimasking : use lumimasking algorithm\n"); |
fprintf(stderr, " -lumimasking : use lumimasking algorithm\n"); |
664 |
fprintf(stderr, " -stats : print stats about encoded frames\n"); |
fprintf(stderr, " -stats : print stats about encoded frames\n"); |
665 |
fprintf(stderr, " -debug : print all MB dquants\n"); |
fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); |
666 |
|
fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n"); |
667 |
fprintf(stderr, " -help : prints this help message\n"); |
fprintf(stderr, " -help : prints this help message\n"); |
668 |
|
fprintf(stderr, "\n"); |
669 |
|
fprintf(stderr, "NB: You can define %d zones repeating the -z[qw] option as many times as needed.\n", MAX_ZONES); |
670 |
|
fprintf(stderr, "\n"); |
671 |
} |
} |
672 |
|
|
673 |
/***************************************************************************** |
/***************************************************************************** |
817 |
/* Set version -- version checking will done by xvidcore */ |
/* Set version -- version checking will done by xvidcore */ |
818 |
memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); |
memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); |
819 |
xvid_gbl_init.version = XVID_VERSION; |
xvid_gbl_init.version = XVID_VERSION; |
820 |
|
xvid_gbl_init.debug = ARG_DEBUG; |
821 |
|
|
822 |
|
|
823 |
/* Do we have to enable ASM optimizations ? */ |
/* Do we have to enable ASM optimizations ? */ |
897 |
xvid_enc_create.num_plugins++; |
xvid_enc_create.num_plugins++; |
898 |
} |
} |
899 |
|
|
900 |
|
#if 0 |
901 |
if (ARG_DEBUG) { |
if (ARG_DEBUG) { |
902 |
plugins[xvid_enc_create.num_plugins].func = rawenc_debug; |
plugins[xvid_enc_create.num_plugins].func = rawenc_debug; |
903 |
plugins[xvid_enc_create.num_plugins].param = NULL; |
plugins[xvid_enc_create.num_plugins].param = NULL; |
904 |
xvid_enc_create.num_plugins++; |
xvid_enc_create.num_plugins++; |
905 |
} |
} |
906 |
|
#endif |
907 |
|
|
908 |
/* No fancy thread tests */ |
/* No fancy thread tests */ |
909 |
xvid_enc_create.num_threads = 0; |
xvid_enc_create.num_threads = 0; |
918 |
} |
} |
919 |
|
|
920 |
/* Maximum key frame interval */ |
/* Maximum key frame interval */ |
921 |
|
if (ARG_MAXKEYINTERVAL > 0) { |
922 |
|
xvid_enc_create.max_key_interval = ARG_MAXKEYINTERVAL; |
923 |
|
}else { |
924 |
xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10; |
xvid_enc_create.max_key_interval = (int) ARG_FRAMERATE *10; |
925 |
|
} |
926 |
|
|
927 |
/* Bframes settings */ |
/* Bframes settings */ |
928 |
xvid_enc_create.max_bframes = ARG_MAXBFRAMES; |
xvid_enc_create.max_bframes = ARG_MAXBFRAMES; |
1002 |
|
|
1003 |
/* Set up core's general features */ |
/* Set up core's general features */ |
1004 |
xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY]; |
xvid_enc_frame.vop_flags = vop_presets[ARG_QUALITY]; |
1005 |
|
if (ARG_VOPDEBUG) { |
1006 |
|
xvid_enc_frame.vop_flags |= XVID_VOP_DEBUG; |
1007 |
|
} |
1008 |
|
|
1009 |
/* Frame type -- let core decide for us */ |
/* Frame type -- let core decide for us */ |
1010 |
xvid_enc_frame.type = XVID_TYPE_AUTO; |
xvid_enc_frame.type = XVID_TYPE_AUTO; |