47 |
#define ARG_BITRATE 900 |
#define ARG_BITRATE 900 |
48 |
|
|
49 |
int QUALITY =5; |
int QUALITY =5; |
50 |
int QUANTI = 0; // used for fixed-quantizer encoding |
int QUANTI = 0; /* used for fixed-quantizer encoding */ |
51 |
|
|
52 |
int XDIM=0; |
int XDIM=0; |
53 |
int YDIM=0; // will be set when reading first image |
int YDIM=0; /* will be set when reading first image */ |
54 |
int filenr = 0; |
int filenr = 0; |
55 |
|
|
56 |
int save_m4v_flag = 0; // save MPEG4-bytestream? |
int save_m4v_flag = 0; /* save MPEG4-bytestream? */ |
57 |
int save_dec_flag = 0; // save decompressed bytestream? |
int save_dec_flag = 0; /* save decompressed bytestream? */ |
58 |
char filepath[256] = "."; // path where to save |
char filepath[256] = "."; /* path where to save */ |
59 |
|
|
60 |
void *enchandle = NULL; // enchandle is a void*, written by encore |
void *enchandle = NULL; /* enchandle is a void*, written by encore */ |
61 |
const long dechandle = 0x0815; // dechandle is a unique constant!!! |
const long dechandle = 0x0815; /* dechandle is a unique constant!!! */ |
62 |
|
|
63 |
/*********************************************************************/ |
/*********************************************************************/ |
64 |
/* Routines for file input/output, nothing specific to XviD */ |
/* Routines for file input/output, nothing specific to XviD */ |
102 |
fread(buff1_ptr3,XDIM/2,1,stdin); |
fread(buff1_ptr3,XDIM/2,1,stdin); |
103 |
buff1_ptr3 += XDIM/2; |
buff1_ptr3 += XDIM/2; |
104 |
} |
} |
105 |
fread(&dummy,1,1,handle); // should be EOF |
fread(&dummy,1,1,handle); /* should be EOF */ |
106 |
return 0; |
return 0; |
107 |
} |
} |
108 |
|
|
119 |
|
|
120 |
enc_param.x_dim = XDIM; |
enc_param.x_dim = XDIM; |
121 |
enc_param.y_dim = YDIM; |
enc_param.y_dim = YDIM; |
122 |
enc_param.framerate = ARG_FRAMERATE; // a float |
enc_param.framerate = ARG_FRAMERATE; /* a float */ |
123 |
enc_param.bitrate = ARG_BITRATE*1000; |
enc_param.bitrate = ARG_BITRATE*1000; |
124 |
|
|
125 |
enc_param.rc_period = 2000; |
enc_param.rc_period = 2000; |
131 |
|
|
132 |
enc_param.quality = QUALITY; |
enc_param.quality = QUALITY; |
133 |
|
|
134 |
enc_param.use_bidirect = 0; // use bidirectional coding |
enc_param.use_bidirect = 0; /* use bidirectional coding */ |
135 |
enc_param.deinterlace = 0; // fast deinterlace |
enc_param.deinterlace = 0; /* fast deinterlace */ |
136 |
enc_param.obmc = 0; // flag to enable overlapped block motion compensation mode |
enc_param.obmc = 0; /* flag to enable overlapped block motion compensation mode */ |
137 |
|
|
138 |
enc_param.max_key_interval = (int)ARG_FRAMERATE*10; |
enc_param.max_key_interval = (int)ARG_FRAMERATE*10; |
139 |
enc_param.handle = NULL; //will be filled by encore |
enc_param.handle = NULL; /* will be filled by encore */ |
140 |
|
|
141 |
status = encore(enchandle, ENC_OPT_INIT, &enc_param, NULL); |
status = encore(enchandle, ENC_OPT_INIT, &enc_param, NULL); |
142 |
enchandle = enc_param.handle; |
enchandle = enc_param.handle; |
165 |
|
|
166 |
enc_frame.image = (void *) image; |
enc_frame.image = (void *) image; |
167 |
enc_frame.bitstream = (void *) bitstream; |
enc_frame.bitstream = (void *) bitstream; |
168 |
enc_frame.length = 0; // filled by encore |
enc_frame.length = 0; /* filled by encore */ |
169 |
enc_frame.colorspace = ENC_CSP_YV12; // input is YUV |
enc_frame.colorspace = ENC_CSP_YV12; /* input is YUV */ |
170 |
enc_frame.mvs = NULL; // unsupported |
enc_frame.mvs = NULL; /* unsupported */ |
171 |
|
|
172 |
if (QUANTI==0) |
if (QUANTI==0) |
173 |
{ |
{ |
175 |
} |
} |
176 |
else |
else |
177 |
{ enc_frame.quant = QUANTI; |
{ enc_frame.quant = QUANTI; |
178 |
enc_frame.intra = -1; // let encoder decide if frame is INTER/INTRA |
enc_frame.intra = -1; /* let encoder decide if frame is INTER/INTRA */ |
179 |
status = encore(enchandle, ENC_OPT_ENCODE_VBR, &enc_frame, &enc_result); |
status = encore(enchandle, ENC_OPT_ENCODE_VBR, &enc_frame, &enc_result); |
180 |
} |
} |
181 |
|
|
202 |
|
|
203 |
dec_param.x_dim = XDIM; |
dec_param.x_dim = XDIM; |
204 |
dec_param.y_dim = YDIM; |
dec_param.y_dim = YDIM; |
205 |
dec_param.output_format = DEC_RGB24; // output color format, , see <decore.h> |
dec_param.output_format = DEC_RGB24; /* output color format, , see <decore.h> */ |
206 |
|
|
207 |
dec_param.time_incr = 20; |
dec_param.time_incr = 20; |
208 |
|
|
231 |
dec_frame.length = m4v_size; |
dec_frame.length = m4v_size; |
232 |
dec_frame.bitstream = m4v_buffer; |
dec_frame.bitstream = m4v_buffer; |
233 |
dec_frame.bmp = rgb_buffer; |
dec_frame.bmp = rgb_buffer; |
234 |
dec_frame.render_flag = 1; // 0 means: skip this frame |
dec_frame.render_flag = 1; /* 0 means: skip this frame */ |
235 |
dec_frame.stride = XDIM; |
dec_frame.stride = XDIM; |
236 |
|
|
237 |
status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info); |
status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info); |
279 |
/* now we know the sizes, so allocate memory */ |
/* now we know the sizes, so allocate memory */ |
280 |
yuv_buffer = (unsigned char *) malloc(XDIM*YDIM); |
yuv_buffer = (unsigned char *) malloc(XDIM*YDIM); |
281 |
if (!yuv_buffer) |
if (!yuv_buffer) |
282 |
goto free_all_memory; // goto is one of the most underestimated instructions in C !!! |
goto free_all_memory; /* goto is one of the most underestimated instructions in C !!! */ |
283 |
divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); // this should really be enough! |
divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); /* this should really be enough! */ |
284 |
if (!divx_buffer) |
if (!divx_buffer) |
285 |
goto free_all_memory; // actually, every program should contain a goto |
goto free_all_memory; /* actually, every program should contain a goto */ |
286 |
|
|
287 |
YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so height is *3/2 too much |
YDIM = YDIM*2/3; /* PGM is YUV 4:2:0 format, so height is *3/2 too much */ |
288 |
|
|
289 |
rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4); |
rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4); |
290 |
if (!rgb_buffer) |
if (!rgb_buffer) |
291 |
goto free_all_memory; // the more, the better! |
goto free_all_memory; /* the more, the better! */ |
292 |
|
|
293 |
/*********************************************************************/ |
/*********************************************************************/ |
294 |
/* DIVX PART Start */ |
/* DIVX PART Start */ |
309 |
|
|
310 |
do |
do |
311 |
{ |
{ |
312 |
status = read_pgmdata(stdin, yuv_buffer); // read PGM data (YUV-format) |
status = read_pgmdata(stdin, yuv_buffer); /* read PGM data (YUV-format) */ |
313 |
if (status) |
if (status) |
314 |
{ |
{ |
315 |
fprintf(stderr, "PGM-Data-Error: %d\n", status); /* this should not happen */ |
fprintf(stderr, "PGM-Data-Error: %d\n", status); /* this should not happen */ |
343 |
filehandle=fopen(filename,"wb"); |
filehandle=fopen(filename,"wb"); |
344 |
if (filehandle) |
if (filehandle) |
345 |
{ |
{ |
346 |
fprintf(filehandle,"P6\n"); // rgb24 in PPM format |
fprintf(filehandle,"P6\n"); /* rgb24 in PPM format */ |
347 |
fprintf(filehandle,"%d %d 255\n",XDIM,YDIM); |
fprintf(filehandle,"%d %d 255\n",XDIM,YDIM); |
348 |
fwrite(rgb_buffer,XDIM,YDIM*3,filehandle); |
fwrite(rgb_buffer,XDIM,YDIM*3,filehandle); |
349 |
fclose(filehandle); |
fclose(filehandle); |
351 |
} |
} |
352 |
|
|
353 |
filenr++; |
filenr++; |
354 |
status = read_pgmheader(stdin); // if it was the last PGM, stop after it |
status = read_pgmheader(stdin); /* if it was the last PGM, stop after it */ |
355 |
if (status) |
if (status) |
356 |
{ |
{ |
357 |
fprintf(stderr, "PGM-Header-Error: %d\n", status); /* normally, just end of file */ |
fprintf(stderr, "PGM-Header-Error: %d\n", status); /* normally, just end of file */ |