Revision 353e433b
libavcodec/ratecontrol.c  

793  793 
int i; 
794  794 
double fps= 1/av_q2d(s>avctx>time_base); 
795  795 
double complexity[5]={0,0,0,0,0}; // aproximate bits at quant=1 
796 
double avg_quantizer[5]; 

797  796 
uint64_t const_bits[5]={0,0,0,0,0}; // quantizer idependant bits 
798 
uint64_t available_bits[5]; 

799  797 
uint64_t all_const_bits; 
800  798 
uint64_t all_available_bits= (uint64_t)(s>bit_rate*(double)rcc>num_entries/fps); 
801  799 
double rate_factor=0; 
...  ...  
825  823 
return 1; 
826  824 
} 
827  825  
828 
/* find average quantizers */ 

829 
avg_quantizer[P_TYPE]=0; 

830 
for(step=256*256; step>0.0000001; step*=0.5){ 

831 
double expected_bits=0; 

832 
avg_quantizer[P_TYPE]+= step; 

833  
834 
avg_quantizer[I_TYPE]= avg_quantizer[P_TYPE]*ABS(s>avctx>i_quant_factor) + s>avctx>i_quant_offset; 

835 
avg_quantizer[B_TYPE]= avg_quantizer[P_TYPE]*ABS(s>avctx>b_quant_factor) + s>avctx>b_quant_offset; 

836  
837 
expected_bits= 

838 
+ all_const_bits 

839 
+ complexity[I_TYPE]/avg_quantizer[I_TYPE] 

840 
+ complexity[P_TYPE]/avg_quantizer[P_TYPE] 

841 
+ complexity[B_TYPE]/avg_quantizer[B_TYPE]; 

842  
843 
if(expected_bits < all_available_bits) avg_quantizer[P_TYPE]= step; 

844 
//printf("%f %lld %f\n", expected_bits, all_available_bits, avg_quantizer[P_TYPE]); 

845 
} 

846 
//printf("qp_i:%f, qp_p:%f, qp_b:%f\n", avg_quantizer[I_TYPE],avg_quantizer[P_TYPE],avg_quantizer[B_TYPE]); 

847  
848 
for(i=0; i<5; i++){ 

849 
available_bits[i]= const_bits[i] + complexity[i]/avg_quantizer[i]; 

850 
} 

851 
//printf("%lld %lld %lld %lld\n", available_bits[I_TYPE], available_bits[P_TYPE], available_bits[B_TYPE], all_available_bits); 

852  
853  826 
qscale= av_malloc(sizeof(double)*rcc>num_entries); 
854  827 
blured_qscale= av_malloc(sizeof(double)*rcc>num_entries); 
855  828 
Also available in: Unified diff