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));
362 int xerr, i,
ret = -1;
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");
498 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
499 xvid_enc_create.num_plugins++;
501 rc2pass2.
version = XVID_VERSION;
514 "Xvid: No 2-pass information loaded for second pass\n");
522 else if (strlen(avctx->
stats_in) > ret) {
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 =
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)
597 xvid_enc_create.min_quant[0] = avctx->
qmin;
598 xvid_enc_create.min_quant[1] = avctx->
qmin;
599 xvid_enc_create.min_quant[2] = avctx->
qmin;
600 xvid_enc_create.max_quant[0] = avctx->
qmax;
601 xvid_enc_create.max_quant[1] = avctx->
qmax;
602 xvid_enc_create.max_quant[2] = avctx->
qmax;
623 for (i = 0; i < 64; i++) {
632 xvid_enc_create.frame_drop_ratio = 0;
633 xvid_enc_create.global = 0;
635 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
656 xvid_enc_create.global |= XVID_GLOBAL_PACKED;
661 xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
681 const AVFrame *picture,
int *got_packet)
683 int xerr, i,
ret, user_packet = !!pkt->
data;
686 int mb_width = (avctx->
width + 15) / 16;
687 int mb_height = (avctx->
height + 15) / 16;
690 xvid_enc_frame_t xvid_enc_frame = { 0 };
691 xvid_enc_stats_t xvid_enc_stats = { 0 };
697 xvid_enc_frame.version = XVID_VERSION;
698 xvid_enc_stats.version = XVID_VERSION;
701 xvid_enc_frame.bitstream = pkt->
data;
702 xvid_enc_frame.length = pkt->
size;
707 "Xvid: Color spaces other than 420P not supported\n");
711 xvid_enc_frame.input.csp = XVID_CSP_PLANAR;
713 for (i = 0; i < 4; i++) {
714 xvid_enc_frame.input.plane[i] = picture->
data[i];
715 xvid_enc_frame.input.stride[i] = picture->
linesize[i];
721 xvid_enc_frame.motion = x->
me_flags;
722 xvid_enc_frame.type =
732 "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n",
737 xvid_enc_frame.par = XVID_PAR_EXT;
745 xvid_enc_frame.quant = 0;
753 &xvid_enc_frame, &xvid_enc_stats);
771 if (xvid_enc_stats.type == XVID_TYPE_PVOP)
773 else if (xvid_enc_stats.type == XVID_TYPE_BVOP)
775 else if (xvid_enc_stats.type == XVID_TYPE_SVOP)
779 if (xvid_enc_frame.out_flags & XVID_KEYFRAME) {
784 xvid_enc_stats.hlength, xerr);
797 "Xvid: Encoding Error Occurred: %i\n", xerr);
829 #define OFFSET(x) offsetof(struct xvid_context, x)
830 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM