54 |
#include <xvid.h> |
#include <xvid.h> |
55 |
#include "debug.h" |
#include "debug.h" |
56 |
#include "codec.h" |
#include "codec.h" |
57 |
|
#include "status.h" |
58 |
|
|
59 |
|
|
60 |
static const int pmvfast_presets[7] = { |
static const int pmvfast_presets[7] = { |
208 |
|
|
209 |
if (lpbiOutput == NULL) |
if (lpbiOutput == NULL) |
210 |
{ |
{ |
211 |
return sizeof(BITMAPV4HEADER); |
return sizeof(BITMAPINFOHEADER); |
212 |
} |
} |
213 |
|
|
214 |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
244 |
|
|
245 |
LRESULT compress_frames_info(CODEC * codec, ICCOMPRESSFRAMES * icf) |
LRESULT compress_frames_info(CODEC * codec, ICCOMPRESSFRAMES * icf) |
246 |
{ |
{ |
247 |
//DPRINTF("%i %i", icf->lStartFrame, icf->lFrameCount); |
#if 0 |
248 |
|
DPRINTF("%i %i", icf->lStartFrame, icf->lFrameCount); |
249 |
|
#endif |
250 |
codec->fincr = icf->dwScale; |
codec->fincr = icf->dwScale; |
251 |
codec->fbase = icf->dwRate; |
codec->fbase = icf->dwRate; |
252 |
return ICERR_OK; |
return ICERR_OK; |
313 |
memset(&init, 0, sizeof(init)); |
memset(&init, 0, sizeof(init)); |
314 |
init.version = XVID_VERSION; |
init.version = XVID_VERSION; |
315 |
init.cpu_flags = codec->config.cpu; |
init.cpu_flags = codec->config.cpu; |
316 |
|
init.debug = codec->config.debug; |
317 |
xvid_global(0, XVID_GBL_INIT, &init, NULL); |
xvid_global(0, XVID_GBL_INIT, &init, NULL); |
318 |
|
|
319 |
memset(&create, 0, sizeof(create)); |
memset(&create, 0, sizeof(create)); |
320 |
create.version = XVID_VERSION; |
create.version = XVID_VERSION; |
321 |
|
|
322 |
// zones |
/* zones */ |
323 |
create.zones = malloc(sizeof(xvid_enc_zone_t) * codec->config.num_zones); |
create.zones = malloc(sizeof(xvid_enc_zone_t) * codec->config.num_zones); |
324 |
create.num_zones = codec->config.num_zones; |
create.num_zones = codec->config.num_zones; |
325 |
for (i=0; i < create.num_zones; i++) { |
for (i=0; i < create.num_zones; i++) { |
326 |
create.zones[i].frame = codec->config.zones[i].frame; |
create.zones[i].frame = codec->config.zones[i].frame; |
327 |
if (create.zones[i].mode = RC_ZONE_QUANT) { |
if (codec->config.zones[i].mode == RC_ZONE_QUANT) { |
328 |
create.zones[i].mode = XVID_ZONE_QUANT; |
create.zones[i].mode = XVID_ZONE_QUANT; |
329 |
create.zones[i].increment = codec->config.zones[i].quant; |
create.zones[i].increment = codec->config.zones[i].quant; |
330 |
}else{ |
}else{ |
334 |
create.zones[i].base = 100; |
create.zones[i].base = 100; |
335 |
} |
} |
336 |
|
|
337 |
// plugins |
/* plugins */ |
338 |
create.plugins = plugins; |
create.plugins = plugins; |
339 |
switch (codec->config.mode) |
switch (codec->config.mode) |
340 |
{ |
{ |
341 |
case RC_MODE_1PASS : |
case RC_MODE_1PASS : |
342 |
memset(&single, 0, sizeof(single)); |
memset(&single, 0, sizeof(single)); |
343 |
single.version = XVID_VERSION; |
single.version = XVID_VERSION; |
344 |
single.bitrate = codec->config.bitrate; |
single.bitrate = codec->config.bitrate * CONFIG_KBPS; |
345 |
single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; |
single.reaction_delay_factor = codec->config.rc_reaction_delay_factor; |
346 |
single.averaging_period = codec->config.rc_averaging_period; |
single.averaging_period = codec->config.rc_averaging_period; |
347 |
single.buffer = codec->config.rc_buffer; |
single.buffer = codec->config.rc_buffer; |
348 |
plugins[create.num_plugins].func = xvid_plugin_single; |
plugins[create.num_plugins].func = xvid_plugin_single; |
349 |
plugins[create.num_plugins].param = &single; |
plugins[create.num_plugins].param = &single; |
350 |
create.num_plugins++; |
create.num_plugins++; |
351 |
|
break; |
352 |
|
|
353 |
case RC_MODE_2PASS1 : |
case RC_MODE_2PASS1 : |
354 |
memset(&pass1, 0, sizeof(pass1)); |
memset(&pass1, 0, sizeof(pass1)); |
355 |
pass1.version = XVID_VERSION; |
pass1.version = XVID_VERSION; |
356 |
|
pass1.filename = codec->config.stats; |
357 |
|
|
358 |
plugins[create.num_plugins].func = xvid_plugin_2pass1; |
plugins[create.num_plugins].func = xvid_plugin_2pass1; |
359 |
plugins[create.num_plugins].param = &pass1; |
plugins[create.num_plugins].param = &pass1; |
363 |
case RC_MODE_2PASS2 : |
case RC_MODE_2PASS2 : |
364 |
memset(&pass2, 0, sizeof(pass2)); |
memset(&pass2, 0, sizeof(pass2)); |
365 |
pass2.version = XVID_VERSION; |
pass2.version = XVID_VERSION; |
366 |
pass2.bitrate = codec->config.bitrate; |
if (codec->config.use_2pass_bitrate) { |
367 |
|
pass2.bitrate = codec->config.bitrate * CONFIG_KBPS; |
368 |
|
}else{ |
369 |
|
pass2.bitrate = -codec->config.desired_size; /* kilobytes */ |
370 |
|
} |
371 |
pass2.filename = codec->config.stats; |
pass2.filename = codec->config.stats; |
372 |
|
|
373 |
|
pass2.keyframe_boost = codec->config.keyframe_boost; /* keyframe boost percentage: [0..100...]; */ |
374 |
|
pass2.payback_method = codec->config.bitrate_payback_method; |
375 |
|
pass2.bitrate_payback_delay = codec->config.bitrate_payback_delay; |
376 |
|
pass2.curve_compression_high = codec->config.curve_compression_high; |
377 |
|
pass2.curve_compression_low = codec->config.curve_compression_low; |
378 |
|
pass2.max_overflow_improvement = codec->config.twopass_max_overflow_improvement; |
379 |
|
pass2.max_overflow_degradation = codec->config.twopass_max_overflow_degradation; |
380 |
|
pass2.kftreshold = codec->config.kftreshold; |
381 |
|
pass2.kfreduction = codec->config.kfreduction; |
382 |
|
pass2.min_key_interval = codec->config.min_key_interval; |
383 |
|
pass2.container_frame_overhead = 24; /* AVI */ |
384 |
|
|
385 |
plugins[create.num_plugins].func = xvid_plugin_2pass2; |
plugins[create.num_plugins].func = xvid_plugin_2pass2; |
386 |
plugins[create.num_plugins].param = &pass2; |
plugins[create.num_plugins].param = &pass2; |
387 |
create.num_plugins++; |
create.num_plugins++; |
456 |
codec->framenum = 0; |
codec->framenum = 0; |
457 |
codec->keyspacing = 0; |
codec->keyspacing = 0; |
458 |
|
|
459 |
|
if (codec->config.display_status) { |
460 |
|
status_destroy_always(&codec->status); |
461 |
|
status_create(&codec->status, codec->fincr, codec->fbase); |
462 |
|
} |
463 |
|
|
464 |
return ICERR_OK; |
return ICERR_OK; |
465 |
} |
} |
466 |
|
|
467 |
|
|
468 |
LRESULT compress_end(CODEC * codec) |
LRESULT compress_end(CODEC * codec) |
469 |
{ |
{ |
470 |
if (codec->ehandle != NULL) |
if (codec->ehandle != NULL) { |
|
{ |
|
471 |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
xvid_encore(codec->ehandle, XVID_ENC_DESTROY, NULL, NULL); |
472 |
codec->ehandle = NULL; |
codec->ehandle = NULL; |
473 |
} |
} |
474 |
|
|
475 |
|
if (codec->config.display_status) |
476 |
|
status_destroy(&codec->status); |
477 |
|
|
478 |
return ICERR_OK; |
return ICERR_OK; |
479 |
} |
} |
480 |
|
|
486 |
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++) ; |
487 |
i--; |
i--; |
488 |
|
|
489 |
|
frame->type = config->zones[i].type; |
490 |
|
|
491 |
if (config->zones[i].greyscale) { |
if (config->zones[i].greyscale) { |
492 |
frame->vop_flags |= XVID_VOP_GREYSCALE; |
frame->vop_flags |= XVID_VOP_GREYSCALE; |
493 |
} |
} |
542 |
frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; |
frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; |
543 |
} |
} |
544 |
|
|
545 |
if ((profiles[codec->config.profile].flags & PROFILE_GMC) && codec->config.gmc) |
if ((profiles[codec->config.profile].flags & PROFILE_GMC) && codec->config.gmc) { |
546 |
frame.vol_flags |= XVID_VOL_GMC; |
frame.vol_flags |= XVID_VOL_GMC; |
547 |
|
frame.motion |= XVID_ME_GME_REFINE; |
548 |
|
} |
549 |
|
|
550 |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) |
551 |
frame.vol_flags |= XVID_VOL_INTERLACING; |
frame.vol_flags |= XVID_VOL_INTERLACING; |
555 |
frame.vop_flags |= XVID_VOP_HALFPEL; |
frame.vop_flags |= XVID_VOP_HALFPEL; |
556 |
frame.vop_flags |= XVID_VOP_HQACPRED; |
frame.vop_flags |= XVID_VOP_HQACPRED; |
557 |
|
|
558 |
if (codec->config.debug) |
if (codec->config.vop_debug) |
559 |
frame.vop_flags |= XVID_VOP_DEBUG; |
frame.vop_flags |= XVID_VOP_DEBUG; |
560 |
|
|
561 |
if (codec->config.trellis_quant) { |
if (codec->config.trellis_quant) { |
566 |
frame.vop_flags |= XVID_VOP_INTER4V; |
frame.vop_flags |= XVID_VOP_INTER4V; |
567 |
|
|
568 |
if (codec->config.chromame) |
if (codec->config.chromame) |
569 |
frame.vop_flags |= XVID_ME_CHROMA16 + XVID_ME_CHROMA8; |
frame.motion |= XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP; |
570 |
|
|
571 |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
frame.motion |= pmvfast_presets[codec->config.motion_search]; |
572 |
|
|
573 |
switch (codec->config.vhq_mode) |
switch (codec->config.vhq_mode) |
574 |
{ |
{ |
575 |
case VHQ_MODE_DECISION : |
case VHQ_MODE_DECISION : |
576 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
577 |
break; |
break; |
578 |
|
|
579 |
case VHQ_LIMITED_SEARCH : |
case VHQ_LIMITED_SEARCH : |
580 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
581 |
frame.motion |= XVID_ME_HALFPELREFINE16_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE16_RD; |
582 |
frame.motion |= XVID_ME_QUARTERPELREFINE16_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE16_RD; |
583 |
break; |
break; |
584 |
|
|
585 |
case VHQ_MEDIUM_SEARCH : |
case VHQ_MEDIUM_SEARCH : |
586 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
587 |
frame.motion |= XVID_ME_HALFPELREFINE16_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE16_RD; |
588 |
frame.motion |= XVID_ME_HALFPELREFINE8_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE8_RD; |
589 |
frame.motion |= XVID_ME_QUARTERPELREFINE16_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE16_RD; |
590 |
frame.motion |= XVID_ME_QUARTERPELREFINE8_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE8_RD; |
591 |
frame.motion |= XVID_ME_CHECKPREDICTION_BITS; |
frame.motion |= XVID_ME_CHECKPREDICTION_RD; |
592 |
break; |
break; |
593 |
|
|
594 |
case VHQ_WIDE_SEARCH : |
case VHQ_WIDE_SEARCH : |
595 |
frame.vop_flags |= XVID_VOP_MODEDECISION_BITS; |
frame.vop_flags |= XVID_VOP_MODEDECISION_RD; |
596 |
frame.motion |= XVID_ME_HALFPELREFINE16_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE16_RD; |
597 |
frame.motion |= XVID_ME_HALFPELREFINE8_BITS; |
frame.motion |= XVID_ME_HALFPELREFINE8_RD; |
598 |
frame.motion |= XVID_ME_QUARTERPELREFINE16_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE16_RD; |
599 |
frame.motion |= XVID_ME_QUARTERPELREFINE8_BITS; |
frame.motion |= XVID_ME_QUARTERPELREFINE8_RD; |
600 |
frame.motion |= XVID_ME_CHECKPREDICTION_BITS; |
frame.motion |= XVID_ME_CHECKPREDICTION_RD; |
601 |
frame.motion |= XVID_ME_EXTSEARCH_BITS; |
frame.motion |= XVID_ME_EXTSEARCH_RD; |
602 |
break; |
break; |
603 |
|
|
604 |
default : |
default : |
660 |
return ICERR_UNSUPPORTED; |
return ICERR_UNSUPPORTED; |
661 |
} |
} |
662 |
|
|
663 |
|
if (codec->config.display_status && stats.type>0) { |
664 |
|
status_update(&codec->status, stats.type, stats.length, stats.quant); |
665 |
|
} |
666 |
|
|
667 |
DPRINTF("{type=%i len=%i} length=%i", stats.type, stats.length, length); |
DPRINTF("{type=%i len=%i} length=%i", stats.type, stats.length, length); |
668 |
|
|
669 |
if (length == 0) /* no encoder output */ |
if (length == 0) /* no encoder output */ |
747 |
|
|
748 |
if (get_colorspace(inhdr) != XVID_CSP_NULL) { |
if (get_colorspace(inhdr) != XVID_CSP_NULL) { |
749 |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
memcpy(outhdr, inhdr, sizeof(BITMAPINFOHEADER)); |
750 |
// XXX: should we set outhdr->biSize ?? |
/* XXX: should we set outhdr->biSize ?? */ |
751 |
return ICERR_OK; |
return ICERR_OK; |
752 |
} |
} |
753 |
/* --- yv12 --- */ |
/* --- yv12 --- */ |