51 #define BUFFER_SIZE 1024
52 #define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x))
53 #define BUFFER_CAT(x) (&((x)[strlen(x)]))
116 return XVID_ERR_FAIL;
122 "# ffmpeg 2-pass log file, using xvid codec\n");
124 "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
125 XVID_VERSION_MAJOR(XVID_VERSION),
126 XVID_VERSION_MINOR(XVID_VERSION),
127 XVID_VERSION_PATCH(XVID_VERSION));
141 xvid_plg_destroy_t *param)
158 xvid_plg_data_t *param)
161 int motion_replacements;
165 if (param->zone && param->zone->mode == XVID_ZONE_QUANT)
172 motion_remove = ~XVID_ME_CHROMA_PVOP &
173 ~XVID_ME_CHROMA_BVOP &
174 ~XVID_ME_EXTSEARCH16 &
175 ~XVID_ME_ADVANCEDDIAMOND16;
176 motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
177 XVID_ME_SKIP_DELTASEARCH |
178 XVID_ME_FASTREFINE16 |
179 XVID_ME_BFRAME_EARLYSTOP;
180 vop_remove = ~XVID_VOP_MODEDECISION_RD &
181 ~XVID_VOP_FAST_MODEDECISION_RD &
182 ~XVID_VOP_TRELLISQUANT &
186 param->vol_flags &= ~XVID_VOL_GMC;
187 param->vop_flags &= vop_remove;
188 param->motion_flags &= motion_remove;
189 param->motion_flags |= motion_replacements;
202 xvid_plg_data_t *param)
205 const char *frame_types =
" ipbs";
210 return XVID_ERR_FAIL;
213 if (param->type < 5 && param->type > 0)
214 frame_type = frame_types[param->type];
216 return XVID_ERR_FAIL;
219 "%c %d %d %d %d %d %d\n",
220 frame_type, param->stats.quant, param->stats.kblks,
221 param->stats.mblks, param->stats.ublks,
222 param->stats.length, param->stats.hlength);
244 case XVID_PLG_BEFORE:
246 case XVID_PLG_CREATE:
250 case XVID_PLG_DESTROY:
253 return XVID_ERR_FAIL;
271 unsigned int header_len,
272 unsigned int frame_len)
276 for (i = 0; i < header_len - 3; i++) {
277 if (pkt->
data[i] == 0x00 &&
278 pkt->
data[i + 1] == 0x00 &&
279 pkt->
data[i + 2] == 0x01 &&
280 pkt->
data[i + 3] == 0xB6) {
295 memmove(pkt->
data, &pkt->
data[vo_len], frame_len - vo_len);
296 pkt->
size = frame_len - vo_len;
313 int est_frate, est_fbase;
320 gcd =
av_gcd(frate, fbase);
326 if (frate <= 65000 && fbase <= 65000) {
332 fps = (float) frate / (
float) fbase;
333 est_fps =
roundf(fps * 1000.0) / 1000.0;
335 est_frate = (int) est_fps;
336 if (est_fps > (
int) est_fps) {
337 est_frate = (est_frate + 1) * 1000;
338 est_fbase = (int)
roundf((
float) est_frate / est_fps);
342 gcd =
av_gcd(est_frate, est_fbase);
348 if (fbase > est_fbase) {
352 "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n",
353 est_fps, (((est_fps - fps) / fps) * 100.0));
363 int xvid_flags = avctx->
flags;
365 uint16_t *intra, *inter;
368 xvid_plugin_single_t single = { 0 };
370 xvid_plugin_2pass2_t rc2pass2 = { 0 };
371 xvid_plugin_lumimasking_t masking_l = { 0 };
372 xvid_plugin_lumimasking_t masking_v = { 0 };
373 xvid_plugin_ssim_t ssim = { 0 };
374 xvid_gbl_init_t xvid_gbl_init = { 0 };
375 xvid_enc_create_t xvid_enc_create = { 0 };
376 xvid_enc_plugin_t plugins[4];
395 x->
me_flags |= XVID_ME_EXTSEARCH16 |
399 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
400 XVID_ME_HALFPELREFINE8 |
401 XVID_ME_CHROMA_PVOP |
407 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
408 XVID_ME_HALFPELREFINE16;
418 x->
vop_flags |= XVID_VOP_MODEDECISION_RD;
419 x->
me_flags |= XVID_ME_HALFPELREFINE8_RD |
420 XVID_ME_QUARTERPELREFINE8_RD |
421 XVID_ME_EXTSEARCH_RD |
422 XVID_ME_CHECKPREDICTION_RD;
424 if (!(x->
vop_flags & XVID_VOP_MODEDECISION_RD))
425 x->
vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
426 x->
me_flags |= XVID_ME_HALFPELREFINE16_RD |
427 XVID_ME_QUARTERPELREFINE16_RD;
445 x->
me_flags |= XVID_ME_QUARTERPELREFINE16;
447 x->
me_flags |= XVID_ME_QUARTERPELREFINE8;
450 xvid_gbl_init.version = XVID_VERSION;
451 xvid_gbl_init.debug = 0;
452 xvid_gbl_init.cpu_flags = 0;
455 xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
458 xvid_enc_create.version = XVID_VERSION;
461 xvid_enc_create.width =
463 xvid_enc_create.height =
470 xvid_enc_create.zones = NULL;
471 xvid_enc_create.num_zones = 0;
475 xvid_enc_create.plugins = plugins;
476 xvid_enc_create.num_plugins = 0;
484 rc2pass1.
version = XVID_VERSION;
490 "Xvid: Cannot allocate 2-pass log buffers\n");
497 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
498 xvid_enc_create.num_plugins++;
500 rc2pass2.
version = XVID_VERSION;
512 "Xvid: No 2-pass information loaded for second pass\n");
523 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
524 plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
525 xvid_enc_create.num_plugins++;
528 single.version = XVID_VERSION;
531 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
532 plugins[xvid_enc_create.num_plugins].param = &single;
533 xvid_enc_create.num_plugins++;
541 masking_l.method = 0;
542 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
546 plugins[xvid_enc_create.num_plugins].param =
548 xvid_enc_create.num_plugins++;
553 masking_v.method = 1;
554 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
555 plugins[xvid_enc_create.num_plugins].param = &masking_v;
556 xvid_enc_create.num_plugins++;
561 "Both lumi_aq and variance_aq are enabled. The resulting quality"
562 "will be the worse one of the two effects made by the AQ.\n");
566 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim;
567 ssim.b_printstat = x->
ssim == 2;
569 ssim.cpu_flags = xvid_gbl_init.cpu_flags;
570 ssim.b_visualize = 0;
571 plugins[xvid_enc_create.num_plugins].param = &ssim;
572 xvid_enc_create.num_plugins++;
580 xvid_enc_create.max_key_interval = avctx->
gop_size;
582 xvid_enc_create.max_key_interval = 240;
585 if (xvid_flags & CODEC_FLAG_QSCALE)
590 xvid_enc_create.min_quant[0] = avctx->
qmin;
591 xvid_enc_create.min_quant[1] = avctx->
qmin;
592 xvid_enc_create.min_quant[2] = avctx->
qmin;
593 xvid_enc_create.max_quant[0] = avctx->
qmax;
594 xvid_enc_create.max_quant[1] = avctx->
qmax;
595 xvid_enc_create.max_quant[2] = avctx->
qmax;
616 for (i = 0; i < 64; i++) {
625 xvid_enc_create.frame_drop_ratio = 0;
626 xvid_enc_create.global = 0;
628 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
649 xvid_enc_create.global |= XVID_GLOBAL_PACKED;
654 xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
672 const AVFrame *picture,
int *got_packet)
674 int xerr, i,
ret, user_packet = !!pkt->
data;
677 int mb_width = (avctx->
width + 15) / 16;
678 int mb_height = (avctx->
height + 15) / 16;
681 xvid_enc_frame_t xvid_enc_frame = { 0 };
682 xvid_enc_stats_t xvid_enc_stats = { 0 };
688 xvid_enc_frame.version = XVID_VERSION;
689 xvid_enc_stats.version = XVID_VERSION;
692 xvid_enc_frame.bitstream = pkt->
data;
693 xvid_enc_frame.length = pkt->
size;
698 "Xvid: Color spaces other than 420P not supported\n");
702 xvid_enc_frame.input.csp = XVID_CSP_PLANAR;
704 for (i = 0; i < 4; i++) {
705 xvid_enc_frame.input.plane[i] = picture->
data[i];
706 xvid_enc_frame.input.stride[i] = picture->
linesize[i];
712 xvid_enc_frame.motion = x->
me_flags;
713 xvid_enc_frame.type =
723 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
728 xvid_enc_frame.par = XVID_PAR_EXT;
736 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);
788 "Xvid: Encoding Error Occurred: %i\n", xerr);
819 #define OFFSET(x) offsetof(struct xvid_context, x)
820 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM