337 |
|
|
338 |
twopass->movie_curve = ((double)(bframe_total_ext + pframe_total_ext + i_boost_total) / |
twopass->movie_curve = ((double)(bframe_total_ext + pframe_total_ext + i_boost_total) / |
339 |
(bframe_total_ext + pframe_total_ext)); |
(bframe_total_ext + pframe_total_ext)); |
340 |
|
|
341 |
|
if (bframes) |
342 |
twopass->average_bframe = (double)bframe_total_ext / bframes / twopass->movie_curve; |
twopass->average_bframe = (double)bframe_total_ext / bframes / twopass->movie_curve; |
343 |
|
|
344 |
|
if (pframes) |
345 |
twopass->average_pframe = (double)pframe_total_ext / pframes / twopass->movie_curve; |
twopass->average_pframe = (double)pframe_total_ext / pframes / twopass->movie_curve; |
346 |
|
else |
347 |
|
if (bframes) |
348 |
|
twopass->average_pframe = twopass->average_bframe; // b-frame packed bitstream fix |
349 |
|
else |
350 |
|
{ |
351 |
|
DEBUGERR("ERROR: No p-frames or b-frames were present in the 1st pass. Rate control cannot function properly!"); |
352 |
|
return ICERR_ERROR; |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
|
660 |
break; |
break; |
661 |
} |
} |
662 |
|
|
663 |
|
if (bframes) |
664 |
twopass->average_bframe = (double)bframe_total / bframes / twopass->movie_curve; |
twopass->average_bframe = (double)bframe_total / bframes / twopass->movie_curve; |
665 |
|
|
666 |
|
if (pframes) |
667 |
twopass->average_pframe = (double)pframe_total / pframes / twopass->movie_curve; |
twopass->average_pframe = (double)pframe_total / pframes / twopass->movie_curve; |
668 |
|
else |
669 |
|
if (bframes) |
670 |
|
twopass->average_pframe = twopass->average_bframe; // b-frame packed bitstream fix |
671 |
|
else |
672 |
|
{ |
673 |
|
DEBUGERR("ERROR: No p-frames or b-frames were present in the 1st pass. Rate control cannot function properly!"); |
674 |
|
return ICERR_ERROR; |
675 |
|
} |
676 |
|
|
677 |
|
|
678 |
|
|
989 |
if (twopass->nns_array_pos >= twopass->nns_array_length) |
if (twopass->nns_array_pos >= twopass->nns_array_length) |
990 |
{ |
{ |
991 |
twopass->nns_array_pos = 0; |
twopass->nns_array_pos = 0; |
992 |
DEBUG("ERROR: VIDEO EXCEEDS 1ST PASS!!!"); |
DEBUGERR("ERROR: VIDEO EXCEEDS 1ST PASS!!!"); |
993 |
frame->intra = -1; |
return ICERR_ERROR; |
|
return 2; |
|
994 |
} |
} |
995 |
|
|
996 |
memcpy(&twopass->nns1, &twopass->nns1_array[twopass->nns_array_pos], sizeof(NNSTATS)); |
memcpy(&twopass->nns1, &twopass->nns1_array[twopass->nns_array_pos], sizeof(NNSTATS)); |
1192 |
} |
} |
1193 |
} |
} |
1194 |
} |
} |
|
curve_temp = curve_temp * twopass->curve_comp_scale + twopass->curve_bias_bonus; |
|
|
|
|
1195 |
if (twopass->nns1.dd_v & NNSTATS_BFRAME) |
if (twopass->nns1.dd_v & NNSTATS_BFRAME) |
1196 |
curve_temp *= twopass->average_bframe / twopass->average_pframe; |
curve_temp *= twopass->average_bframe / twopass->average_pframe; |
1197 |
|
|
1198 |
|
curve_temp = curve_temp * twopass->curve_comp_scale + twopass->curve_bias_bonus; |
1199 |
|
|
1200 |
bytes2 += ((int)curve_temp); |
bytes2 += ((int)curve_temp); |
1201 |
curve_comp_error += curve_temp - ((int)curve_temp); |
curve_comp_error += curve_temp - ((int)curve_temp); |
1202 |
} |
} |
1452 |
|
|
1453 |
if (capped_to_max_framesize == 0) |
if (capped_to_max_framesize == 0) |
1454 |
{ |
{ |
1455 |
if (twopass->nns1.dd_v & NNSTATS_BFRAME) |
if (twopass->nns1.quant & NNSTATS_KEYFRAME) |
1456 |
|
{ |
1457 |
|
last_bquant = frame->quant; |
1458 |
|
last_pquant = frame->quant; |
1459 |
|
} |
1460 |
|
else if (twopass->nns1.dd_v & NNSTATS_BFRAME) |
1461 |
last_bquant = frame->quant; |
last_bquant = frame->quant; |
1462 |
else |
else |
1463 |
last_pquant = frame->quant; |
last_pquant = frame->quant; |
1615 |
else if (codec->twopass.nns1.dd_v & NNSTATS_SKIPFRAME) { |
else if (codec->twopass.nns1.dd_v & NNSTATS_SKIPFRAME) { |
1616 |
frame_type="skipped"; |
frame_type="skipped"; |
1617 |
frame->quant = 2; |
frame->quant = 2; |
1618 |
codec->twopass.bytes1 = 8; |
codec->twopass.bytes1 = 1; |
1619 |
codec->twopass.desired_bytes2 = 8; |
codec->twopass.desired_bytes2 = 1; |
1620 |
frame->length = 8; |
frame->length = 1; |
1621 |
} |
} |
1622 |
else if (codec->twopass.nns1.dd_v & NNSTATS_PADFRAME) { |
else if (codec->twopass.nns1.dd_v & NNSTATS_PADFRAME) { |
1623 |
frame_type="padded"; |
frame_type="padded"; |
1624 |
frame->quant = 2; |
frame->quant = 2; |
1625 |
codec->twopass.bytes1 = 8; |
codec->twopass.bytes1 = 7; |
1626 |
codec->twopass.desired_bytes2 = 8; |
codec->twopass.desired_bytes2 = 7; |
1627 |
frame->length = 8; |
frame->length = 7; |
1628 |
} |
} |
1629 |
else if (codec->twopass.nns1.dd_v & NNSTATS_DELAYFRAME) { |
else if (codec->twopass.nns1.dd_v & NNSTATS_DELAYFRAME) { |
1630 |
frame_type="delayed"; |
frame_type="delayed"; |
1631 |
frame->quant = 2; |
frame->quant = 2; |
1632 |
codec->twopass.bytes1 = 8; |
codec->twopass.bytes1 = 1; |
1633 |
codec->twopass.desired_bytes2 = 8; |
codec->twopass.desired_bytes2 = 1; |
1634 |
frame->length = 8; |
frame->length = 1; |
1635 |
} |
} |
1636 |
|
|
1637 |
DEBUG2ND(frame->quant, quant_type, frame_type, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos) |
DEBUG2ND(frame->quant, quant_type, frame_type, codec->twopass.bytes1, codec->twopass.desired_bytes2, frame->length, codec->twopass.overflow, credits_pos) |
1650 |
char s[100]; |
char s[100]; |
1651 |
|
|
1652 |
if (codec->twopass.nns1_array) |
if (codec->twopass.nns1_array) |
1653 |
|
{ |
1654 |
free(codec->twopass.nns1_array); |
free(codec->twopass.nns1_array); |
1655 |
|
codec->twopass.nns1_array = NULL; |
1656 |
|
} |
1657 |
if (codec->twopass.nns2_array) |
if (codec->twopass.nns2_array) |
1658 |
|
{ |
1659 |
free(codec->twopass.nns2_array); |
free(codec->twopass.nns2_array); |
1660 |
|
codec->twopass.nns2_array = NULL; |
1661 |
|
} |
1662 |
codec->twopass.nns_array_size = 0; |
codec->twopass.nns_array_size = 0; |
1663 |
codec->twopass.nns_array_length = 0; |
codec->twopass.nns_array_length = 0; |
1664 |
codec->twopass.nns_array_pos = 0; |
codec->twopass.nns_array_pos = 0; |