45 #define BUFFER_SIZE 1024
46 #define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x))
47 #define BUFFER_CAT(x) (&((x)[strlen(x)]))
110 return XVID_ERR_FAIL;
116 "# ffmpeg 2-pass log file, using xvid codec\n");
118 "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
119 XVID_VERSION_MAJOR(XVID_VERSION),
120 XVID_VERSION_MINOR(XVID_VERSION),
121 XVID_VERSION_PATCH(XVID_VERSION));
135 xvid_plg_destroy_t *param) {
151 xvid_plg_data_t *param) {
153 int motion_replacements;
157 if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
164 motion_remove = ~XVID_ME_CHROMA_PVOP &
165 ~XVID_ME_CHROMA_BVOP &
166 ~XVID_ME_EXTSEARCH16 &
167 ~XVID_ME_ADVANCEDDIAMOND16;
168 motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
169 XVID_ME_SKIP_DELTASEARCH |
170 XVID_ME_FASTREFINE16 |
171 XVID_ME_BFRAME_EARLYSTOP;
172 vop_remove = ~XVID_VOP_MODEDECISION_RD &
173 ~XVID_VOP_FAST_MODEDECISION_RD &
174 ~XVID_VOP_TRELLISQUANT &
178 param->vol_flags &= ~XVID_VOL_GMC;
179 param->vop_flags &= vop_remove;
180 param->motion_flags &= motion_remove;
181 param->motion_flags |= motion_replacements;
194 xvid_plg_data_t *param) {
196 const char *frame_types =
" ipbs";
201 return XVID_ERR_FAIL;
204 if( param->type < 5 && param->type > 0 ) {
205 frame_type = frame_types[param->type];
207 return XVID_ERR_FAIL;
211 "%c %d %d %d %d %d %d\n",
212 frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
213 param->stats.ublks, param->stats.length, param->stats.hlength);
236 case XVID_PLG_BEFORE:
239 case XVID_PLG_CREATE:
245 case XVID_PLG_DESTROY:
249 return XVID_ERR_FAIL;
268 unsigned int header_len,
269 unsigned int frame_len) {
272 for( i = 0; i < header_len - 3; i++ ) {
273 if( pkt->
data[i] == 0x00 &&
274 pkt->
data[i+1] == 0x00 &&
275 pkt->
data[i+2] == 0x01 &&
276 pkt->
data[i+3] == 0xB6 ) {
291 memmove(pkt->
data, &pkt->
data[vo_len], frame_len - vo_len);
292 pkt->
size = frame_len - vo_len;
309 int est_frate, est_fbase;
316 gcd =
av_gcd(frate, fbase);
322 if( frate <= 65000 && fbase <= 65000 ) {
328 fps = (float)frate / (
float)fbase;
329 est_fps =
roundf(fps * 1000.0) / 1000.0;
331 est_frate = (int)est_fps;
332 if( est_fps > (
int)est_fps ) {
333 est_frate = (est_frate + 1) * 1000;
334 est_fbase = (int)
roundf((
float)est_frate / est_fps);
338 gcd =
av_gcd(est_frate, est_fbase);
344 if( fbase > est_fbase ) {
348 "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n",
349 est_fps, (((est_fps - fps)/fps) * 100.0));
358 int xvid_flags = avctx->
flags;
360 uint16_t *intra, *inter;
363 xvid_plugin_single_t single = { 0 };
365 xvid_plugin_2pass2_t rc2pass2 = { 0 };
366 xvid_plugin_lumimasking_t masking_l = { 0 };
367 xvid_plugin_lumimasking_t masking_v = { 0 };
368 xvid_plugin_ssim_t ssim = { 0 };
369 xvid_gbl_init_t xvid_gbl_init = { 0 };
370 xvid_enc_create_t xvid_enc_create = { 0 };
371 xvid_enc_plugin_t plugins[4];
391 | XVID_ME_EXTSEARCH8;
394 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND8
395 | XVID_ME_HALFPELREFINE8
396 | XVID_ME_CHROMA_PVOP
397 | XVID_ME_CHROMA_BVOP;
402 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND16
403 | XVID_ME_HALFPELREFINE16;
413 x->
vop_flags |= XVID_VOP_MODEDECISION_RD;
414 x->
me_flags |= XVID_ME_HALFPELREFINE8_RD
415 | XVID_ME_QUARTERPELREFINE8_RD
416 | XVID_ME_EXTSEARCH_RD
417 | XVID_ME_CHECKPREDICTION_RD;
419 if( !(x->
vop_flags & XVID_VOP_MODEDECISION_RD) )
420 x->
vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
421 x->
me_flags |= XVID_ME_HALFPELREFINE16_RD
422 | XVID_ME_QUARTERPELREFINE16_RD;
441 x->
me_flags |= XVID_ME_QUARTERPELREFINE16;
443 x->
me_flags |= XVID_ME_QUARTERPELREFINE8;
446 xvid_gbl_init.version = XVID_VERSION;
447 xvid_gbl_init.debug = 0;
453 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
456 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
459 xvid_gbl_init.cpu_flags = 0;
463 xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
466 xvid_enc_create.version = XVID_VERSION;
469 xvid_enc_create.width = x->
xsize = avctx->
width;
476 xvid_enc_create.zones = NULL;
477 xvid_enc_create.num_zones = 0;
481 xvid_enc_create.plugins = plugins;
482 xvid_enc_create.num_plugins = 0;
490 rc2pass1.
version = XVID_VERSION;
496 "Xvid: Cannot allocate 2-pass log buffers\n");
502 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
503 xvid_enc_create.num_plugins++;
505 rc2pass2.
version = XVID_VERSION;
511 "Xvid: Cannot write 2-pass pipe\n");
518 "Xvid: No 2-pass information loaded for second pass\n");
525 "Xvid: Cannot write to 2-pass pipe\n");
530 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
531 plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
532 xvid_enc_create.num_plugins++;
535 single.version = XVID_VERSION;
538 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
539 plugins[xvid_enc_create.num_plugins].param = &single;
540 xvid_enc_create.num_plugins++;
548 masking_l.method = 0;
549 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
553 plugins[xvid_enc_create.num_plugins].param = avctx->
lumi_masking ? NULL
555 xvid_enc_create.num_plugins++;
560 masking_v.method = 1;
561 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
562 plugins[xvid_enc_create.num_plugins].param = &masking_v;
563 xvid_enc_create.num_plugins++;
568 "Both lumi_aq and variance_aq are enabled. The resulting quality"
569 "will be the worse one of the two effects made by the AQ.\n");
573 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim;
574 ssim.b_printstat = x->
ssim == 2;
576 ssim.cpu_flags = xvid_gbl_init.cpu_flags;
577 ssim.b_visualize = 0;
578 plugins[xvid_enc_create.num_plugins].param = &ssim;
579 xvid_enc_create.num_plugins++;
587 xvid_enc_create.max_key_interval = avctx->
gop_size;
589 xvid_enc_create.max_key_interval = 240;
592 if( xvid_flags & CODEC_FLAG_QSCALE ) x->
qscale = 1;
595 xvid_enc_create.min_quant[0] = avctx->
qmin;
596 xvid_enc_create.min_quant[1] = avctx->
qmin;
597 xvid_enc_create.min_quant[2] = avctx->
qmin;
598 xvid_enc_create.max_quant[0] = avctx->
qmax;
599 xvid_enc_create.max_quant[1] = avctx->
qmax;
600 xvid_enc_create.max_quant[2] = avctx->
qmax;
620 for( i = 0; i < 64; i++ ) {
629 xvid_enc_create.frame_drop_ratio = 0;
630 xvid_enc_create.global = 0;
632 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
657 xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
675 const AVFrame *picture,
int *got_packet)
677 int xerr, i,
ret, user_packet = !!pkt->
data;
681 int mb_width = (avctx->
width + 15) / 16;
682 int mb_height = (avctx->
height + 15) / 16;
684 xvid_enc_frame_t xvid_enc_frame = { 0 };
685 xvid_enc_stats_t xvid_enc_stats = { 0 };
691 xvid_enc_frame.version = XVID_VERSION;
692 xvid_enc_stats.version = XVID_VERSION;
695 xvid_enc_frame.bitstream = pkt->
data;
696 xvid_enc_frame.length = pkt->
size;
704 xvid_enc_frame.input.csp = XVID_CSP_PLANAR;
706 for( i = 0; i < 4; i++ ) {
707 xvid_enc_frame.input.plane[i] = picture->
data[i];
708 xvid_enc_frame.input.stride[i] = picture->
linesize[i];
714 xvid_enc_frame.motion = x->
me_flags;
715 xvid_enc_frame.type =
725 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
730 xvid_enc_frame.par = XVID_PAR_EXT;
736 else xvid_enc_frame.quant = 0;
744 &xvid_enc_frame, &xvid_enc_stats);
762 if( xvid_enc_stats.type == XVID_TYPE_PVOP )
764 else if( xvid_enc_stats.type == XVID_TYPE_BVOP )
766 else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
770 if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
775 xvid_enc_stats.hlength, xerr);
817 #define OFFSET(x) offsetof(struct xvid_context, x)
818 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM