42 #define BUFFER_SIZE 1024
43 #define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x))
44 #define BUFFER_CAT(x) (&((x)[strlen(x)]))
105 "# ffmpeg 2-pass log file, using xvid codec\n");
107 "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
108 XVID_VERSION_MAJOR(XVID_VERSION),
109 XVID_VERSION_MINOR(XVID_VERSION),
110 XVID_VERSION_PATCH(XVID_VERSION));
124 xvid_plg_destroy_t *param) {
140 xvid_plg_data_t *param) {
142 int motion_replacements;
146 if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
153 motion_remove = ~XVID_ME_CHROMA_PVOP &
154 ~XVID_ME_CHROMA_BVOP &
155 ~XVID_ME_EXTSEARCH16 &
156 ~XVID_ME_ADVANCEDDIAMOND16;
157 motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
158 XVID_ME_SKIP_DELTASEARCH |
159 XVID_ME_FASTREFINE16 |
160 XVID_ME_BFRAME_EARLYSTOP;
161 vop_remove = ~XVID_VOP_MODEDECISION_RD &
162 ~XVID_VOP_FAST_MODEDECISION_RD &
163 ~XVID_VOP_TRELLISQUANT &
167 param->vol_flags &= ~XVID_VOL_GMC;
168 param->vop_flags &= vop_remove;
169 param->motion_flags &= motion_remove;
170 param->motion_flags |= motion_replacements;
183 xvid_plg_data_t *param) {
185 const char *frame_types =
" ipbs";
190 return XVID_ERR_FAIL;
193 if( param->type < 5 && param->type > 0 ) {
194 frame_type = frame_types[param->type];
196 return XVID_ERR_FAIL;
200 "%c %d %d %d %d %d %d\n",
201 frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
202 param->stats.ublks, param->stats.length, param->stats.hlength);
225 case XVID_PLG_BEFORE:
228 case XVID_PLG_CREATE:
234 case XVID_PLG_DESTROY:
238 return XVID_ERR_FAIL;
257 unsigned int header_len,
258 unsigned int frame_len) {
261 for( i = 0; i < header_len - 3; i++ ) {
262 if( pkt->
data[i] == 0x00 &&
263 pkt->
data[i+1] == 0x00 &&
264 pkt->
data[i+2] == 0x01 &&
265 pkt->
data[i+3] == 0xB6 ) {
280 memmove(pkt->
data, &pkt->
data[vo_len], frame_len - vo_len);
281 pkt->
size = frame_len - vo_len;
298 int est_frate, est_fbase;
305 gcd =
av_gcd(frate, fbase);
311 if( frate <= 65000 && fbase <= 65000 ) {
317 fps = (float)frate / (
float)fbase;
318 est_fps =
roundf(fps * 1000.0) / 1000.0;
320 est_frate = (int)est_fps;
321 if( est_fps > (
int)est_fps ) {
322 est_frate = (est_frate + 1) * 1000;
323 est_fbase = (int)
roundf((
float)est_frate / est_fps);
327 gcd =
av_gcd(est_frate, est_fbase);
333 if( fbase > est_fbase ) {
337 "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n",
338 est_fps, (((est_fps - fps)/fps) * 100.0));
347 int xvid_flags = avctx->
flags;
349 uint16_t *intra, *inter;
352 xvid_plugin_single_t single = { 0 };
354 xvid_plugin_2pass2_t rc2pass2 = { 0 };
355 xvid_gbl_init_t xvid_gbl_init = { 0 };
356 xvid_enc_create_t xvid_enc_create = { 0 };
357 xvid_enc_plugin_t plugins[7];
376 | XVID_ME_EXTSEARCH8;
379 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND8
380 | XVID_ME_HALFPELREFINE8
381 | XVID_ME_CHROMA_PVOP
382 | XVID_ME_CHROMA_BVOP;
387 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND16
388 | XVID_ME_HALFPELREFINE16;
398 x->
vop_flags |= XVID_VOP_MODEDECISION_RD;
399 x->
me_flags |= XVID_ME_HALFPELREFINE8_RD
400 | XVID_ME_QUARTERPELREFINE8_RD
401 | XVID_ME_EXTSEARCH_RD
402 | XVID_ME_CHECKPREDICTION_RD;
404 if( !(x->
vop_flags & XVID_VOP_MODEDECISION_RD) )
405 x->
vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
406 x->
me_flags |= XVID_ME_HALFPELREFINE16_RD
407 | XVID_ME_QUARTERPELREFINE16_RD;
421 x->
me_flags |= XVID_ME_QUARTERPELREFINE16;
423 x->
me_flags |= XVID_ME_QUARTERPELREFINE8;
426 xvid_gbl_init.version = XVID_VERSION;
427 xvid_gbl_init.debug = 0;
433 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
436 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
439 xvid_gbl_init.cpu_flags = 0;
443 xvid_global(
NULL, XVID_GBL_INIT, &xvid_gbl_init,
NULL);
446 xvid_enc_create.version = XVID_VERSION;
449 xvid_enc_create.width = x->
xsize = avctx->
width;
456 xvid_enc_create.zones =
NULL;
457 xvid_enc_create.num_zones = 0;
461 xvid_enc_create.plugins = plugins;
462 xvid_enc_create.num_plugins = 0;
470 rc2pass1.
version = XVID_VERSION;
476 "Xvid: Cannot allocate 2-pass log buffers\n");
482 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
483 xvid_enc_create.num_plugins++;
485 rc2pass2.
version = XVID_VERSION;
491 "Xvid: Cannot write 2-pass pipe\n");
497 "Xvid: No 2-pass information loaded for second pass\n");
505 "Xvid: Cannot write to 2-pass pipe\n");
511 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
512 plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
513 xvid_enc_create.num_plugins++;
516 single.version = XVID_VERSION;
519 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
520 plugins[xvid_enc_create.num_plugins].param = &single;
521 xvid_enc_create.num_plugins++;
526 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
527 plugins[xvid_enc_create.num_plugins].param =
NULL;
528 xvid_enc_create.num_plugins++;
536 xvid_enc_create.max_key_interval = avctx->
gop_size;
538 xvid_enc_create.max_key_interval = 240;
541 if( xvid_flags & CODEC_FLAG_QSCALE ) x->
qscale = 1;
544 xvid_enc_create.min_quant[0] = avctx->
qmin;
545 xvid_enc_create.min_quant[1] = avctx->
qmin;
546 xvid_enc_create.min_quant[2] = avctx->
qmin;
547 xvid_enc_create.max_quant[0] = avctx->
qmax;
548 xvid_enc_create.max_quant[1] = avctx->
qmax;
549 xvid_enc_create.max_quant[2] = avctx->
qmax;
569 for( i = 0; i < 64; i++ ) {
578 xvid_enc_create.frame_drop_ratio = 0;
579 xvid_enc_create.global = 0;
581 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
604 xerr = xvid_encore(
NULL, XVID_ENC_CREATE, &xvid_enc_create,
NULL);
617 const AVFrame *picture,
int *got_packet)
619 int xerr, i, ret, user_packet = !!pkt->
data;
623 int mb_width = (avctx->
width + 15) / 16;
624 int mb_height = (avctx->
height + 15) / 16;
626 xvid_enc_frame_t xvid_enc_frame = { 0 };
627 xvid_enc_stats_t xvid_enc_stats = { 0 };
633 xvid_enc_frame.version = XVID_VERSION;
634 xvid_enc_stats.version = XVID_VERSION;
638 xvid_enc_frame.bitstream = pkt->
data;
639 xvid_enc_frame.length = pkt->
size;
647 xvid_enc_frame.input.csp = XVID_CSP_PLANAR;
649 for( i = 0; i < 4; i++ ) {
650 xvid_enc_frame.input.plane[i] = picture->
data[i];
651 xvid_enc_frame.input.stride[i] = picture->
linesize[i];
657 xvid_enc_frame.motion = x->
me_flags;
658 xvid_enc_frame.type =
671 xvid_enc_frame.par = XVID_PAR_EXT;
677 else xvid_enc_frame.quant = 0;
685 &xvid_enc_frame, &xvid_enc_stats);
703 if( xvid_enc_stats.type == XVID_TYPE_PVOP )
705 else if( xvid_enc_stats.type == XVID_TYPE_BVOP )
707 else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
711 if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
716 xvid_enc_stats.hlength, xerr);