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.45 2010-11-28 15:19:07 Isibaar Exp $ |
* $Id$ |
26 |
* |
* |
27 |
****************************************************************************/ |
****************************************************************************/ |
28 |
|
|
200 |
static char *ARG_PASS2 = 0; |
static char *ARG_PASS2 = 0; |
201 |
//static int ARG_QUALITY = ME_ELEMENTS - 1; |
//static int ARG_QUALITY = ME_ELEMENTS - 1; |
202 |
static int ARG_QUALITY = 6; |
static int ARG_QUALITY = 6; |
203 |
static float ARG_FRAMERATE = 25.00f; |
static float ARG_FRAMERATE = 0.f; |
204 |
static int ARG_DWRATE = 25; |
static int ARG_DWRATE = 25; |
205 |
static int ARG_DWSCALE = 1; |
static int ARG_DWSCALE = 1; |
206 |
static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; |
static int ARG_MAXFRAMENR = ABS_MAXFRAMENR; |
257 |
static int ARG_VBVMAXRATE = 0; |
static int ARG_VBVMAXRATE = 0; |
258 |
static int ARG_VBVPEAKRATE = 0; |
static int ARG_VBVPEAKRATE = 0; |
259 |
static int ARG_THREADS = 0; |
static int ARG_THREADS = 0; |
260 |
|
static int ARG_SLICES = 1; |
261 |
static int ARG_VFR = 0; |
static int ARG_VFR = 0; |
262 |
static int ARG_PROGRESS = 0; |
static int ARG_PROGRESS = 0; |
263 |
static int ARG_COLORSPACE = XVID_CSP_YV12; |
static int ARG_COLORSPACE = XVID_CSP_YV12; |
353 |
|
|
354 |
/* Is there a dumb Xvid coder ? */ |
/* Is there a dumb Xvid coder ? */ |
355 |
if(ME_ELEMENTS != VOP_ELEMENTS) { |
if(ME_ELEMENTS != VOP_ELEMENTS) { |
356 |
fprintf(stderr, "Presets' arrays should have the same number of elements -- Please fill a bug to xvid-devel@xvid.org\n"); |
fprintf(stderr, "Presets' arrays should have the same number of elements -- Please file a bug to xvid-devel@xvid.org\n"); |
357 |
return(-1); |
return(-1); |
358 |
} |
} |
359 |
|
|
448 |
} else if (strcmp("-threads", argv[i]) == 0 && i < argc -1) { |
} else if (strcmp("-threads", argv[i]) == 0 && i < argc -1) { |
449 |
i++; |
i++; |
450 |
ARG_THREADS = atoi(argv[i]); |
ARG_THREADS = atoi(argv[i]); |
451 |
|
} else if (strcmp("-slices", argv[i]) == 0 && i < argc -1) { |
452 |
|
i++; |
453 |
|
ARG_SLICES = atoi(argv[i]); |
454 |
} else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) { |
} else if (strcmp("-bquant_ratio", argv[i]) == 0 && i < argc - 1) { |
455 |
i++; |
i++; |
456 |
ARG_BQRATIO = atoi(argv[i]); |
ARG_BQRATIO = atoi(argv[i]); |
485 |
memset(&ZONES[NUM_ZONES], 0, sizeof(zone_t)); |
memset(&ZONES[NUM_ZONES], 0, sizeof(zone_t)); |
486 |
|
|
487 |
ZONES[NUM_ZONES].frame = startframe; |
ZONES[NUM_ZONES].frame = startframe; |
488 |
ZONES[NUM_ZONES].modifier = atof(options)*100; |
ZONES[NUM_ZONES].modifier = (int)(atof(options)*100); |
489 |
if (toupper(c)=='Q') |
if (toupper(c)=='Q') |
490 |
ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT; |
ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT; |
491 |
else if (toupper(c)=='W') |
else if (toupper(c)=='W') |
498 |
if ((frameoptions=strchr(options, ','))!=NULL) { |
if ((frameoptions=strchr(options, ','))!=NULL) { |
499 |
int readchar=0, count; |
int readchar=0, count; |
500 |
frameoptions++; |
frameoptions++; |
501 |
while (readchar<strlen(frameoptions)) { |
while (readchar<(int)strlen(frameoptions)) { |
502 |
if (sscanf(frameoptions+readchar, "%d%n", &(ZONES[NUM_ZONES].bvop_threshold), &count)==1) { |
if (sscanf(frameoptions+readchar, "%d%n", &(ZONES[NUM_ZONES].bvop_threshold), &count)==1) { |
503 |
readchar += count; |
readchar += count; |
504 |
} |
} |
536 |
else { |
else { |
537 |
ZONES[NUM_ZONES].mode = XVID_ZONE_WEIGHT; |
ZONES[NUM_ZONES].mode = XVID_ZONE_WEIGHT; |
538 |
} |
} |
539 |
ZONES[NUM_ZONES].modifier = atof(argv[i+2])*100; |
ZONES[NUM_ZONES].modifier = (int)(atof(argv[i+2])*100); |
540 |
i++; |
i++; |
541 |
ZONES[NUM_ZONES].frame = atoi(argv[i]); |
ZONES[NUM_ZONES].frame = atoi(argv[i]); |
542 |
i++; |
i++; |
563 |
int exponent; |
int exponent; |
564 |
i++; |
i++; |
565 |
ARG_FRAMERATE = (float) atof(argv[i]); |
ARG_FRAMERATE = (float) atof(argv[i]); |
566 |
exponent = strcspn(argv[i], "."); |
exponent = (int)strcspn(argv[i], "."); |
567 |
if (exponent<strlen(argv[i])) |
if (exponent<(int)strlen(argv[i])) |
568 |
exponent=pow(10.0, (int)(strlen(argv[i])-1-exponent)); |
exponent=(int)pow(10.0, (int)(strlen(argv[i])-1-exponent)); |
569 |
else |
else |
570 |
exponent=1; |
exponent=1; |
571 |
ARG_DWRATE = atof(argv[i])*exponent; |
ARG_DWRATE = (int)(atof(argv[i])*exponent); |
572 |
ARG_DWSCALE = exponent; |
ARG_DWSCALE = exponent; |
573 |
exponent = gcd(ARG_DWRATE, ARG_DWSCALE); |
exponent = gcd(ARG_DWRATE, ARG_DWSCALE); |
574 |
ARG_DWRATE /= exponent; |
ARG_DWRATE /= exponent; |
753 |
i++; |
i++; |
754 |
else |
else |
755 |
ARG_PROGRESS = 10; |
ARG_PROGRESS = 10; |
756 |
} else if (strcmp("-help", argv[i])) { |
} else if (strcmp("-help", argv[i]) == 0) { |
757 |
usage(); |
usage(); |
758 |
return (0); |
return (0); |
759 |
} else { |
} else { |
900 |
temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0); |
temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0); |
901 |
if (temp != NULL) { |
if (temp != NULL) { |
902 |
int i; |
int i; |
903 |
for (i = 0; i < ((DWORD*)temp)[0]; i++) { |
for (i = 0; i < (int)((DWORD*)temp)[0]; i++) { |
904 |
fprintf(stderr, "%2d ", temp[i]); |
fprintf(stderr, "%2d ", temp[i]); |
905 |
} |
} |
906 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
916 |
if (ARG_MAXFRAMENR<0) |
if (ARG_MAXFRAMENR<0) |
917 |
ARG_MAXFRAMENR = avi_info.dwLength-ARG_STARTFRAMENR; |
ARG_MAXFRAMENR = avi_info.dwLength-ARG_STARTFRAMENR; |
918 |
else |
else |
919 |
ARG_MAXFRAMENR = min(ARG_MAXFRAMENR, avi_info.dwLength-ARG_STARTFRAMENR); |
ARG_MAXFRAMENR = min(ARG_MAXFRAMENR, (int)(avi_info.dwLength-ARG_STARTFRAMENR)); |
920 |
|
|
921 |
XDIM = avi_info.rcFrame.right - avi_info.rcFrame.left; |
XDIM = avi_info.rcFrame.right - avi_info.rcFrame.left; |
922 |
YDIM = avi_info.rcFrame.bottom - avi_info.rcFrame.top; |
YDIM = avi_info.rcFrame.bottom - avi_info.rcFrame.top; |
951 |
} |
} |
952 |
|
|
953 |
if (ARG_FRAMERATE <= 0) { |
if (ARG_FRAMERATE <= 0) { |
954 |
fprintf(stderr, "Wrong Framerate %f\n", ARG_FRAMERATE); |
ARG_FRAMERATE = 25.00f; /* default value */ |
|
return (-1); |
|
955 |
} |
} |
956 |
|
|
957 |
if (ARG_TARGETSIZE) { |
if (ARG_TARGETSIZE) { |
962 |
fprintf(stderr, "Parameter conflict: Do not specify both -bitrate and -size\n"); |
fprintf(stderr, "Parameter conflict: Do not specify both -bitrate and -size\n"); |
963 |
goto release_all; |
goto release_all; |
964 |
} else |
} else |
965 |
ARG_BITRATE = ((ARG_TARGETSIZE * 8) / (ARG_MAXFRAMENR / ARG_FRAMERATE)) * 1024; |
ARG_BITRATE = (int)(((ARG_TARGETSIZE * 8) / (ARG_MAXFRAMENR / ARG_FRAMERATE)) * 1024); |
966 |
} |
} |
967 |
|
|
968 |
/* Set constant quant to default if no bitrate given for single pass */ |
/* Set constant quant to default if no bitrate given for single pass */ |
1299 |
temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0); |
temp = (unsigned char*)AVIStreamGetFrame(get_frame, 0); |
1300 |
if (temp != NULL) { |
if (temp != NULL) { |
1301 |
int i; |
int i; |
1302 |
for (i = 0; i < ((DWORD*)temp)[0]; i++) { |
for (i = 0; i < (int)((DWORD*)temp)[0]; i++) { |
1303 |
fprintf(stderr, "%2d ", temp[i]); |
fprintf(stderr, "%2d ", temp[i]); |
1304 |
} |
} |
1305 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
1409 |
myAVIStreamInfo.dwRate = ARG_DWRATE; |
myAVIStreamInfo.dwRate = ARG_DWRATE; |
1410 |
myAVIStreamInfo.dwLength = ARG_MAXFRAMENR; |
myAVIStreamInfo.dwLength = ARG_MAXFRAMENR; |
1411 |
myAVIStreamInfo.dwQuality = 10000; |
myAVIStreamInfo.dwQuality = 10000; |
1412 |
SetRect(&myAVIStreamInfo.rcFrame, 0, 0, YDIM, XDIM); |
SetRect(&myAVIStreamInfo.rcFrame, 0, 0, XDIM, YDIM); |
1413 |
|
|
1414 |
if (avierr=AVIFileOpen(&myAVIFile, ARG_AVIOUTPUTFILE, OF_CREATE|OF_WRITE, NULL)) { |
if (avierr=AVIFileOpen(&myAVIFile, ARG_AVIOUTPUTFILE, OF_CREATE|OF_WRITE, NULL)) { |
1415 |
fprintf(stderr, "AVIFileOpen failed opening output file %s, error code %d\n", ARG_AVIOUTPUTFILE, avierr); |
fprintf(stderr, "AVIFileOpen failed opening output file %s, error code %d\n", ARG_AVIOUTPUTFILE, avierr); |
1526 |
* Encode and decode this frame |
* Encode and decode this frame |
1527 |
****************************************************************************/ |
****************************************************************************/ |
1528 |
|
|
1529 |
if ((input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) { |
if ((unsigned int)(input_num+start_num) >= (unsigned int)(stop_num-1) && ARG_MAXBFRAMES) { |
1530 |
stats_type = XVID_TYPE_PVOP; |
stats_type = XVID_TYPE_PVOP; |
1531 |
} |
} |
1532 |
else |
else |
1838 |
fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (100)\n"); |
fprintf(stderr, " -bquant_offset integer: bframe quantizer offset (100)\n"); |
1839 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
1840 |
fprintf(stderr, "Rate control options:\n"); |
fprintf(stderr, "Rate control options:\n"); |
1841 |
fprintf(stderr, " -framerate float : target framerate (25.0)\n"); |
fprintf(stderr, " -framerate float : target framerate (auto)\n"); |
1842 |
fprintf(stderr, " -bitrate [integer] : target bitrate in kbps (700)\n"); |
fprintf(stderr, " -bitrate [integer] : target bitrate in kbps (700)\n"); |
1843 |
fprintf(stderr, " -size integer : target size in kilobytes\n"); |
fprintf(stderr, " -size integer : target size in kilobytes\n"); |
1844 |
fprintf(stderr, " -single : single pass mode (default)\n"); |
fprintf(stderr, " -single : single pass mode (default)\n"); |
1901 |
fprintf(stderr, " -drop integer : Frame Drop Ratio (0..100) (0)\n"); |
fprintf(stderr, " -drop integer : Frame Drop Ratio (0..100) (0)\n"); |
1902 |
fprintf(stderr, " -start integer : Starting frame number\n"); |
fprintf(stderr, " -start integer : Starting frame number\n"); |
1903 |
fprintf(stderr, " -threads integer : Number of threads\n"); |
fprintf(stderr, " -threads integer : Number of threads\n"); |
1904 |
|
fprintf(stderr, " -slices integer : Number of slices\n"); |
1905 |
fprintf(stderr, " -progress [integer] : Show progress updates every n frames (10)\n"); |
fprintf(stderr, " -progress [integer] : Show progress updates every n frames (10)\n"); |
1906 |
fprintf(stderr, " -par integer[:integer] : Set Pixel Aspect Ratio.\n"); |
fprintf(stderr, " -par integer[:integer] : Set Pixel Aspect Ratio.\n"); |
1907 |
fprintf(stderr, " 1 = 1:1\n"); |
fprintf(stderr, " 1 = 1:1\n"); |
1930 |
int bytes, xsize, ysize, depth; |
int bytes, xsize, ysize, depth; |
1931 |
char dummy[2]; |
char dummy[2]; |
1932 |
|
|
1933 |
bytes = fread(dummy, 1, 2, handle); |
bytes = (int) fread(dummy, 1, 2, handle); |
1934 |
|
|
1935 |
if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5')) |
if ((bytes < 2) || (dummy[0] != 'P') || (dummy[1] != '5')) |
1936 |
return (1); |
return (1); |
1937 |
|
|
1938 |
fscanf(handle, "%d %d %d", &xsize, &ysize, &depth); |
fscanf(handle, "%d %d %d", &xsize, &ysize, &depth); |
1939 |
|
fread(&dummy, 1, 1, handle); |
1940 |
if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) { |
if ((xsize > 4096) || (ysize > 4096*3/2) || (depth != 255)) { |
1941 |
fprintf(stderr, "%d %d %d\n", xsize, ysize, depth); |
fprintf(stderr, "%d %d %d\n", xsize, ysize, depth); |
1942 |
return (2); |
return (2); |
1954 |
unsigned char *image) |
unsigned char *image) |
1955 |
{ |
{ |
1956 |
int i; |
int i; |
|
char dummy; |
|
1957 |
|
|
1958 |
unsigned char *y = image; |
unsigned char *y = image; |
1959 |
unsigned char *u = image + XDIM * YDIM; |
unsigned char *u = image + XDIM * YDIM; |
1974 |
v += XDIM / 2; |
v += XDIM / 2; |
1975 |
} |
} |
1976 |
|
|
|
/* I don't know why, but this seems needed */ |
|
|
fread(&dummy, 1, 1, handle); |
|
|
|
|
1977 |
return (0); |
return (0); |
1978 |
} |
} |
1979 |
#else |
#else |
2266 |
#endif |
#endif |
2267 |
|
|
2268 |
xvid_enc_create.num_threads = ARG_THREADS; |
xvid_enc_create.num_threads = ARG_THREADS; |
2269 |
|
xvid_enc_create.num_slices = ARG_SLICES; |
2270 |
|
|
2271 |
/* Frame rate */ |
/* Frame rate */ |
2272 |
xvid_enc_create.fincr = ARG_DWSCALE; |
xvid_enc_create.fincr = ARG_DWSCALE; |
2587 |
|
|
2588 |
ZONES[NUM_ZONES].frame = 0; |
ZONES[NUM_ZONES].frame = 0; |
2589 |
ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT; |
ZONES[NUM_ZONES].mode = XVID_ZONE_QUANT; |
2590 |
ZONES[NUM_ZONES].modifier = ARG_CQ; |
ZONES[NUM_ZONES].modifier = (int)ARG_CQ; |
2591 |
ZONES[NUM_ZONES].type = XVID_TYPE_AUTO; |
ZONES[NUM_ZONES].type = XVID_TYPE_AUTO; |
2592 |
ZONES[NUM_ZONES].greyscale = 0; |
ZONES[NUM_ZONES].greyscale = 0; |
2593 |
ZONES[NUM_ZONES].chroma_opt = 0; |
ZONES[NUM_ZONES].chroma_opt = 0; |
2603 |
for(i = 0; i < NUM_ZONES; i++) |
for(i = 0; i < NUM_ZONES; i++) |
2604 |
if (ZONES[i].mode == XVID_ZONE_WEIGHT) { |
if (ZONES[i].mode == XVID_ZONE_WEIGHT) { |
2605 |
ZONES[i].mode = XVID_ZONE_QUANT; |
ZONES[i].mode = XVID_ZONE_QUANT; |
2606 |
ZONES[i].modifier = (100*ARG_CQ) / ZONES[i].modifier; |
ZONES[i].modifier = (int) ((100*ARG_CQ) / ZONES[i].modifier); |
2607 |
} |
} |
2608 |
} |
} |
2609 |
|
|
2672 |
int i; |
int i; |
2673 |
char* userdata; |
char* userdata; |
2674 |
|
|
2675 |
for (i=0; i <= (bufsize-sizeof(userdata_start_code)); i++) { |
for (i=0; i <= (int)(bufsize-sizeof(userdata_start_code)); i++) { |
2676 |
if (memcmp((void*)userdata_start_code, (void*)(buf+i), strlen(userdata_start_code))==0) { |
if (memcmp((void*)userdata_start_code, (void*)(buf+i), strlen(userdata_start_code))==0) { |
2677 |
if ((userdata = strstr(buf+i+4, "DivX"))!=NULL) { |
if ((userdata = strstr(buf+i+4, "DivX"))!=NULL) { |
2678 |
userdata[strlen(userdata)-1] = '\0'; |
userdata[strlen(userdata)-1] = '\0'; |