25 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27 |
* |
* |
28 |
* $Id: plugin_2pass2.c,v 1.1.2.15 2003-05-29 11:37:20 edgomez Exp $ |
* $Id: plugin_2pass2.c,v 1.1.2.17 2003-05-29 13:53:17 edgomez Exp $ |
29 |
* |
* |
30 |
*****************************************************************************/ |
*****************************************************************************/ |
31 |
|
|
600 |
if (capped_to_max_framesize == 0) |
if (capped_to_max_framesize == 0) |
601 |
rc->last_quant[s->type-1] = data->quant; |
rc->last_quant[s->type-1] = data->quant; |
602 |
|
|
603 |
|
/* Force frame type */ |
604 |
|
data->type = s->type; |
605 |
|
|
606 |
return 0; |
return 0; |
607 |
} |
} |
608 |
|
|
876 |
int64_t pass1_length = rc->tot_length[0] + rc->tot_length[1] + rc->tot_length[2] - rc->tot_quant; |
int64_t pass1_length = rc->tot_length[0] + rc->tot_length[1] + rc->tot_length[2] - rc->tot_quant; |
877 |
double scaler; |
double scaler; |
878 |
int i, num_MBs; |
int i, num_MBs; |
|
int min_size[3]; |
|
879 |
|
|
880 |
/* Let's compute a linear scaler in order to perform curve scaling */ |
/* Let's compute a linear scaler in order to perform curve scaling */ |
881 |
scaler = (double)target / (double)pass1_length; |
scaler = (double)target / (double)pass1_length; |
893 |
* Compute min frame lengths (for each frame type) according to the number |
* Compute min frame lengths (for each frame type) according to the number |
894 |
* of MBs. We sum all blocks count from frame 0 (should be an IFrame, so |
* of MBs. We sum all blocks count from frame 0 (should be an IFrame, so |
895 |
* blocks[0] should be enough) to know how many MBs there are. |
* blocks[0] should be enough) to know how many MBs there are. |
896 |
|
* |
897 |
|
* We compare these hardcoded values with observed values in first pass |
898 |
|
* (determined in pre_process0).Then we keep the real minimum. |
899 |
*/ |
*/ |
900 |
num_MBs = rc->stats[0].blks[0] + rc->stats[0].blks[1] + rc->stats[0].blks[2]; |
num_MBs = rc->stats[0].blks[0] + rc->stats[0].blks[1] + rc->stats[0].blks[2]; |
901 |
min_size[0] = ((num_MBs*22) + 240) / 8; |
|
902 |
min_size[1] = ((num_MBs) + 88) / 8; |
if(rc->min_length[0] > ((num_MBs*22) + 240) / 8) |
903 |
min_size[2] = 8; |
rc->min_length[0] = ((num_MBs*22) + 240) / 8; |
904 |
|
|
905 |
|
if(rc->min_length[1] > ((num_MBs) + 88) / 8) |
906 |
|
rc->min_length[1] = ((num_MBs) + 88) / 8; |
907 |
|
|
908 |
|
if(rc->min_length[2] > 8) |
909 |
|
rc->min_length[2] = 8; |
910 |
|
|
911 |
/* |
/* |
912 |
* Perform an initial scale pass. |
* Perform an initial scale pass. |
927 |
len = (int)((double)s->length * scaler * s->weight / rc->avg_weight); |
len = (int)((double)s->length * scaler * s->weight / rc->avg_weight); |
928 |
|
|
929 |
/* Compare with the computed minimum */ |
/* Compare with the computed minimum */ |
930 |
if (len < min_size[s->type-1]) { |
if (len < rc->min_length[s->type-1]) { |
931 |
/* force frame size to our computed minimum */ |
/* force frame size to our computed minimum */ |
932 |
s->scaled_length = min_size[s->type-1]; |
s->scaled_length = rc->min_length[s->type-1]; |
933 |
target -= s->scaled_length; |
target -= s->scaled_length; |
934 |
pass1_length -= s->length; |
pass1_length -= s->length; |
935 |
} else { |
} else { |