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.39 2010-03-09 10:00:22 Isibaar Exp $ |
* $Id: xvid_encraw.c,v 1.44 2010-11-16 14:42: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; |
346 |
int use_assembler = 1; |
int use_assembler = 1; |
347 |
int i; |
int i; |
348 |
|
|
|
#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 |
|
|
|
|
349 |
printf("xvid_encraw - raw mpeg4 bitstream encoder "); |
printf("xvid_encraw - raw mpeg4 bitstream encoder "); |
350 |
printf("written by Christoph Lampert\n\n"); |
printf("written by Christoph Lampert\n\n"); |
351 |
|
|
389 |
ARG_BITRATE = atoi(argv[i+1]); |
ARG_BITRATE = atoi(argv[i+1]); |
390 |
if (ARG_BITRATE) { |
if (ARG_BITRATE) { |
391 |
i++; |
i++; |
392 |
if (ARG_BITRATE <= 10000) |
if (ARG_BITRATE <= 20000) |
393 |
/* if given parameter is <= 10000, assume it means kbps */ |
/* if given parameter is <= 20000, assume it means kbps */ |
394 |
ARG_BITRATE *= 1000; |
ARG_BITRATE *= 1000; |
395 |
} |
} |
396 |
else |
else |
579 |
i++; |
i++; |
580 |
ARG_SSIM = atoi(argv[i]); |
ARG_SSIM = atoi(argv[i]); |
581 |
} |
} |
582 |
|
} else if (strcmp("-psnrhvsm", argv[i]) == 0) { |
583 |
|
ARG_PSNRHVSM = 1; |
584 |
} else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) { |
} else if (strcmp("-ssim_file", argv[i]) == 0 && i < argc -1) { |
585 |
i++; |
i++; |
586 |
ARG_SSIM_PATH = argv[i]; |
ARG_SSIM_PATH = argv[i]; |
700 |
ARG_VBVMAXRATE = atoi(argv[i]); |
ARG_VBVMAXRATE = atoi(argv[i]); |
701 |
} else if (strcmp("-vbvpeak", argv[i]) == 0 && i < argc -1) { |
} else if (strcmp("-vbvpeak", argv[i]) == 0 && i < argc -1) { |
702 |
i++; |
i++; |
703 |
ARG_VBVPEAKRATE = atoi(argv[i])*3; |
ARG_VBVPEAKRATE = atoi(argv[i]); |
704 |
} else if (strcmp("-reaction", argv[i]) == 0 && i < argc -1) { |
} else if (strcmp("-reaction", argv[i]) == 0 && i < argc -1) { |
705 |
i++; |
i++; |
706 |
ARG_REACTION = atoi(argv[i]); |
ARG_REACTION = atoi(argv[i]); |
816 |
} |
} |
817 |
|
|
818 |
if (ARG_INPUTFILE != NULL) { |
if (ARG_INPUTFILE != NULL) { |
819 |
#ifdef XVID_AVI_INPUT |
#if defined(XVID_AVI_INPUT) |
820 |
if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 || |
if (strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avs")==0 || |
821 |
strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 || |
strcmp(ARG_INPUTFILE+(strlen(ARG_INPUTFILE)-3), "avi")==0 || |
822 |
ARG_INPUTTYPE==2) |
ARG_INPUTTYPE==2) |
823 |
{ |
{ |
824 |
|
PAVIFILE avi_in = NULL; |
825 |
|
PAVISTREAM avi_in_stream = NULL; |
826 |
|
PGETFRAME get_frame = NULL; |
827 |
|
BITMAPINFOHEADER myBitmapInfoHeader; |
828 |
AVISTREAMINFO avi_info; |
AVISTREAMINFO avi_info; |
|
|
|
829 |
FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); |
FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); |
830 |
|
|
831 |
|
AVIFileInit(); |
832 |
|
|
833 |
if (avi_fp == NULL) { |
if (avi_fp == NULL) { |
834 |
fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); |
fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); |
835 |
return (-1); |
return (-1); |
922 |
|
|
923 |
if (get_frame) AVIStreamGetFrameClose(get_frame); |
if (get_frame) AVIStreamGetFrameClose(get_frame); |
924 |
if (avi_in_stream) AVIStreamRelease(avi_in_stream); |
if (avi_in_stream) AVIStreamRelease(avi_in_stream); |
925 |
|
AVIFileExit(); |
926 |
} |
} |
927 |
else |
else |
928 |
#endif |
#endif |
1026 |
sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k); |
sprintf(statsfilename[k], "%s.%03d", ARG_PASS1, k); |
1027 |
enc_data[k].statsfilename1 = statsfilename[k]; |
enc_data[k].statsfilename1 = statsfilename[k]; |
1028 |
} |
} |
1029 |
enc_data[k].start_num = (ARG_MAXFRAMENR-ARG_STARTFRAMENR)/ARG_NUM_APP_THREADS; |
enc_data[k].start_num = (k*(ARG_MAXFRAMENR-ARG_STARTFRAMENR))/ARG_NUM_APP_THREADS; |
1030 |
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; |
1031 |
} |
} |
1032 |
|
|
1151 |
|
|
1152 |
release_all: |
release_all: |
1153 |
|
|
|
#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) |
|
|
AVIFileExit(); |
|
|
#endif |
|
|
|
|
1154 |
return (0); |
return (0); |
|
|
|
1155 |
} |
} |
1156 |
|
|
1157 |
/***************************************************************************** |
/***************************************************************************** |
1194 |
|
|
1195 |
char filename[256]; |
char filename[256]; |
1196 |
|
|
1197 |
|
#ifdef XVID_MKV_OUTPUT |
1198 |
|
PMKVFILE myMKVFile = NULL; |
1199 |
|
PMKVSTREAM myMKVStream = NULL; |
1200 |
|
MKVSTREAMINFO myMKVStreamInfo; |
1201 |
|
#endif |
1202 |
#if defined(XVID_AVI_INPUT) |
#if defined(XVID_AVI_INPUT) |
1203 |
PAVIFILE avi_in = NULL; |
PAVIFILE avi_in = NULL; |
1204 |
PAVISTREAM avi_in_stream = NULL; |
PAVISTREAM avi_in_stream = NULL; |
1205 |
PGETFRAME get_frame = NULL; |
PGETFRAME get_frame = NULL; |
1206 |
|
BITMAPINFOHEADER myBitmapInfoHeader; |
1207 |
#else |
#else |
1208 |
#define get_frame NULL |
#define get_frame NULL |
1209 |
#endif |
#endif |
1212 |
PAVIFILE myAVIFile=NULL; |
PAVIFILE myAVIFile=NULL; |
1213 |
PAVISTREAM myAVIStream=NULL; |
PAVISTREAM myAVIStream=NULL; |
1214 |
AVISTREAMINFO myAVIStreamInfo; |
AVISTREAMINFO myAVIStreamInfo; |
1215 |
BITMAPINFOHEADER myBitmapInfoHeader; |
#endif |
1216 |
|
#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) |
1217 |
|
if (ARG_NUM_APP_THREADS > 1) |
1218 |
|
CoInitializeEx(0, COINIT_MULTITHREADED); |
1219 |
|
AVIFileInit(); |
1220 |
#endif |
#endif |
1221 |
|
|
1222 |
if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
if (ARG_INPUTFILE == NULL || strcmp(ARG_INPUTFILE, "stdin") == 0) { |
1230 |
AVISTREAMINFO avi_info; |
AVISTREAMINFO avi_info; |
1231 |
FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); |
FILE *avi_fp = fopen(ARG_INPUTFILE, "rb"); |
1232 |
|
|
|
if (ARG_NUM_APP_THREADS > 1) |
|
|
CoInitializeEx(0, COINIT_MULTITHREADED); |
|
|
|
|
1233 |
if (avi_fp == NULL) { |
if (avi_fp == NULL) { |
1234 |
fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); |
fprintf(stderr, "Couldn't open file '%s'!\n", ARG_INPUTFILE); |
1235 |
return; |
return; |
1713 |
if (myMKVStream) MKVStreamRelease(myMKVStream); |
if (myMKVStream) MKVStreamRelease(myMKVStream); |
1714 |
if (myMKVFile) MKVFileRelease(myMKVFile); |
if (myMKVFile) MKVFileRelease(myMKVFile); |
1715 |
#endif |
#endif |
1716 |
|
#if defined(XVID_AVI_INPUT) || defined(XVID_AVI_OUTPUT) |
1717 |
|
AVIFileExit(); |
1718 |
|
#endif |
1719 |
|
|
1720 |
free_all_memory: |
free_all_memory: |
1721 |
free(out_buffer); |
free(out_buffer); |
1857 |
fprintf(stderr, "-odegrade integer : max overflow degradation (5)\n"); |
fprintf(stderr, "-odegrade integer : max overflow degradation (5)\n"); |
1858 |
fprintf(stderr, "-chigh integer : high bitrate scenes degradation (0)\n"); |
fprintf(stderr, "-chigh integer : high bitrate scenes degradation (0)\n"); |
1859 |
fprintf(stderr, "-clow integer : low bitrate scenes improvement (0)\n"); |
fprintf(stderr, "-clow integer : low bitrate scenes improvement (0)\n"); |
1860 |
fprintf(stderr, "-overhead integer : container frame overhead (24)\n"); |
fprintf(stderr, "-overhead integer : container frame overhead (0)\n"); |
1861 |
fprintf(stderr, "-vbvsize integer : use vbv buffer size\n"); |
fprintf(stderr, "-vbvsize integer : use vbv buffer size\n"); |
1862 |
fprintf(stderr, "-vbvmax integer : vbv max bitrate\n"); |
fprintf(stderr, "-vbvmax integer : vbv max bitrate\n"); |
1863 |
fprintf(stderr, "-vbvpeak integer : vbv peak bitrate over 1 second\n"); |
fprintf(stderr, "-vbvpeak integer : vbv peak bitrate over 1 second\n"); |
1879 |
fprintf(stderr, " -stats : print stats about encoded frames\n"); |
fprintf(stderr, " -stats : print stats about encoded frames\n"); |
1880 |
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"); |
1881 |
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"); |
1882 |
|
fprintf(stderr, " -psnrhvsm : prints psnr-hvs-m metric for every frame\n"); |
1883 |
fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); |
fprintf(stderr, " -debug : activates xvidcore internal debugging output\n"); |
1884 |
fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n"); |
fprintf(stderr, " -vop_debug : print some info directly into encoded frames\n"); |
1885 |
fprintf(stderr, " -nochromame : Disable chroma motion estimation\n"); |
fprintf(stderr, " -nochromame : Disable chroma motion estimation\n"); |
2178 |
rc2pass2.vbv_size = ARG_VBVSIZE; |
rc2pass2.vbv_size = ARG_VBVSIZE; |
2179 |
rc2pass2.vbv_initial = (ARG_VBVSIZE*3)/4; |
rc2pass2.vbv_initial = (ARG_VBVSIZE*3)/4; |
2180 |
rc2pass2.vbv_maxrate = ARG_VBVMAXRATE; |
rc2pass2.vbv_maxrate = ARG_VBVMAXRATE; |
2181 |
rc2pass2.vbv_peakrate = ARG_VBVPEAKRATE*3; |
rc2pass2.vbv_peakrate = ARG_VBVPEAKRATE; |
2182 |
|
|
2183 |
|
|
2184 |
plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; |
plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; |
2245 |
xvid_enc_create.num_plugins++; |
xvid_enc_create.num_plugins++; |
2246 |
} |
} |
2247 |
|
|
2248 |
|
if (ARG_PSNRHVSM>0) { |
2249 |
|
plugins[xvid_enc_create.num_plugins].func = xvid_plugin_psnrhvsm; |
2250 |
|
plugins[xvid_enc_create.num_plugins].param = NULL; |
2251 |
|
xvid_enc_create.num_plugins++; |
2252 |
|
} |
2253 |
|
|
2254 |
#if 0 |
#if 0 |
2255 |
if (ARG_DEBUG) { |
if (ARG_DEBUG) { |
2256 |
plugins[xvid_enc_create.num_plugins].func = rawenc_debug; |
plugins[xvid_enc_create.num_plugins].func = rawenc_debug; |