Revision b7b5bccb

View differences:

libavcodec/ffv1.c
742 742
        int sye= f->avctx->height*(sy+1) / f->num_v_slices;
743 743
        f->slice_context[i]= fs;
744 744
        memcpy(fs, f, sizeof(*fs));
745
        memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
745 746

  
746 747
        fs->slice_width = sxe - sxs;
747 748
        fs->slice_height= sye - sys;
......
869 870
static av_cold int encode_init(AVCodecContext *avctx)
870 871
{
871 872
    FFV1Context *s = avctx->priv_data;
872
    int i, j;
873
    int i, j, k, m;
873 874

  
874 875
    common_init(avctx);
875 876

  
......
950 951

  
951 952
    s->picture_number=0;
952 953

  
954
    if(avctx->flags & (CODEC_FLAG_PASS1|CODEC_FLAG_PASS2)){
955
        for(i=0; i<s->quant_table_count; i++){
956
            s->rc_stat2[i]= av_mallocz(s->context_count[i]*sizeof(*s->rc_stat2[i]));
957
            if(!s->rc_stat2[i])
958
                return AVERROR(ENOMEM);
959
        }
960
    }
953 961
    if(avctx->stats_in){
954 962
        char *p= avctx->stats_in;
955 963

  
964
        av_assert0(s->version>=2);
965

  
956 966
        for(;;){
957 967
            for(j=0; j<256; j++){
958 968
                for(i=0; i<2; i++){
......
965 975
                    p=next;
966 976
                }
967 977
            }
978
            for(i=0; i<s->quant_table_count; i++){
979
                for(j=0; j<s->context_count[i]; j++){
980
                    for(k=0; k<32; k++){
981
                        for(m=0; m<2; m++){
982
                            char *next;
983
                            s->rc_stat2[i][j][k][m]= strtol(p, &next, 0);
984
                            if(next==p){
985
                                av_log(avctx, AV_LOG_ERROR, "2Pass file invalid at %d %d %d %d [%s]\n", i,j,k,m,p);
986
                                return -1;
987
                            }
988
                            p=next;
989
                        }
990
                    }
991
                }
992
            }
968 993
            while(*p=='\n' || *p==' ') p++;
969 994
            if(p[0]==0) break;
970 995
        }
971 996
        sort_stt(s, s->state_transition);
997

  
998
        for(i=0; i<s->quant_table_count; i++){
999
            for(j=0; j<s->context_count[i]; j++){
1000
                for(k=0; k<32; k++){
1001
                    int p= 128;
1002
                    if(s->rc_stat2[i][j][k][0]+s->rc_stat2[i][j][k][1]){
1003
                        p=256*s->rc_stat2[i][j][k][1] / (s->rc_stat2[i][j][k][0]+s->rc_stat2[i][j][k][1]);
1004
                    }
1005
                    p= av_clip(p, 1, 254);
1006
                    s->initial_states[i][j][k]= p;
1007
                }
1008
            }
1009
        }
972 1010
    }
973 1011

  
974 1012
    if(s->version>1){
......
982 1020
    if(init_slice_state(s) < 0)
983 1021
        return -1;
984 1022

  
985
#define STATS_OUT_SIZE 1024*30
1023
#define STATS_OUT_SIZE 1024*1024*6
986 1024
    if(avctx->flags & CODEC_FLAG_PASS1){
987 1025
    avctx->stats_out= av_mallocz(STATS_OUT_SIZE);
988 1026
        for(i=0; i<s->quant_table_count; i++){
......
1133 1171
    }
1134 1172

  
1135 1173
    if((avctx->flags&CODEC_FLAG_PASS1) && (f->picture_number&31)==0){
1136
        int j;
1174
        int j, k, m;
1137 1175
        char *p= avctx->stats_out;
1138 1176
        char *end= p + STATS_OUT_SIZE;
1139 1177

  
1140 1178
        memset(f->rc_stat, 0, sizeof(f->rc_stat));
1179
        for(i=0; i<f->quant_table_count; i++)
1180
            memset(f->rc_stat2[i], 0, f->context_count[i]*sizeof(*f->rc_stat2[i]));
1181

  
1141 1182
        for(j=0; j<f->slice_count; j++){
1142 1183
            FFV1Context *fs= f->slice_context[j];
1143 1184
            for(i=0; i<256; i++){
1144 1185
                f->rc_stat[i][0] += fs->rc_stat[i][0];
1145 1186
                f->rc_stat[i][1] += fs->rc_stat[i][1];
1146 1187
            }
1188
            for(i=0; i<f->quant_table_count; i++){
1189
                for(k=0; k<f->context_count[i]; k++){
1190
                    for(m=0; m<32; m++){
1191
                        f->rc_stat2[i][k][m][0] += fs->rc_stat2[i][k][m][0];
1192
                        f->rc_stat2[i][k][m][1] += fs->rc_stat2[i][k][m][1];
1193
                    }
1194
                }
1195
            }
1147 1196
        }
1148 1197

  
1149 1198
        for(j=0; j<256; j++){
......
1151 1200
            p+= strlen(p);
1152 1201
        }
1153 1202
        snprintf(p, end-p, "\n");
1203

  
1204
        for(i=0; i<f->quant_table_count; i++){
1205
            for(j=0; j<f->context_count[i]; j++){
1206
                for(m=0; m<32; m++){
1207
                    snprintf(p, end-p, "%"PRIu64" %"PRIu64" ", f->rc_stat2[i][j][m][0], f->rc_stat2[i][j][m][1]);
1208
                    p+= strlen(p);
1209
                }
1210
            }
1211
        }
1212
        snprintf(p, end-p, "\n");
1154 1213
    } else if(avctx->flags&CODEC_FLAG_PASS1)
1155 1214
        avctx->stats_out[0] = '\0';
1156 1215

  
......
1181 1240
            FFV1Context *sf= s->slice_context[i];
1182 1241
            av_freep(&sf->rc_stat2[j]);
1183 1242
        }
1243
        av_freep(&s->rc_stat2[j]);
1184 1244
    }
1185 1245

  
1186 1246
    return 0;

Also available in: Unified diff