57 #define BUFFER_SIZE 1024
58 #define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x))
59 #define BUFFER_CAT(x) (&((x)[strlen(x)]))
100 const AVFrame *picture,
int *got_packet);
127 return XVID_ERR_FAIL;
133 "# ffmpeg 2-pass log file, using xvid codec\n");
135 "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
136 XVID_VERSION_MAJOR(XVID_VERSION),
137 XVID_VERSION_MINOR(XVID_VERSION),
138 XVID_VERSION_PATCH(XVID_VERSION));
152 xvid_plg_destroy_t *param)
156 if (
ref->twopassbuffer)
157 ref->twopassbuffer[0] = 0;
169 xvid_plg_data_t *param)
172 int motion_replacements;
176 if (param->zone && param->zone->mode == XVID_ZONE_QUANT)
183 motion_remove = ~XVID_ME_CHROMA_PVOP &
184 ~XVID_ME_CHROMA_BVOP &
185 ~XVID_ME_EXTSEARCH16 &
186 ~XVID_ME_ADVANCEDDIAMOND16;
187 motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
188 XVID_ME_SKIP_DELTASEARCH |
189 XVID_ME_FASTREFINE16 |
190 XVID_ME_BFRAME_EARLYSTOP;
191 vop_remove = ~XVID_VOP_MODEDECISION_RD &
192 ~XVID_VOP_FAST_MODEDECISION_RD &
193 ~XVID_VOP_TRELLISQUANT &
197 param->vol_flags &= ~XVID_VOL_GMC;
198 param->vop_flags &= vop_remove;
199 param->motion_flags &= motion_remove;
200 param->motion_flags |= motion_replacements;
213 xvid_plg_data_t *param)
215 char *log =
ref->twopassbuffer;
216 const char *frame_types =
" ipbs";
221 return XVID_ERR_FAIL;
224 if (param->type < 5 && param->type > 0)
227 return XVID_ERR_FAIL;
230 "%c %d %d %d %d %d %d\n",
231 frame_type, param->stats.quant, param->stats.kblks,
232 param->stats.mblks, param->stats.ublks,
233 param->stats.length, param->stats.hlength);
255 case XVID_PLG_BEFORE:
257 case XVID_PLG_CREATE:
261 case XVID_PLG_DESTROY:
264 return XVID_ERR_FAIL;
282 unsigned int header_len,
283 unsigned int frame_len)
287 for (
i = 0;
i < header_len - 3;
i++) {
309 pkt->
size = frame_len - vo_len;
326 int est_frate, est_fbase;
333 gcd =
av_gcd(frate, fbase);
339 if (frate <= 65000 && fbase <= 65000) {
345 fps = (float) frate / (
float) fbase;
346 est_fps =
roundf(fps * 1000.0) / 1000.0;
348 est_frate = (
int) est_fps;
349 if (est_fps > (
int) est_fps) {
350 est_frate = (est_frate + 1) * 1000;
351 est_fbase = (
int)
roundf((
float) est_frate / est_fps);
355 gcd =
av_gcd(est_frate, est_fbase);
361 if (fbase > est_fbase) {
365 "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n",
366 est_fps, (((est_fps - fps) / fps) * 100.0));
375 int xerr,
i,
ret = -1;
376 int xvid_flags = avctx->
flags;
378 uint16_t *intra, *inter;
381 xvid_plugin_single_t single = { 0 };
383 xvid_plugin_2pass2_t rc2pass2 = { 0 };
384 xvid_plugin_lumimasking_t masking_l = { 0 };
385 xvid_plugin_lumimasking_t masking_v = { 0 };
386 xvid_plugin_ssim_t ssim = { 0 };
387 xvid_gbl_init_t xvid_gbl_init = { 0 };
388 xvid_enc_create_t xvid_enc_create = { 0 };
389 xvid_enc_plugin_t plugins[4];
409 x->
me_flags |= XVID_ME_EXTSEARCH16 |
413 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
414 XVID_ME_HALFPELREFINE8 |
415 XVID_ME_CHROMA_PVOP |
419 x->
me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
420 XVID_ME_HALFPELREFINE16;
426 x->
vop_flags |= XVID_VOP_MODEDECISION_RD;
427 x->
me_flags |= XVID_ME_HALFPELREFINE8_RD |
428 XVID_ME_QUARTERPELREFINE8_RD |
429 XVID_ME_EXTSEARCH_RD |
430 XVID_ME_CHECKPREDICTION_RD;
432 if (!(x->
vop_flags & XVID_VOP_MODEDECISION_RD))
433 x->
vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
434 x->
me_flags |= XVID_ME_HALFPELREFINE16_RD |
435 XVID_ME_QUARTERPELREFINE16_RD;
448 x->
me_flags |= XVID_ME_QUARTERPELREFINE16;
450 x->
me_flags |= XVID_ME_QUARTERPELREFINE8;
453 xvid_gbl_init.version = XVID_VERSION;
454 xvid_gbl_init.debug = 0;
455 xvid_gbl_init.cpu_flags = 0;
458 xvid_global(
NULL, XVID_GBL_INIT, &xvid_gbl_init,
NULL);
461 xvid_enc_create.version = XVID_VERSION;
464 xvid_enc_create.width =
466 xvid_enc_create.height =
473 xvid_enc_create.zones =
NULL;
474 xvid_enc_create.num_zones = 0;
477 #if (XVID_VERSION <= 0x010303) && (XVID_VERSION >= 0x010300)
479 if (avctx->
height <= 16) {
481 xvid_enc_create.num_threads = 0;
484 "Too small height for threads > 1.");
490 xvid_enc_create.plugins = plugins;
491 xvid_enc_create.num_plugins = 0;
499 rc2pass1.
version = XVID_VERSION;
505 "Xvid: Cannot allocate 2-pass log buffers\n");
512 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
513 xvid_enc_create.num_plugins++;
515 rc2pass2.
version = XVID_VERSION;
527 "Xvid: No 2-pass information loaded for second pass\n");
542 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2;
543 plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
544 xvid_enc_create.num_plugins++;
547 single.version = XVID_VERSION;
550 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single;
551 plugins[xvid_enc_create.num_plugins].param = &single;
552 xvid_enc_create.num_plugins++;
560 masking_l.method = 0;
561 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
565 plugins[xvid_enc_create.num_plugins].param =
567 xvid_enc_create.num_plugins++;
572 masking_v.method = 1;
573 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking;
574 plugins[xvid_enc_create.num_plugins].param = &masking_v;
575 xvid_enc_create.num_plugins++;
580 "Both lumi_aq and variance_aq are enabled. The resulting quality"
581 "will be the worse one of the two effects made by the AQ.\n");
585 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_ssim;
586 ssim.b_printstat = x->
ssim == 2;
588 ssim.cpu_flags = xvid_gbl_init.cpu_flags;
589 ssim.b_visualize = 0;
590 plugins[xvid_enc_create.num_plugins].param = &ssim;
591 xvid_enc_create.num_plugins++;
599 xvid_enc_create.max_key_interval = avctx->
gop_size;
601 xvid_enc_create.max_key_interval = 240;
609 xvid_enc_create.min_quant[0] = avctx->
qmin;
610 xvid_enc_create.min_quant[1] = avctx->
qmin;
611 xvid_enc_create.min_quant[2] = avctx->
qmin;
612 xvid_enc_create.max_quant[0] = avctx->
qmax;
613 xvid_enc_create.max_quant[1] = avctx->
qmax;
614 xvid_enc_create.max_quant[2] = avctx->
qmax;
640 for (
i = 0;
i < 64;
i++) {
649 xvid_enc_create.frame_drop_ratio = 0;
650 xvid_enc_create.global = 0;
652 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
673 xvid_enc_create.global |= XVID_GLOBAL_PACKED;
681 int size, got_packet;
693 xerr = xvid_encore(
NULL, XVID_ENC_CREATE, &xvid_enc_create,
NULL);
703 if (!picture->
data[0]) {
711 memset(picture->
data[1], 128,
size / 2);
720 xerr = xvid_encore(
NULL, XVID_ENC_CREATE, &xvid_enc_create,
NULL);
732 const AVFrame *picture,
int *got_packet)
736 int mb_width = (avctx->
width + 15) / 16;
737 int mb_height = (avctx->
height + 15) / 16;
740 xvid_enc_frame_t xvid_enc_frame = { 0 };
741 xvid_enc_stats_t xvid_enc_stats = { 0 };
747 xvid_enc_frame.version = XVID_VERSION;
748 xvid_enc_stats.version = XVID_VERSION;
751 xvid_enc_frame.bitstream =
pkt->
data;
752 xvid_enc_frame.length =
pkt->
size;
757 "Xvid: Color spaces other than 420P not supported\n");
761 xvid_enc_frame.input.csp = XVID_CSP_PLANAR;
763 for (
i = 0;
i < 4;
i++) {
764 xvid_enc_frame.input.plane[
i] = picture->
data[
i];
765 xvid_enc_frame.input.stride[
i] = picture->
linesize[
i];
771 xvid_enc_frame.motion = x->
me_flags;
772 xvid_enc_frame.type =
782 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
787 xvid_enc_frame.par = XVID_PAR_EXT;
795 xvid_enc_frame.quant = 0;
803 &xvid_enc_frame, &xvid_enc_stats);
822 if (xvid_enc_stats.type == XVID_TYPE_PVOP)
824 else if (xvid_enc_stats.type == XVID_TYPE_BVOP)
826 else if (xvid_enc_stats.type == XVID_TYPE_SVOP)
833 if (xvid_enc_frame.out_flags & XVID_KEYFRAME) {
837 xvid_enc_stats.hlength, xerr);
847 "Xvid: Encoding Error Occurred: %i\n", xerr);
878 #define OFFSET(x) offsetof(struct xvid_context, x)
879 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
914 .wrapper_name =
"libxvid",