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.40 2010-03-09 14:56:02 Isibaar Exp $ |
* $Id: xvid_encraw.c,v 1.45 2010-11-28 15:19:07 Isibaar Exp $ |
26 |
* |
* |
27 |
****************************************************************************/ |
****************************************************************************/ |
28 |
|
|
189 |
static int ARG_CPU_FLAGS = 0; |
static int ARG_CPU_FLAGS = 0; |
190 |
static int ARG_STATS = 0; |
static int ARG_STATS = 0; |
191 |
static int ARG_SSIM = -1; |
static int ARG_SSIM = -1; |
192 |
|
static int ARG_PSNRHVSM = 0; |
193 |
static char* ARG_SSIM_PATH = NULL; |
static char* ARG_SSIM_PATH = NULL; |
194 |
static int ARG_DUMP = 0; |
static int ARG_DUMP = 0; |
195 |
static int ARG_LUMIMASKING = 0; |
static int ARG_LUMIMASKING = 0; |
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; |
347 |
int use_assembler = 1; |
int use_assembler = 1; |
348 |
int i; |
int i; |
349 |
|
|
|
#if defined(XVID_AVI_INPUT) |
|
|
PAVIFILE avi_in = NULL; |
|
|
PAVISTREAM avi_in_stream = NULL; |
|
|
PGETFRAME get_frame = NULL; |
|
|
#else |
|
|
#define get_frame NULL |
|
|
#endif |
|
|
#if defined(XVID_AVI_OUTPUT) |
|
|
PAVIFILE myAVIFile = NULL; |
|
|
PAVISTREAM myAVIStream = NULL; |
|
|
BITMAPINFOHEADER myBitmapInfoHeader; |
|
|
#endif |
|
|
#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) |
|
|
AVIFileInit(); |
|
|
#endif |
|
|
#ifdef XVID_MKV_OUTPUT |
|
|
PMKVFILE myMKVFile=NULL; |
|
|
PMKVSTREAM myMKVStream=NULL; |
|
|
MKVSTREAMINFO myMKVStreamInfo; |
|
|
#endif |
|
|
|
|
350 |
printf("xvid_encraw - raw mpeg4 bitstream encoder "); |
printf("xvid_encraw - raw mpeg4 bitstream encoder "); |
351 |
printf("written by Christoph Lampert\n\n"); |
printf("written by Christoph Lampert\n\n"); |
352 |
|
|
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 |
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++; |
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]; |
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]); |
820 |
} |
} |
821 |
|
|
822 |
if (ARG_INPUTFILE != NULL) { |
if (ARG_INPUTFILE != NULL) { |
823 |
#ifdef XVID_AVI_INPUT |
#if defined(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; |
|
|
|
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); |
926 |
|
|
927 |
if (get_frame) AVIStreamGetFrameClose(get_frame); |
if (get_frame) AVIStreamGetFrameClose(get_frame); |
928 |
if (avi_in_stream) AVIStreamRelease(avi_in_stream); |
if (avi_in_stream) AVIStreamRelease(avi_in_stream); |
929 |
|
AVIFileExit(); |
930 |
} |
} |
931 |
else |
else |
932 |
#endif |
#endif |
1030 |
sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k); |
sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k); |
1031 |
enc_data[k].statsfilename1 = statsfilename[k]; |
enc_data[k].statsfilename1 = statsfilename[k]; |
1032 |
} |
} |
1033 |
enc_data[k].start_num = k*((ARG_MAXFRAMENR-ARG_STARTFRAMENR)/ARG_NUM_APP_THREADS); |
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; |
enc_data[k].stop_num = ((k+1)*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS; |
1035 |
} |
} |
1036 |
|
|
1155 |
|
|
1156 |
release_all: |
release_all: |
1157 |
|
|
|
#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) |
|
|
AVIFileExit(); |
|
|
#endif |
|
|
|
|
1158 |
return (0); |
return (0); |
|
|
|
1159 |
} |
} |
1160 |
|
|
1161 |
/***************************************************************************** |
/***************************************************************************** |
1198 |
|
|
1199 |
char filename[256]; |
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) |
#if defined(XVID_AVI_INPUT) |
1207 |
PAVIFILE avi_in = NULL; |
PAVIFILE avi_in = NULL; |
1208 |
PAVISTREAM avi_in_stream = NULL; |
PAVISTREAM avi_in_stream = NULL; |
1209 |
PGETFRAME get_frame = NULL; |
PGETFRAME get_frame = NULL; |
1210 |
|
BITMAPINFOHEADER myBitmapInfoHeader; |
1211 |
#else |
#else |
1212 |
#define get_frame NULL |
#define get_frame NULL |
1213 |
#endif |
#endif |
1216 |
PAVIFILE myAVIFile=NULL; |
PAVIFILE myAVIFile=NULL; |
1217 |
PAVISTREAM myAVIStream=NULL; |
PAVISTREAM myAVIStream=NULL; |
1218 |
AVISTREAMINFO myAVIStreamInfo; |
AVISTREAMINFO myAVIStreamInfo; |
1219 |
BITMAPINFOHEADER myBitmapInfoHeader; |
#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 |
#endif |
1225 |
|
|
1226 |
if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
1234 |
AVISTREAMINFO avi_info; |
AVISTREAMINFO avi_info; |
1235 |
FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); |
FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); |
1236 |
|
|
|
if (ARG_NUM_APP_THREADS > 1) |
|
|
CoInitializeEx(0, COINIT_MULTITHREADED); |
|
|
|
|
1237 |
if (avi_fp == NULL) { |
if (avi_fp == NULL) { |
1238 |
fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); |
fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); |
1239 |
return; |
return; |
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); |
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"); |
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"); |
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"); |
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; |
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; |
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 */ |