49 |
|
|
50 |
#include <windows.h> |
#include <windows.h> |
51 |
#include <vfw.h> |
#include <vfw.h> |
52 |
|
#include <stdio.h> |
53 |
#include "vfwext.h" |
#include "vfwext.h" |
54 |
|
|
55 |
#include <xvid.h> |
#include <xvid.h> |
56 |
#include "debug.h" |
#include "debug.h" |
57 |
#include "codec.h" |
#include "codec.h" |
58 |
|
#include "status.h" |
59 |
|
|
60 |
|
|
61 |
static const int pmvfast_presets[7] = { |
static const int pmvfast_presets[7] = { |
209 |
|
|
210 |
if (lpbiOutput == NULL) |
if (lpbiOutput == NULL) |
211 |
{ |
{ |
212 |
return sizeof(BITMAPV4HEADER); |
return sizeof(BITMAPINFOHEADER); |
213 |
} |
} |
214 |
|
|
215 |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
245 |
|
|
246 |
LRESULT compress_frames_info(CODEC * codec, ICCOMPRESSFRAMES * icf) |
LRESULT compress_frames_info(CODEC * codec, ICCOMPRESSFRAMES * icf) |
247 |
{ |
{ |
248 |
//DPRINTF("%i %i", icf->lStartFrame, icf->lFrameCount); |
#if 0 |
249 |
|
DPRINTF("%i %i", icf->lStartFrame, icf->lFrameCount); |
250 |
|
#endif |
251 |
codec->fincr = icf->dwScale; |
codec->fincr = icf->dwScale; |
252 |
codec->fbase = icf->dwRate; |
codec->fbase = icf->dwRate; |
253 |
return ICERR_OK; |
return ICERR_OK; |
281 |
{ |
{ |
282 |
xvid_plg_data_t *data = (xvid_plg_data_t *) param1; |
xvid_plg_data_t *data = (xvid_plg_data_t *) param1; |
283 |
|
|
284 |
DPRINTF("[%5i] type=%c Q:%2i length:%6i", |
/* We don't use DPRINTF here because it's active only for _DEBUG |
285 |
|
* builds and that activates lot of other debug printfs. We only |
286 |
|
* want these all the time */ |
287 |
|
char buf[1024]; |
288 |
|
sprintf(buf, "[%6i] type=%c Q:%2i length:%6i", |
289 |
data->frame_num, |
data->frame_num, |
290 |
type2char(data->type), |
type2char(data->type), |
291 |
data->quant, |
data->quant, |
292 |
data->length); |
data->length); |
293 |
|
OutputDebugString(buf); |
294 |
|
|
295 |
return 0; |
return 0; |
296 |
} |
} |
297 |
} |
} |
326 |
memset(&create, 0, sizeof(create)); |
memset(&create, 0, sizeof(create)); |
327 |
create.version = XVID_VERSION; |
create.version = XVID_VERSION; |
328 |
|
|
329 |
// zones |
/* zones */ |
330 |
create.zones = malloc(sizeof(xvid_enc_zone_t) * codec->config.num_zones); |
create.zones = malloc(sizeof(xvid_enc_zone_t) * codec->config.num_zones); |
331 |
create.num_zones = codec->config.num_zones; |
create.num_zones = codec->config.num_zones; |
332 |
for (i=0; i < create.num_zones; i++) { |
for (i=0; i < create.num_zones; i++) { |
341 |
create.zones[i].base = 100; |
create.zones[i].base = 100; |
342 |
} |
} |
343 |
|
|
344 |
// plugins |
/* plugins */ |
345 |
create.plugins = plugins; |
create.plugins = plugins; |
346 |
switch (codec->config.mode) |
switch (codec->config.mode) |
347 |
{ |
{ |
370 |
case RC_MODE_2PASS2 : |
case RC_MODE_2PASS2 : |
371 |
memset(&pass2, 0, sizeof(pass2)); |
memset(&pass2, 0, sizeof(pass2)); |
372 |
pass2.version = XVID_VERSION; |
pass2.version = XVID_VERSION; |
373 |
|
if (codec->config.use_2pass_bitrate) { |
374 |
pass2.bitrate = codec->config.bitrate * CONFIG_KBPS; |
pass2.bitrate = codec->config.bitrate * CONFIG_KBPS; |
375 |
|
}else{ |
376 |
|
pass2.bitrate = -codec->config.desired_size; /* kilobytes */ |
377 |
|
} |
378 |
pass2.filename = codec->config.stats; |
pass2.filename = codec->config.stats; |
379 |
pass2.container_frame_overhead = 24; |
|
380 |
|
pass2.keyframe_boost = codec->config.keyframe_boost; /* keyframe boost percentage: [0..100...]; */ |
381 |
|
pass2.curve_compression_high = codec->config.curve_compression_high; |
382 |
|
pass2.curve_compression_low = codec->config.curve_compression_low; |
383 |
|
pass2.overflow_control_strength = codec->config.overflow_control_strength; |
384 |
|
pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; |
385 |
|
pass2.max_overflow_degradation = codec->config.twopass_max_overflow_degradation; |
386 |
|
pass2.kfreduction = codec->config.kfreduction; |
387 |
|
pass2.kfthreshold = codec->config.kfthreshold; |
388 |
|
pass2.container_frame_overhead = 24; /* AVI */ |
389 |
|
|
390 |
plugins[create.num_plugins].func = xvid_plugin_2pass2; |
plugins[create.num_plugins].func = xvid_plugin_2pass2; |
391 |
plugins[create.num_plugins].param = &pass2; |
plugins[create.num_plugins].param = &pass2; |
461 |
codec->framenum = 0; |
codec->framenum = 0; |
462 |
codec->keyspacing = 0; |
codec->keyspacing = 0; |
463 |
|
|
464 |
|
if (codec->config.display_status) { |
465 |
|
status_destroy_always(&codec->status); |
466 |
|
status_create(&codec->status, codec->fincr, codec->fbase); |
467 |
|
} |
468 |
|
|
469 |
return ICERR_OK; |
return ICERR_OK; |
470 |
} |
} |
471 |
|
|
472 |
|
|
473 |
LRESULT compress_end(CODEC * codec) |
LRESULT compress_end(CODEC * codec) |
474 |
{ |
{ |
475 |
if (codec->ehandle != NULL) |
if (codec->ehandle != NULL) { |
|
{ |
|
476 |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
477 |
codec->ehandle = NULL; |
codec->ehandle = NULL; |
478 |
} |
} |
479 |
|
|
480 |
|
if (codec->config.display_status) |
481 |
|
status_destroy(&codec->status); |
482 |
|
|
483 |
return ICERR_OK; |
return ICERR_OK; |
484 |
} |
} |
485 |
|
|
489 |
int i; |
int i; |
490 |
|
|
491 |
for (i=0; i<config->num_zones && config->zones[i].frame <= framenum; i++) ; |
for (i=0; i<config->num_zones && config->zones[i].frame <= framenum; i++) ; |
492 |
i--; |
|
493 |
|
if (--i < 0) return; /* there are no zones, or we're before the first zone */ |
494 |
|
|
495 |
|
if (framenum == config->zones[i].frame) |
496 |
|
frame->type = config->zones[i].type; |
497 |
|
|
498 |
if (config->zones[i].greyscale) { |
if (config->zones[i].greyscale) { |
499 |
frame->vop_flags |= XVID_VOP_GREYSCALE; |
frame->vop_flags |= XVID_VOP_GREYSCALE; |
549 |
frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; |
frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; |
550 |
} |
} |
551 |
|
|
552 |
if ((profiles[codec->config.profile].flags & PROFILE_GMC) && codec->config.gmc) |
if ((profiles[codec->config.profile].flags & PROFILE_GMC) && codec->config.gmc) { |
553 |
frame.vol_flags |= XVID_VOL_GMC; |
frame.vol_flags |= XVID_VOL_GMC; |
554 |
|
frame.motion |= XVID_ME_GME_REFINE; |
555 |
|
} |
556 |
|
|
557 |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
558 |
frame.vol_flags |= XVID_VOL_INTERLACING; |
frame.vol_flags |= XVID_VOL_INTERLACING; |
559 |
|
|
560 |
|
if (codec->config.ar_mode == 0) { /* PAR */ |
561 |
|
if (codec->config.display_aspect_ratio != 5) { |
562 |
|
frame.par = codec->config.display_aspect_ratio + 1; |
563 |
|
} else { |
564 |
|
frame.par = XVID_PAR_EXT; |
565 |
|
frame.par_width = codec->config.par_x; |
566 |
|
frame.par_height= codec->config.par_y; |
567 |
|
} |
568 |
|
} else { /* AR */ |
569 |
|
/* custom pixel aspect ratio -> calculated from DAR */ |
570 |
|
frame.par = XVID_PAR_EXT; |
571 |
|
frame.par_width = (100 * inhdr->biHeight) / codec->config.ar_y; |
572 |
|
frame.par_height= (100 * inhdr->biWidth) / codec->config.ar_x; |
573 |
|
} |
574 |
|
|
575 |
/* vop stuff */ |
/* vop stuff */ |
576 |
|
|
577 |
frame.vop_flags |= XVID_VOP_HALFPEL; |
frame.vop_flags |= XVID_VOP_HALFPEL; |
588 |
frame.vop_flags |= XVID_VOP_INTER4V; |
frame.vop_flags |= XVID_VOP_INTER4V; |
589 |
|
|
590 |
if (codec->config.chromame) |
if (codec->config.chromame) |
591 |
frame.vop_flags |= XVID_ME_CHROMA16 + XVID_ME_CHROMA8; |
frame.motion |= XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP; |
592 |
|
|
593 |
|
if (codec->config.cartoon_mode) { |
594 |
|
frame.vop_flags |= XVID_VOP_CARTOON; |
595 |
|
frame.motion |= XVID_ME_DETECT_STATIC_MOTION; |
596 |
|
} |
597 |
|
|
598 |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
599 |
|
|
600 |
switch (codec->config.vhq_mode) |
switch (codec->config.vhq_mode) |
601 |
{ |
{ |
602 |
case VHQ_MODE_DECISION : |
case VHQ_MODE_DECISION : |
603 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
604 |
break; |
break; |
605 |
|
|
606 |
case VHQ_LIMITED_SEARCH : |
case VHQ_LIMITED_SEARCH : |
607 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
608 |
frame.motion |= XVID_ME_HALFPELREFINE16_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE16_RD; |
609 |
frame.motion |= XVID_ME_QUARTERPELREFINE16_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE16_RD; |
610 |
break; |
break; |
611 |
|
|
612 |
case VHQ_MEDIUM_SEARCH : |
case VHQ_MEDIUM_SEARCH : |
613 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
614 |
frame.motion |= XVID_ME_HALFPELREFINE16_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE16_RD; |
615 |
frame.motion |= XVID_ME_HALFPELREFINE8_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE8_RD; |
616 |
frame.motion |= XVID_ME_QUARTERPELREFINE16_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE16_RD; |
617 |
frame.motion |= XVID_ME_QUARTERPELREFINE8_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE8_RD; |
618 |
frame.motion |= XVID_ME_CHECKPREDICTION_BITS; |
frame.motion |= XVID_ME_CHECKPREDICTION_RD; |
619 |
break; |
break; |
620 |
|
|
621 |
case VHQ_WIDE_SEARCH : |
case VHQ_WIDE_SEARCH : |
622 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
623 |
frame.motion |= XVID_ME_HALFPELREFINE16_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE16_RD; |
624 |
frame.motion |= XVID_ME_HALFPELREFINE8_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE8_RD; |
625 |
frame.motion |= XVID_ME_QUARTERPELREFINE16_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE16_RD; |
626 |
frame.motion |= XVID_ME_QUARTERPELREFINE8_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE8_RD; |
627 |
frame.motion |= XVID_ME_CHECKPREDICTION_BITS; |
frame.motion |= XVID_ME_CHECKPREDICTION_RD; |
628 |
frame.motion |= XVID_ME_EXTSEARCH_BITS; |
frame.motion |= XVID_ME_EXTSEARCH_RD; |
629 |
break; |
break; |
630 |
|
|
631 |
default : |
default : |
654 |
|
|
655 |
// force keyframe spacing in 2-pass 1st pass |
// force keyframe spacing in 2-pass 1st pass |
656 |
if (codec->config.motion_search == 0) |
if (codec->config.motion_search == 0) |
|
{ |
|
657 |
frame.type = XVID_TYPE_IVOP; |
frame.type = XVID_TYPE_IVOP; |
|
} |
|
|
else if (codec->keyspacing < codec->config.min_key_interval && codec->framenum) |
|
|
{ |
|
|
DPRINTF("current frame forced to p-frame"); |
|
|
frame.type = XVID_TYPE_PVOP; |
|
|
} |
|
658 |
|
|
659 |
/* frame-based stuff */ |
/* frame-based stuff */ |
660 |
apply_zone_modifiers(&frame, &codec->config, codec->framenum); |
apply_zone_modifiers(&frame, &codec->config, codec->framenum); |
680 |
return ICERR_UNSUPPORTED; |
return ICERR_UNSUPPORTED; |
681 |
} |
} |
682 |
|
|
683 |
|
if (codec->config.display_status && stats.type>0) { |
684 |
|
status_update(&codec->status, stats.type, stats.length, stats.quant); |
685 |
|
} |
686 |
|
|
687 |
DPRINTF("{type=%i len=%i} length=%i", stats.type, stats.length, length); |
DPRINTF("{type=%i len=%i} length=%i", stats.type, stats.length, length); |
688 |
|
|
689 |
if (length == 0) /* no encoder output */ |
if (length == 0) /* no encoder output */ |
767 |
|
|
768 |
if (get_colorspace(inhdr) != XVID_CSP_NULL) { |
if (get_colorspace(inhdr) != XVID_CSP_NULL) { |
769 |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
770 |
// XXX: should we set outhdr->biSize ?? |
/* XXX: should we set outhdr->biSize ?? */ |
771 |
return ICERR_OK; |
return ICERR_OK; |
772 |
} |
} |
773 |
/* --- yv12 --- */ |
/* --- yv12 --- */ |