Revision 577cd173

View differences:

libavcodec/ratecontrol.c
790 790
{
791 791
    RateControlContext *rcc= &s->rc_context;
792 792
    AVCodecContext *a= s->avctx;
793
    int i;
793
    int i, toobig;
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 796
    uint64_t const_bits[5]={0,0,0,0,0}; // quantizer idependant bits
......
801 801
    //int last_i_frame=-10000000;
802 802
    const int filter_size= (int)(a->qblur*4) | 1;
803 803
    double expected_bits;
804
    double *qscale, *blured_qscale;
804
    double *qscale, *blured_qscale, qscale_sum;
805 805

  
806 806
    /* find complexity & const_bits & decide the pict_types */
807 807
    for(i=0; i<rcc->num_entries; i++){
......
825 825

  
826 826
    qscale= av_malloc(sizeof(double)*rcc->num_entries);
827 827
    blured_qscale= av_malloc(sizeof(double)*rcc->num_entries);
828
    toobig = 0;
828 829

  
829 830
    for(step=256*256; step>0.0000001; step*=0.5){
830 831
        expected_bits=0;
......
878 879
            expected_bits += bits;
879 880
        }
880 881

  
881
//        printf("%f %d %f\n", expected_bits, (int)all_available_bits, rate_factor);
882
        if(expected_bits > all_available_bits) rate_factor-= step;
882
        /*
883
        av_log(s->avctx, AV_LOG_INFO,
884
            "expected_bits: %f all_available_bits: %d rate_factor: %f\n",
885
            expected_bits, (int)all_available_bits, rate_factor);
886
        */
887
        if(expected_bits > all_available_bits) {
888
            rate_factor-= step;
889
            ++toobig;
890
        }
883 891
    }
884 892
    av_free(qscale);
885 893
    av_free(blured_qscale);
886 894

  
887
    if(fabs(expected_bits/all_available_bits - 1.0) > 0.01 ){
888
        av_log(s->avctx, AV_LOG_ERROR, "Error: 2pass curve failed to converge\n");
895
    /* check bitrate calculations and print info */
896
    qscale_sum = 0.0;
897
    for(i=0; i<rcc->num_entries; i++){
898
        /* av_log(s->avctx, AV_LOG_DEBUG, "[lavc rc] entry[%d].new_qscale = %.3f  qp = %.3f\n",
899
            i, rcc->entry[i].new_qscale, rcc->entry[i].new_qscale / FF_QP2LAMBDA); */
900
        qscale_sum += clip(rcc->entry[i].new_qscale / FF_QP2LAMBDA, s->avctx->qmin, s->avctx->qmax);
901
    }
902
    assert(toobig <= 40);
903
    av_log(s->avctx, AV_LOG_DEBUG,
904
        "[lavc rc] requested bitrate: %d bps  expected bitrate: %d bps\n",
905
        s->bit_rate,
906
        (int)(expected_bits / ((double)all_available_bits/s->bit_rate)));
907
    av_log(s->avctx, AV_LOG_DEBUG,
908
        "[lavc rc] estimated target average qp: %.3f\n",
909
        (float)qscale_sum / rcc->num_entries);
910
    if (toobig == 0) {
911
        av_log(s->avctx, AV_LOG_INFO,
912
            "[lavc rc] Using all of requested bitrate is not "
913
            "necessary for this video with these parameters.\n");
914
    } else if (toobig == 40) {
915
        av_log(s->avctx, AV_LOG_ERROR,
916
            "[lavc rc] Error: bitrate too low for this video "
917
            "with these parameters.\n");
918
        return -1;
919
    } else if (fabs(expected_bits/all_available_bits - 1.0) > 0.01) {
920
        av_log(s->avctx, AV_LOG_ERROR,
921
            "[lavc rc] Error: 2pass curve failed to converge\n");
889 922
        return -1;
890 923
    }
891 924

  

Also available in: Unified diff