51
54
#define VOP_ELEMENTS (sizeof(vop_presets)/sizeof(vop_presets[0]))
55
static myENC_RESULT xvid_res;
56
static xvid_gbl_init_t xvid_gbl_init2;
57
static xvid_enc_create_t xvid_enc_create;
58
static xvid_plugin_single_t single;
59
static xvid_plugin_2pass1_t pass1;
60
static xvid_plugin_2pass2_t pass2;
61
static xvid_enc_plugin_t plugins[7];
62
static xvid_enc_frame_t xvid_enc_frame;
63
static xvid_enc_stats_t xvid_enc_stats;
64
static xvid_gbl_info_t xvid_gbl_info;
57
static xvid_gbl_init_t xvid_gbl_init2;
58
static xvid_enc_create_t xvid_enc_create;
59
static xvid_plugin_single_t single;
60
static xvid_plugin_2pass1_t pass1;
61
static xvid_plugin_2pass2_t pass2;
62
static xvid_enc_plugin_t plugins[7];
63
static xvid_enc_frame_t xvid_enc_frame;
64
static xvid_enc_stats_t xvid_enc_stats;
65
static xvid_gbl_info_t xvid_gbl_info;
66
static uint32_t xvid_framenum;
65
67
#define MMSET(x) memset(&x,0,sizeof(x))
67
void xvid4_init(void);
71
adm_hook (void *handle, int opt, void *param1, void *param2)
73
xvid_plg_data_t *data = (xvid_plg_data_t *) param1;
74
// printf("Pass %d value %d\n",opt,data->frame_num);
75
if (opt == XVID_PLG_FRAME)
78
xvid_framenum = data->frame_num;
79
//printf("Before called with %u\n",xvid_framenum);
85
uint8_t xvid4Encoder::encode(ADMImage * in,ADMBitstream * out)
88
/* Encode the frame */
89
xvid_enc_frame.bitstream = out->data;
91
ret = xvid_encore (_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
95
printf ("Error calling xvid4 %d\n", ret);
103
printf ("Skipped\n");
109
void xvid4_init (void);
69
111
System wide init, do it once for all
73
MMSET(xvid_gbl_init2);
76
printf("Initializing global xvid 4\n");
77
xvid_gbl_init2.version = XVID_VERSION;
78
xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init2, NULL);
79
xvid_gbl_info.version = XVID_VERSION;
80
xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL);
81
if(xvid_gbl_info.build)
83
printf("\txvid build:%s\n",xvid_gbl_info.build);
85
printf("\txvid thread:%d\n",xvid_gbl_info.num_threads);
86
printf("\txvid SIMD supported:(%x)\n",xvid_gbl_info.cpu_flags);
87
#define CPUF(x) if(xvid_gbl_info.cpu_flags & XVID_CPU_##x) printf("\t\t"#x"\n");
116
MMSET (xvid_gbl_init2);
117
MMSET (xvid_gbl_info);
119
printf ("Initializing global xvid 4\n");
120
xvid_gbl_init2.version = XVID_VERSION;
121
xvid_global (NULL, XVID_GBL_INIT, &xvid_gbl_init2, NULL);
122
xvid_gbl_info.version = XVID_VERSION;
123
xvid_global (NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL);
124
if (xvid_gbl_info.build)
126
printf ("\txvid build:%s\n", xvid_gbl_info.build);
128
printf ("\txvid thread:%d\n", xvid_gbl_info.num_threads);
129
printf ("\txvid SIMD supported:(%x)\n", xvid_gbl_info.cpu_flags);
130
#define CPUF(x) if(xvid_gbl_info.cpu_flags & XVID_CPU_##x) printf("\t\t"#x"\n");
88
131
#if defined( ARCH_X86) || defined(ARCH_X86_64)
101
xvid4Encoder::~xvid4Encoder()
144
xvid4Encoder::~xvid4Encoder ()
105
148
//--------------------------------------------------
107
uint8_t xvid4Encoder::init(uint32_t q,uint32_t fps1000,xvid4EncParam *param)
113
uint8_t xvid4Encoder::getResult( void *ress)
117
res=(myENC_RESULT *)ress;
118
memcpy(res,&xvid_res,sizeof(myENC_RESULT));
122
void xvid4Encoder::createUpdate(void )
124
xvid_enc_create.max_bframes=_param.bframes;
125
xvid_enc_create.max_key_interval=_param.max_key_interval;
126
xvid_enc_create.bquant_ratio = _param.bquant_ratio;
127
xvid_enc_create.bquant_offset = _param.bquant_offset;
130
xvid_enc_create.global |= XVID_GLOBAL_PACKED;
132
if (_param.closed_gop)
133
xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
135
for(uint32_t i=0;i<3;i++)
137
xvid_enc_create.min_quant[i]=_param.qmin[i];
138
xvid_enc_create.max_quant[i]=_param.qmax[i];
142
#define C_VOP(x) if(xvid_enc_frame.vop_flags& XVID_VOP_##x) printf("Vop :"#x" is set\n");
151
xvid4Encoder::init (uint32_t q, uint32_t fps1000, xvid4EncParam * param)
158
xvid4Encoder::createUpdate (void)
160
uint32_t nbThread = 0;
161
xvid_enc_create.num_threads = 0;
162
if (nbThread = ADM_useNbThreads ())
164
printf ("Xvid4 : using %u threads..\n", nbThread);
165
xvid_enc_create.num_threads = nbThread;
167
xvid_enc_create.max_bframes = _param.bframes;
168
xvid_enc_create.max_key_interval = _param.max_key_interval;
169
xvid_enc_create.bquant_ratio = _param.bquant_ratio;
170
xvid_enc_create.bquant_offset = _param.bquant_offset;
173
xvid_enc_create.global |=XVID_GLOBAL_PACKED;
175
if (_param.closed_gop)
176
xvid_enc_create.global |=XVID_GLOBAL_CLOSED_GOP;
178
for (uint32_t i = 0; i < 3; i++)
180
xvid_enc_create.min_quant[i] = _param.qmin[i];
181
xvid_enc_create.max_quant[i] = _param.qmax[i];
185
#define C_VOP(x) if(xvid_enc_frame.vop_flags& XVID_VOP_##x) printf("Vop :"#x" is set\n");
143
186
#define C_VOL(x) if(xvid_enc_frame.vol_flags& XVID_VOL_##x) printf("Vol :"#x" is set\n");
144
187
#define C_ME(x) if(xvid_enc_frame.motion& XVID_ME_##x) printf("ME :"#x" is set\n");
155
C_VOP(MODEDECISION_RD);
163
C_ME(ADVANCEDDIAMOND16);
164
C_ME(ADVANCEDDIAMOND8);
169
C_ME(HALFPELREFINE16);
170
C_ME(HALFPELREFINE8);
175
C_ME(SKIP_DELTASEARCH);
176
C_ME(FAST_MODEINTERPOLATE);
177
C_ME(BFRAME_EARLYSTOP);
180
C_ME(QUARTERPELREFINE8);
181
C_ME(QUARTERPELREFINE16);
190
void xvid4Encoder::encUpdate(void )
196
void xvid4Encoder::dump(void)
198
printf("Xvid4 codec configuration:\n");
199
if(_param.mpegQuantizer)
200
printf("\tMPEGQUANT\n");
201
if(_param.interlaced)
202
printf("\tINTERLACED\n");
193
C_VOP (TRELLISQUANT);
198
C_VOP (MODEDECISION_RD);
206
C_ME (ADVANCEDDIAMOND16);
207
C_ME (ADVANCEDDIAMOND8);
212
C_ME (HALFPELREFINE16);
213
C_ME (HALFPELREFINE8);
218
C_ME (SKIP_DELTASEARCH);
219
C_ME (FAST_MODEINTERPOLATE);
220
C_ME (BFRAME_EARLYSTOP);
223
C_ME (QUARTERPELREFINE8);
224
C_ME (QUARTERPELREFINE16);
229
MMSET (xvid_enc_frame);
235
xvid4Encoder::dump (void)
237
printf ("Xvid4 codec configuration:\n");
238
if (_param.mpegQuantizer)
239
printf ("\tMPEGQUANT\n");
240
if (_param.interlaced)
241
printf ("\tINTERLACED\n");
205
244
#define ST(x,y) \
206
if(_param.x) printf("\t"#y"\n");
209
ST( inter4mv, INTER4V);
210
ST( trellis, TRELLISQUANT);
211
ST( cartoon, CARTOON);
212
ST( greyscale, GREYSCALE);
245
if(_param.x) printf("\t"#y"\n");
248
ST (inter4mv, INTER4V);
249
ST (trellis, TRELLISQUANT);
250
ST (cartoon, CARTOON);
251
ST (greyscale, GREYSCALE);
218
257
// Initialize the compressor
220
uint8_t xvid4Encoder::stopEncoder(void )
260
xvid4Encoder::stopEncoder (void)
224
xvid_encore(_handle, XVID_ENC_DESTROY, NULL, NULL);
225
printf("Destroying xvid codec\n");
264
xvid_encore (_handle, XVID_ENC_DESTROY, NULL, NULL);
265
printf ("Destroying xvid codec\n");
230
uint8_t xvid4Encoder::preAmble(uint8_t *in )
271
xvid4Encoder::preAmble (uint8_t * in)
232
273
/* Version for the frame and the stats */
233
MMSET(xvid_enc_frame);
234
MMSET(xvid_enc_stats);
236
xvid_enc_frame.version = XVID_VERSION;
237
xvid_enc_stats.version = XVID_VERSION;
239
/* Bind output buffer */
241
xvid_enc_frame.length = 0;
242
if(_param.mpegQuantizer)
243
xvid_enc_frame.vol_flags|=XVID_VOL_MPEGQUANT;
244
if(_param.interlaced)
245
xvid_enc_frame.vol_flags|=XVID_VOL_INTERLACING;
274
//MMSET (xvid_enc_frame);
275
MMSET (xvid_enc_stats);
277
xvid_enc_frame.version = XVID_VERSION;
278
xvid_enc_stats.version = XVID_VERSION;
280
/* Bind output buffer */
282
xvid_enc_frame.length = 0;
283
if (_param.mpegQuantizer)
284
xvid_enc_frame.vol_flags |= XVID_VOL_MPEGQUANT;
285
if (_param.interlaced)
286
xvid_enc_frame.vol_flags |= XVID_VOL_INTERLACING;
248
289
#define SVOP(x,y) if(_param.x) xvid_enc_frame.vop_flags|=XVID_VOP_##y
251
xvid_enc_frame.motion = motion_presets[_param.guiLevel];
253
SVOP( inter4mv ,INTER4V);
254
SVOP( trellis ,TRELLISQUANT);
255
SVOP( hqac ,HQACPRED);
256
SVOP( greyscale,GREYSCALE);
257
SVOP( cartoon ,CARTOON);
258
SVOP( chroma_opt,CHROMAOPT);
260
xvid_enc_frame.vop_flags|=XVID_VOP_HALFPEL;
264
xvid_enc_frame.motion|=XVID_ME_CHROMA_BVOP;
265
xvid_enc_frame.motion|=XVID_ME_CHROMA_PVOP;
269
xvid_enc_frame.motion|=XVID_ME_DETECT_STATIC_MOTION;
271
//printf("Vhq mode : %d\n",_param.vhqmode);
292
xvid_enc_frame.motion = motion_presets[_param.guiLevel];
294
SVOP (inter4mv, INTER4V);
295
SVOP (trellis, TRELLISQUANT);
296
SVOP (hqac, HQACPRED);
297
#if XVID_API==XVID_MAKE_API(4, 1)
298
SVOP (bvhq, RD_BVOP);
301
SVOP (greyscale, GREYSCALE);
302
SVOP (cartoon, CARTOON);
303
SVOP (chroma_opt, CHROMAOPT);
305
xvid_enc_frame.vop_flags |= XVID_VOP_HALFPEL;
307
if (_param.chroma_me)
309
xvid_enc_frame.motion |= XVID_ME_CHROMA_BVOP;
310
xvid_enc_frame.motion |= XVID_ME_CHROMA_PVOP;
314
xvid_enc_frame.motion |= XVID_ME_DETECT_STATIC_MOTION;
316
//printf("Vhq mode : %d\n",_param.vhqmode);
272
317
#define VHME(x) xvid_enc_frame.motion|= XVID_ME_##x
273
switch(_param.vhqmode)
275
case 4: VHME(EXTSEARCH_RD);
276
case 3: VHME(HALFPELREFINE8_RD);
277
VHME(QUARTERPELREFINE8_RD);
278
VHME(CHECKPREDICTION_RD);
281
VHME(HALFPELREFINE16_RD);
282
VHME(QUARTERPELREFINE16_RD);
284
SVOP(vhqmode,MODEDECISION_RD);
292
xvid_enc_frame.vol_flags|=XVID_VOL_QUARTERPEL;
294
xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16;
295
xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8;
300
xvid_enc_frame.vol_flags |= XVID_VOL_GMC;
301
xvid_enc_frame.motion |= XVID_ME_GME_REFINE;
306
xvid_enc_frame.motion |= XVID_ME_FASTREFINE16;
307
xvid_enc_frame.motion |= XVID_ME_FASTREFINE8;
308
xvid_enc_frame.motion |= XVID_ME_SKIP_DELTASEARCH;
309
xvid_enc_frame.motion |= XVID_ME_FAST_MODEINTERPOLATE;
310
xvid_enc_frame.motion |= XVID_ME_BFRAME_EARLYSTOP;
313
xvid_enc_frame.bframe_threshold = _param.bframe_threshold;
315
xvid_enc_frame.input.csp = XVID_CSP_YV12;
316
xvid_enc_frame.input.stride[0] = _w;
317
xvid_enc_frame.input.stride[1] = _w>>1;
318
xvid_enc_frame.input.stride[2] = _w>>1;
319
xvid_enc_frame.type = XVID_TYPE_AUTO;
322
/* Set up motion estimation flags */
323
xvid_enc_frame.input.plane[0] = in;
324
xvid_enc_frame.input.plane[1] = in+(_w*_h);
325
xvid_enc_frame.input.plane[2] = in+((_w*_h*5)>>2);
329
uint8_t xvid4Encoder::postAmble(uint32_t *flags )
331
xvid_res.is_key_frame=*flags=0;
333
if(xvid_enc_frame.out_flags & XVID_KEYFRAME)
335
*flags=AVI_KEY_FRAME;
336
xvid_res.is_key_frame=1;
339
if(xvid_enc_stats.type == XVID_TYPE_BVOP)
344
xvid_res.out_quantizer=xvid_enc_stats.quant;
348
// *************************************************
349
// *************************************************
351
// *************************************************
352
// *************************************************
353
uint8_t xvid4EncoderCQ::init(uint32_t q,uint32_t fps1000, xvid4EncParam *param)
356
printf("Using Xvid 4 codec with CQ mode = %lu (%dx%d)\n",q,_w,_h);
359
memcpy(&_param,param,sizeof(_param));
362
MMSET(xvid_enc_create);
363
xvid_enc_create.version = XVID_VERSION;
364
xvid_enc_create.width = _w;
365
xvid_enc_create.height = _h;
369
plugins[0].func = xvid_plugin_single;
370
plugins[0].param = &single;
372
single.version = XVID_VERSION;
373
single.bitrate = 1500;
375
xvid_enc_create.plugins = plugins;
376
xvid_enc_create.num_plugins = 1;
379
xvid_enc_create.fincr = 1000;
380
xvid_enc_create.fbase = _fps1000;
383
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
386
printf("Xvid-4 init error :%d\n",xerr);
391
_handle = xvid_enc_create.handle;
393
printf("Xvid-4 CQ init Ok\n");
399
uint8_t xvid4EncoderCQ::encode(
411
xvid_enc_frame.quant = _q;
412
xvid_enc_frame.bitstream = out;
414
/* Encode the frame */
415
ret = xvid_encore(_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
419
printf("Error calling xvid4 %d\n",ret);
425
*len=xvid_res.total_bits=ret;
426
xvid_res.total_bits*=8;
431
// *************************************************
432
// *************************************************
433
// CQ but Q is controlled externally
434
// *************************************************
435
// *************************************************
437
uint8_t xvid4EncoderVBRExternal::init(uint32_t q,uint32_t fps1000, xvid4EncParam *param)
440
printf("Using Xvid 4 codec with CQ mode = %lu (%dx%d)\n",q,_w,_h);
443
memcpy(&_param,param,sizeof(_param));
446
MMSET(xvid_enc_create);
447
xvid_enc_create.version = XVID_VERSION;
448
xvid_enc_create.width = _w;
449
xvid_enc_create.height = _h;
453
plugins[0].func = xvid_plugin_single;
454
plugins[0].param = &single;
456
single.version = XVID_VERSION;
457
single.bitrate = 1500;
459
xvid_enc_create.plugins = plugins;
460
xvid_enc_create.num_plugins = 1;
463
xvid_enc_create.fincr = 1000;
464
xvid_enc_create.fbase = _fps1000;
467
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
470
printf("Xvid-4 init error :%d\n",xerr);
475
_handle = xvid_enc_create.handle;
477
printf("Xvid-4 CQ init Ok\n");
483
uint8_t xvid4EncoderVBRExternal::encode(
492
return encodeVBR(in,out,len,q,flags);
495
uint8_t xvid4EncoderVBRExternal::encodeVBR(
505
xvid_enc_frame.quant = q;
506
xvid_enc_frame.bitstream = out;
507
if(*flags & AVI_KEY_FRAME)
509
xvid_enc_frame.type=XVID_TYPE_IVOP;
511
else if(*flags & AVI_B_FRAME)
513
xvid_enc_frame.type=XVID_TYPE_BVOP;
517
xvid_enc_frame.type=XVID_TYPE_PVOP;
520
/* Encode the frame */
521
ret = xvid_encore(_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
525
printf("Error calling xvid4 %d\n",ret);
531
*len=xvid_res.total_bits=ret;
532
xvid_res.total_bits*=8;
537
// *************************************************
538
// *************************************************
540
// *************************************************
541
// *************************************************
542
uint8_t xvid4EncoderCBR::init(uint32_t br,uint32_t fps1000, xvid4EncParam *param)
545
printf("Using Xvid 4 codec with CBR mode = %lu kbps\n",br);
548
memcpy(&_param,param,sizeof(_param));
552
MMSET(xvid_enc_create);
554
xvid_enc_create.version = XVID_VERSION;
555
xvid_enc_create.width = _w;
556
xvid_enc_create.height = _h;
559
plugins[0].func = xvid_plugin_single;
560
plugins[0].param = &single;
562
single.version = XVID_VERSION;
563
single.bitrate = _bitrate*1000; // Kb->bit
565
xvid_enc_create.plugins = plugins;
566
xvid_enc_create.num_plugins = 1;
569
xvid_enc_create.fincr = 1000;
570
xvid_enc_create.fbase = _fps1000;
573
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
576
printf("Xvid-4 init error :%d\n",xerr);
581
_handle = xvid_enc_create.handle;
583
printf("Xvid-4 CBR init Ok\n");
589
uint8_t xvid4EncoderCBR::encode(
601
xvid_enc_frame.quant = 0;
602
xvid_enc_frame.bitstream = out;
610
/* Encode the frame */
611
ret = xvid_encore(_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
615
printf("Error calling xvid4 %d\n",ret);
621
*len=xvid_res.total_bits=ret;
622
xvid_res.total_bits*=8;
627
// *************************************************
628
// *************************************************
630
// *************************************************
631
// *************************************************
632
uint8_t xvid4EncoderPass1::init(uint32_t br,uint32_t fps1000, xvid4EncParam *param)
635
printf("Using Xvid 4 codec pass 1 of 2 (log: %s)\n",(char *)param->logName);
638
memcpy(&_param,param,sizeof(_param));
641
MMSET(xvid_enc_create);
644
xvid_enc_create.version = XVID_VERSION;
645
xvid_enc_create.width = _w;
646
xvid_enc_create.height = _h;
650
plugins[0].func = xvid_plugin_2pass1;
651
plugins[0].param = &pass1;
653
pass1.version = XVID_VERSION;
654
pass1.filename = (char *)_param.logName;
656
xvid_enc_create.plugins = plugins;
657
xvid_enc_create.num_plugins = 1;
661
xvid_enc_create.fincr = 1000;
662
xvid_enc_create.fbase = _fps1000;
666
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
669
printf("Xvid-4 init error :%d\n",xerr);
674
_handle = xvid_enc_create.handle;
676
printf("Xvid-4 Pass1 init Ok\n");
682
uint8_t xvid4EncoderPass1::encode(
694
//xvid_enc_frame.quant = 2;
695
xvid_enc_frame.bitstream = out;
696
xvid_enc_frame.input.plane[0] = YPLANE(in);
700
/* Encode the frame */
701
ret = xvid_encore(_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
705
printf("Error calling xvid4 %d\n",ret);
711
*len=xvid_res.total_bits=ret;
712
xvid_res.total_bits*=8;
717
// *************************************************
718
// *************************************************
720
// *************************************************
721
// *************************************************
722
uint8_t xvid4EncoderPass2::init(uint32_t br,uint32_t fps1000, xvid4EncParam *param)
725
printf("Using Xvid 4 codec with 2pass mode pass 2 of 2, average bitrate = %lu\n",br);
728
memcpy(&_param,param,sizeof(_param));
731
MMSET(xvid_enc_create);
734
xvid_enc_create.version = XVID_VERSION;
735
xvid_enc_create.width = _w;
736
xvid_enc_create.height = _h;
740
plugins[0].func = xvid_plugin_2pass2;
741
plugins[0].param = &pass2;
743
pass2.version = XVID_VERSION;
744
pass2.filename = (char *)_param.logName;
746
pass2.bitrate=br; // Average bitrate
747
#define CPY(x) pass2.x=_param.x;printf(#x"=%d\n",pass2.x);
749
CPY( keyframe_boost);
750
CPY( curve_compression_high);
751
CPY( curve_compression_low);
752
CPY( overflow_control_strength);
753
CPY( max_overflow_improvement);
754
CPY( max_overflow_degradation);
758
CPY( container_frame_overhead);
762
xvid_enc_create.plugins = plugins;
763
xvid_enc_create.num_plugins = 1;
766
xvid_enc_create.fincr = 1000;
767
xvid_enc_create.fbase = _fps1000;
770
xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
773
printf("Xvid-4 init error :%d\n",xerr);
778
_handle = xvid_enc_create.handle;
780
printf("Xvid-4 init Ok\n");
786
uint8_t xvid4EncoderPass2::encode(
798
xvid_enc_frame.bitstream = out;
799
xvid_enc_frame.input.plane[0] = YPLANE(in);
803
/* Encode the frame */
804
ret = xvid_encore(_handle, XVID_ENC_ENCODE, &xvid_enc_frame,
808
printf("Error calling xvid4 %d\n",ret);
814
*len=xvid_res.total_bits=ret;
815
xvid_res.total_bits*=8;
318
switch (_param.vhqmode)
323
VHME (HALFPELREFINE8_RD);
324
VHME (QUARTERPELREFINE8_RD);
325
VHME (CHECKPREDICTION_RD);
328
VHME (HALFPELREFINE16_RD);
329
VHME (QUARTERPELREFINE16_RD);
331
SVOP (vhqmode, MODEDECISION_RD);
339
xvid_enc_frame.vol_flags |= XVID_VOL_QUARTERPEL;
341
xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE16;
342
xvid_enc_frame.motion |= XVID_ME_QUARTERPELREFINE8;
347
xvid_enc_frame.vol_flags |= XVID_VOL_GMC;
348
xvid_enc_frame.motion |= XVID_ME_GME_REFINE;
353
xvid_enc_frame.motion |= XVID_ME_FASTREFINE16;
354
xvid_enc_frame.motion |= XVID_ME_FASTREFINE8;
355
xvid_enc_frame.motion |= XVID_ME_SKIP_DELTASEARCH;
356
xvid_enc_frame.motion |= XVID_ME_FAST_MODEINTERPOLATE;
357
xvid_enc_frame.motion |= XVID_ME_BFRAME_EARLYSTOP;
360
xvid_enc_frame.bframe_threshold = _param.bframe_threshold;
362
xvid_enc_frame.input.csp = XVID_CSP_YV12;
363
xvid_enc_frame.input.stride[0] = _w;
364
xvid_enc_frame.input.stride[1] = _w >> 1;
365
xvid_enc_frame.input.stride[2] = _w >> 1;
366
xvid_enc_frame.type = XVID_TYPE_AUTO;
369
/* Set up motion estimation flags */
370
xvid_enc_frame.input.plane[0] = in;
371
xvid_enc_frame.input.plane[1] = in + (_w * _h);
372
xvid_enc_frame.input.plane[2] = in + ((_w * _h * 5) >> 2);
374
xvid_enc_frame.par_width = _param.par_width;
375
xvid_enc_frame.par_height = _param.par_height;
376
//printf("Using AR : %u x %u\n",xvid_enc_frame.par_width,xvid_enc_frame.par_height );
377
if (xvid_enc_frame.par_width != xvid_enc_frame.par_height)
378
xvid_enc_frame.par = XVID_PAR_EXT;
380
xvid_enc_frame.par = XVID_PAR_11_VGA;
382
/* Custome matrices */
383
if(_param.useCustomIntra)
385
if(!xvid_enc_frame.quant_intra_matrix)
386
printf("[Xvid4]Using custom intra matrix\n");
387
xvid_enc_frame.quant_intra_matrix=_param.intraMatrix;
389
if(_param.useCustomInter)
391
if(!xvid_enc_frame.quant_inter_matrix)
392
printf("[Xvid4]Using custom inter matrix\n");
393
xvid_enc_frame.quant_inter_matrix=_param.interMatrix;
399
xvid4Encoder::postAmble (ADMBitstream * out)
402
if (xvid_enc_frame.out_flags & XVID_KEYFRAME)
404
out->flags = AVI_KEY_FRAME;
406
else if (xvid_enc_stats.type == XVID_TYPE_BVOP)
408
out->flags = AVI_B_FRAME;
411
out->out_quantizer = xvid_enc_stats.quant;
412
out->ptsFrame= xvid_framenum;
416
// *************************************************
417
// *************************************************
419
// *************************************************
420
// *************************************************
422
xvid4EncoderCQ::init (uint32_t q, uint32_t fps1000, xvid4EncParam * param)
425
printf ("Using Xvid 4 codec with CQ mode = %lu (%dx%d)\n", q, _w, _h);
428
memcpy (&_param, param, sizeof (_param));
431
MMSET (xvid_enc_create);
432
xvid_enc_create.version = XVID_VERSION;
433
xvid_enc_create.width = _w;
434
xvid_enc_create.height = _h;
438
plugins[0].func = xvid_plugin_single;
439
plugins[0].param = &single;
441
plugins[1].func = adm_hook;
442
plugins[1].param = NULL;
445
single.version = XVID_VERSION;
446
single.bitrate = 1500;
448
xvid_enc_create.plugins = plugins;
449
xvid_enc_create.num_plugins = 2;
452
xvid_enc_create.fincr = 1000;
453
xvid_enc_create.fbase = _fps1000;
456
xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
459
printf ("Xvid-4 init error :%d\n", xerr);
464
_handle = xvid_enc_create.handle;
466
printf ("Xvid-4 CQ init Ok\n");
473
xvid4EncoderCQ::encode (ADMImage * in, ADMBitstream * out)
477
xvid_enc_frame.quant = _q;
478
return xvid4Encoder::encode(in,out);
481
// *************************************************
482
// *************************************************
483
// CQ but Q is controlled externally
484
// *************************************************
485
// *************************************************
488
xvid4EncoderVBRExternal::init (uint32_t q, uint32_t fps1000,
489
xvid4EncParam * param)
492
printf ("Using Xvid 4 codec with CQ mode = %lu (%dx%d)\n", q, _w, _h);
495
memcpy (&_param, param, sizeof (_param));
498
MMSET (xvid_enc_create);
499
xvid_enc_create.version = XVID_VERSION;
500
xvid_enc_create.width = _w;
501
xvid_enc_create.height = _h;
505
plugins[0].func = xvid_plugin_single;
506
plugins[0].param = &single;
508
plugins[1].func = adm_hook;
509
plugins[1].param = NULL;
511
single.version = XVID_VERSION;
512
single.bitrate = 1500;
514
xvid_enc_create.plugins = plugins;
515
xvid_enc_create.num_plugins = 2;
518
xvid_enc_create.fincr = 1000;
519
xvid_enc_create.fbase = _fps1000;
522
xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
525
printf ("Xvid-4 init error :%d\n", xerr);
530
_handle = xvid_enc_create.handle;
532
printf ("Xvid-4 CQ init Ok\n");
541
xvid4EncoderVBRExternal::encode (ADMImage * in,
544
xvid_enc_frame.quant = out->in_quantizer;
545
if (out->flags & AVI_KEY_FRAME)
547
xvid_enc_frame.type = XVID_TYPE_IVOP;
549
else if (out->flags & AVI_B_FRAME)
551
xvid_enc_frame.type = XVID_TYPE_BVOP;
555
xvid_enc_frame.type = XVID_TYPE_PVOP;
557
return xvid4Encoder::encode(in,out);
559
// *************************************************
560
// *************************************************
562
// *************************************************
563
// *************************************************
565
xvid4EncoderCBR::init (uint32_t br, uint32_t fps1000, xvid4EncParam * param)
568
printf ("Using Xvid 4 codec with CBR mode = %lu kbps\n", br);
571
memcpy (&_param, param, sizeof (_param));
575
MMSET (xvid_enc_create);
577
xvid_enc_create.version = XVID_VERSION;
578
xvid_enc_create.width = _w;
579
xvid_enc_create.height = _h;
582
plugins[0].func = xvid_plugin_single;
583
plugins[0].param = &single;
585
plugins[1].func = adm_hook;
586
plugins[1].param = NULL;
588
single.version = XVID_VERSION;
589
single.bitrate = _bitrate * 1000; // Kb->bit
591
xvid_enc_create.plugins = plugins;
592
xvid_enc_create.num_plugins = 2;
595
xvid_enc_create.fincr = 1000;
596
xvid_enc_create.fbase = _fps1000;
599
xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
602
printf ("Xvid-4 init error :%d\n", xerr);
607
_handle = xvid_enc_create.handle;
609
printf ("Xvid-4 CBR init Ok\n");
616
xvid4EncoderCBR::encode (ADMImage * in, ADMBitstream * out)
618
xvid_enc_frame.quant = 0;
619
return xvid4Encoder::encode(in,out);
621
// *************************************************
622
// *************************************************
624
// *************************************************
625
// *************************************************
627
xvid4EncoderPass1::init (uint32_t br, uint32_t fps1000,
628
xvid4EncParam * param)
631
printf ("Using Xvid 4 codec pass 1 of 2 (log: %s)\n",
632
(char *) param->logName);
635
memcpy (&_param, param, sizeof (_param));
638
MMSET (xvid_enc_create);
641
xvid_enc_create.version = XVID_VERSION;
642
xvid_enc_create.width = _w;
643
xvid_enc_create.height = _h;
647
plugins[0].func = xvid_plugin_2pass1;
648
plugins[0].param = &pass1;
651
pass1.version = XVID_VERSION;
652
pass1.filename = (char *) _param.logName;
654
xvid_enc_create.plugins = plugins;
655
xvid_enc_create.num_plugins = 1;
659
xvid_enc_create.fincr = 1000;
660
xvid_enc_create.fbase = _fps1000;
664
xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
667
printf ("Xvid-4 init error :%d\n", xerr);
672
_handle = xvid_enc_create.handle;
674
printf ("Xvid-4 Pass1 init Ok\n");
681
// *************************************************
682
// *************************************************
684
// *************************************************
685
// *************************************************
687
xvid4EncoderPass2::init (uint32_t br, uint32_t fps1000,
688
xvid4EncParam * param)
692
("Using Xvid 4 codec with 2pass mode pass 2 of 2, average bitrate = %lu\n",
696
memcpy (&_param, param, sizeof (_param));
699
MMSET (xvid_enc_create);
702
xvid_enc_create.version = XVID_VERSION;
703
xvid_enc_create.width = _w;
704
xvid_enc_create.height = _h;
708
plugins[0].func = xvid_plugin_2pass2;
709
plugins[0].param = &pass2;
710
plugins[1].func = adm_hook;
711
plugins[1].param = NULL;
713
pass2.version = XVID_VERSION;
714
pass2.filename = (char *) _param.logName;
716
pass2.bitrate = br; // Average bitrate
717
#define CPY(x) pass2.x=_param.x;printf(#x"=%d\n",pass2.x);
719
CPY (keyframe_boost);
720
CPY (curve_compression_high);
721
CPY (curve_compression_low);
722
CPY (overflow_control_strength);
723
CPY (max_overflow_improvement);
724
CPY (max_overflow_degradation);
728
CPY (container_frame_overhead);
732
xvid_enc_create.plugins = plugins;
733
xvid_enc_create.num_plugins = 2;
736
xvid_enc_create.fincr = 1000;
737
xvid_enc_create.fbase = _fps1000;
740
xerr = xvid_encore (NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
743
printf ("Xvid-4 init error :%d\n", xerr);
748
_handle = xvid_enc_create.handle;
750
printf ("Xvid-4 init Ok\n");