9 |
* the BFRAME option must be match to core compile option |
* the BFRAME option must be match to core compile option |
10 |
*******************************************************************************/ |
*******************************************************************************/ |
11 |
|
|
12 |
#define BFRAMES |
//#define BFRAMES |
13 |
#include "ex1.h" |
#include "ex1.h" |
14 |
|
|
15 |
int Encode(char *, int, int, char *); |
int Encode(char *, int, int, char *); |
55 |
param->max_quantizer = 31; |
param->max_quantizer = 31; |
56 |
param->max_key_interval = 100; |
param->max_key_interval = 100; |
57 |
|
|
58 |
|
#ifdef BFRAMES |
59 |
param->max_bframes = 0; // Disable B-frame |
param->max_bframes = 0; // Disable B-frame |
60 |
|
#endif |
61 |
} |
} |
62 |
|
|
63 |
void set_enc_frame(XVID_ENC_FRAME *frame) |
void set_enc_frame(XVID_ENC_FRAME *frame) |
72 |
frame->colorspace = XVID_CSP_YV12; // the test.yuv format is YV12 |
frame->colorspace = XVID_CSP_YV12; // the test.yuv format is YV12 |
73 |
frame->quant = 0; // CBR mode |
frame->quant = 0; // CBR mode |
74 |
|
|
|
frame->general = 0; |
|
75 |
frame->general |= XVID_MPEGQUANT; // Use MPEG quant |
frame->general |= XVID_MPEGQUANT; // Use MPEG quant |
76 |
frame->quant_inter_matrix = NULL; // Use default quant matrix |
frame->quant_inter_matrix = NULL; // Use default quant matrix |
77 |
frame->quant_intra_matrix = NULL; |
frame->quant_intra_matrix = NULL; |
104 |
} |
} |
105 |
|
|
106 |
// get Xvid core status |
// get Xvid core status |
107 |
|
init_param.cpu_flags = 0; |
108 |
xvid_init(0, 0, &init_param, NULL); |
xvid_init(0, 0, &init_param, NULL); |
109 |
// Check API Version is 2.1? |
// Check API Version is 2.1? |
110 |
if (init_param.api_version != ((2<<16)|(1))) |
if (init_param.api_version != ((2<<16)|(1))) |
121 |
// Encode Frame |
// Encode Frame |
122 |
temp=fread(inBuf, 1, width*height*3/2, fpi); // Read YUV data |
temp=fread(inBuf, 1, width*height*3/2, fpi); // Read YUV data |
123 |
while(temp == width*height*3/2){ |
while(temp == width*height*3/2){ |
124 |
//printf("Frames=%d\n",num); |
printf("Frames=%d\n",num); |
125 |
set_enc_frame(&frame); |
set_enc_frame(&frame); |
126 |
if (!(num%param.max_key_interval)) |
if (!(num%param.max_key_interval)) |
127 |
frame.intra = 1; // Encode as I-frame |
frame.intra = 1; // Encode as I-frame |