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.26 2003-05-18 12:24:55 edgomez Exp $ |
* $Id: xvid_encraw.c,v 1.11.2.31 2003-08-04 17:22:36 chl 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> |
50 |
|
|
51 |
#include "xvid.h" |
#include "xvid.h" |
52 |
|
|
53 |
|
#undef READ_PNM |
54 |
|
|
55 |
/***************************************************************************** |
/***************************************************************************** |
56 |
* Quality presets |
* Quality presets |
57 |
****************************************************************************/ |
****************************************************************************/ |
58 |
static xvid_motion_t const motion_presets[] = { |
|
59 |
|
static const int motion_presets[] = { |
60 |
/* quality 0 */ |
/* quality 0 */ |
61 |
0, |
XVID_ME_GME_REFINE, |
62 |
|
|
63 |
/* quality 1 */ |
/* quality 1 */ |
64 |
XVID_ME_ADVANCEDDIAMOND16, |
XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16, |
65 |
|
|
66 |
/* quality 2 */ |
/* quality 2 */ |
67 |
XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16, |
XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16, |
68 |
|
|
69 |
/* quality 3 */ |
/* quality 3 */ |
70 |
XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | |
XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | |
71 |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8, |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8, |
72 |
|
|
73 |
/* quality 4 */ |
/* quality 4 */ |
74 |
XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | |
XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | |
75 |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | |
76 |
XVID_ME_CHROMA16 | XVID_ME_CHROMA8, |
XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, |
77 |
|
|
78 |
/* quality 5 */ |
/* quality 5 */ |
79 |
XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | |
XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | |
80 |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | |
81 |
XVID_ME_CHROMA16 | XVID_ME_CHROMA8, |
XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, |
82 |
|
|
83 |
/* quality 6 */ |
/* quality 6 */ |
84 |
XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | |
XVID_ME_GME_REFINE | XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | |
85 |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 | |
XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 | |
86 |
XVID_ME_CHROMA16 | XVID_ME_CHROMA8 , |
XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP, |
87 |
|
|
88 |
}; |
}; |
89 |
#define ME_ELEMENTS (sizeof(motion_presets)/sizeof(motion_presets[0])) |
#define ME_ELEMENTS (sizeof(motion_presets)/sizeof(motion_presets[0])) |
90 |
|
|
91 |
static xvid_vop_t const vop_presets[] = { |
static const int vop_presets[] = { |
92 |
/* quality 0 */ |
/* quality 0 */ |
93 |
0, |
0, |
94 |
|
|
151 |
static int ARG_DEBUG = 0; |
static int ARG_DEBUG = 0; |
152 |
static int ARG_VOPDEBUG = 0; |
static int ARG_VOPDEBUG = 0; |
153 |
|
|
154 |
|
#ifndef READ_PNM |
155 |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
#define IMAGE_SIZE(x,y) ((x)*(y)*3/2) |
156 |
|
#else |
157 |
|
#define IMAGE_SIZE(x,y) ((x)*(y)*3) |
158 |
|
#endif |
159 |
|
|
160 |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
#define MAX(A,B) ( ((A)>(B)) ? (A) : (B) ) |
161 |
#define SMALL_EPS (1e-10) |
#define SMALL_EPS (1e-10) |
186 |
static double msecond(); |
static double msecond(); |
187 |
|
|
188 |
/* PGM related functions */ |
/* PGM related functions */ |
189 |
|
#ifndef READ_PNM |
190 |
static int read_pgmheader(FILE * handle); |
static int read_pgmheader(FILE * handle); |
191 |
static int read_pgmdata(FILE * handle, |
static int read_pgmdata(FILE * handle, |
192 |
unsigned char *image); |
unsigned char *image); |
193 |
|
#else |
194 |
|
static int read_pnmheader(FILE * handle); |
195 |
|
static int read_pnmdata(FILE * handle, |
196 |
|
unsigned char *image); |
197 |
|
#endif |
198 |
static int read_yuvdata(FILE * handle, |
static int read_yuvdata(FILE * handle, |
199 |
unsigned char *image); |
unsigned char *image); |
200 |
|
|
385 |
} |
} |
386 |
|
|
387 |
if (ARG_INPUTTYPE) { |
if (ARG_INPUTTYPE) { |
388 |
|
#ifndef READ_PNM |
389 |
if (read_pgmheader(in_file)) { |
if (read_pgmheader(in_file)) { |
390 |
|
#else |
391 |
|
if (read_pnmheader(in_file)) { |
392 |
|
#endif |
393 |
fprintf(stderr, |
fprintf(stderr, |
394 |
"Wrong input format, I want YUV encapsulated in PGM\n"); |
"Wrong input format, I want YUV encapsulated in PGM\n"); |
395 |
return (-1); |
return (-1); |
455 |
if (!result) { |
if (!result) { |
456 |
if (ARG_INPUTTYPE) { |
if (ARG_INPUTTYPE) { |
457 |
/* read PGM data (YUV-format) */ |
/* read PGM data (YUV-format) */ |
458 |
|
#ifndef READ_PNM |
459 |
result = read_pgmdata(in_file, in_buffer); |
result = read_pgmdata(in_file, in_buffer); |
460 |
|
#else |
461 |
|
result = read_pnmdata(in_file, in_buffer); |
462 |
|
#endif |
463 |
} else { |
} else { |
464 |
/* read raw data (YUV-format) */ |
/* read raw data (YUV-format) */ |
465 |
result = read_yuvdata(in_file, in_buffer); |
result = read_yuvdata(in_file, in_buffer); |
555 |
|
|
556 |
/* Read the header if it's pgm stream */ |
/* Read the header if it's pgm stream */ |
557 |
if (!result && ARG_INPUTTYPE) |
if (!result && ARG_INPUTTYPE) |
558 |
|
#ifndef READ_PNM |
559 |
result = read_pgmheader(in_file); |
result = read_pgmheader(in_file); |
560 |
|
#else |
561 |
|
result = read_pnmheader(in_file); |
562 |
|
#endif |
563 |
} while (1); |
} while (1); |
564 |
|
|
565 |
|
|
701 |
* |
* |
702 |
*****************************************************************************/ |
*****************************************************************************/ |
703 |
|
|
704 |
|
#ifndef READ_PNM |
705 |
static int |
static int |
706 |
read_pgmheader(FILE * handle) |
read_pgmheader(FILE * handle) |
707 |
{ |
{ |
757 |
|
|
758 |
return (0); |
return (0); |
759 |
} |
} |
760 |
|
#else |
761 |
|
static int |
762 |
|
read_pnmheader(FILE * handle) |
763 |
|
{ |
764 |
|
int bytes, xsize, ysize, depth; |
765 |
|
char dummy[2]; |
766 |
|
|
767 |
|
bytes = fread(dummy, 1, 2, handle); |
768 |
|
|
769 |
|
if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '6')) |
770 |
|
return (1); |
771 |
|
|
772 |
|
fscanf(handle, "%d %d %d", &xsize, &ysize, &depth); |
773 |
|
if ((xsize > 1440) || (ysize > 2880) || (depth != 255)) { |
774 |
|
fprintf(stderr, "%d %d %d\n", xsize, ysize, depth); |
775 |
|
return (2); |
776 |
|
} |
777 |
|
|
778 |
|
XDIM = xsize; |
779 |
|
YDIM = ysize; |
780 |
|
|
781 |
|
return (0); |
782 |
|
} |
783 |
|
|
784 |
|
static int |
785 |
|
read_pnmdata(FILE * handle, |
786 |
|
unsigned char *image) |
787 |
|
{ |
788 |
|
int i; |
789 |
|
char dummy; |
790 |
|
|
791 |
|
/* read Y component of picture */ |
792 |
|
fread(image, 1, XDIM * YDIM * 3, handle); |
793 |
|
|
794 |
|
/* I don't know why, but this seems needed */ |
795 |
|
fread(&dummy, 1, 1, handle); |
796 |
|
|
797 |
|
return (0); |
798 |
|
} |
799 |
|
#endif |
800 |
|
|
801 |
static int |
static int |
802 |
read_yuvdata(FILE * handle, |
read_yuvdata(FILE * handle, |
888 |
if (use_assembler) { |
if (use_assembler) { |
889 |
|
|
890 |
#ifdef ARCH_IS_IA64 |
#ifdef ARCH_IS_IA64 |
891 |
xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_IA64; |
xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ASM; |
892 |
#else |
#else |
893 |
xvid_gbl_init.cpu_flags = 0; |
xvid_gbl_init.cpu_flags = 0; |
894 |
#endif |
#endif |
1053 |
/* Initialize input image fields */ |
/* Initialize input image fields */ |
1054 |
if (image) { |
if (image) { |
1055 |
xvid_enc_frame.input.plane[0] = image; |
xvid_enc_frame.input.plane[0] = image; |
1056 |
|
#ifndef READ_PNM |
1057 |
xvid_enc_frame.input.csp = XVID_CSP_I420; |
xvid_enc_frame.input.csp = XVID_CSP_I420; |
1058 |
xvid_enc_frame.input.stride[0] = XDIM; |
xvid_enc_frame.input.stride[0] = XDIM; |
1059 |
|
#else |
1060 |
|
xvid_enc_frame.input.csp = XVID_CSP_BGR; |
1061 |
|
xvid_enc_frame.input.stride[0] = XDIM*3; |
1062 |
|
#endif |
1063 |
} else { |
} else { |
1064 |
xvid_enc_frame.input.csp = XVID_CSP_NULL; |
xvid_enc_frame.input.csp = XVID_CSP_NULL; |
1065 |
} |
} |
1066 |
|
|
1067 |
/* Set up core's general features */ |
/* Set up core's general features */ |
1068 |
xvid_enc_frame.vol_flags = 0; |
xvid_enc_frame.vol_flags = XVID_VOL_GMC; |
1069 |
if (ARG_STATS) |
if (ARG_STATS) |
1070 |
xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS; |
xvid_enc_frame.vol_flags |= XVID_VOL_EXTRASTATS; |
1071 |
|
|