Revision 098eefe1

View differences:

libavcodec/avcodec.h
145 145
    float psnr_y;
146 146
    float psnr_cb;
147 147
    float psnr_cr;
148
    
149
    /* statistics, used for 2-pass encoding */
150
    int mv_bits;
151
    int header_bits;
152
    int i_tex_bits;
153
    int p_tex_bits;
154
    int i_count;
155
    int p_count;
156
    int skip_count;
157
    int misc_bits; // cbp, mb_type
158
    int frame_bits;
148 159
                 
149 160
    /* the following fields are ignored */
150 161
    void *opaque;   /* can be used to carry app specific stuff */
libavcodec/h263.c
245 245
		    int motion_x, int motion_y)
246 246
{
247 247
    int cbpc, cbpy, i, cbp, pred_x, pred_y;
248
    int bits;
248 249
    
249 250
    //    printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
250 251
    if (!s->mb_intra) {
......
257 258
        if ((cbp | motion_x | motion_y) == 0) {
258 259
            /* skip macroblock */
259 260
            put_bits(&s->pb, 1, 1);
261
            s->misc_bits++;
262
            s->last_bits++;
263
            s->skip_count++;
260 264
            return;
261 265
        }
262 266
        put_bits(&s->pb, 1, 0);	/* mb coded */
......
267 271
        cbpy = cbp >> 2;
268 272
        cbpy ^= 0xf;
269 273
        put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
274
            
275
        bits= get_bit_count(&s->pb);
276
        s->misc_bits+= bits - s->last_bits;
277
        s->last_bits=bits;
270 278

  
271 279
        /* motion vectors: 16x16 mode only now */
272 280
        h263_pred_motion(s, 0, &pred_x, &pred_y);
......
274 282
        h263_encode_motion(s, motion_x - pred_x);
275 283
        h263_encode_motion(s, motion_y - pred_y);
276 284

  
285
        bits= get_bit_count(&s->pb);
286
        s->mv_bits+= bits - s->last_bits;
287
        s->last_bits=bits;
288

  
277 289
        /* encode each block */
278 290
        for (i = 0; i < 6; i++) {
279 291
            mpeg4_encode_block(s, block[i], i, 0, zigzag_direct);
280 292
        }
293
        bits= get_bit_count(&s->pb);
294
        s->p_tex_bits+= bits - s->last_bits;
295
        s->last_bits=bits;
296
        s->p_count++;
281 297
    } else {
282 298
        int dc_diff[6];   //dc values with the dc prediction subtracted 
283 299
        int dir[6];  //prediction direction
......
340 356
        cbpy = cbp >> 2;
341 357
        put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
342 358

  
359
        bits= get_bit_count(&s->pb);
360
        s->misc_bits+= bits - s->last_bits;
361
        s->last_bits=bits;
362

  
343 363
        /* encode each block */
344 364
        for (i = 0; i < 6; i++) {
345 365
            mpeg4_encode_block(s, block[i], i, dc_diff[i], scan_table[i]);
346 366
        }
347 367

  
368
        bits= get_bit_count(&s->pb);
369
        s->i_tex_bits+= bits - s->last_bits;
370
        s->last_bits=bits;
371
        s->i_count++;
372

  
348 373
        /* restore ac coeffs & last_index stuff if we messed them up with the prediction */
349 374
        if(s->ac_pred){
350 375
            for(i=0; i<6; i++){
libavcodec/mpegvideo.c
542 542

  
543 543
    encode_picture(s, s->picture_number);
544 544
    avctx->key_frame = (s->pict_type == I_TYPE);
545
    
545
    avctx->header_bits = s->header_bits;
546
    avctx->mv_bits     = s->mv_bits;
547
    avctx->misc_bits   = s->misc_bits;
548
    avctx->i_tex_bits  = s->i_tex_bits;
549
    avctx->p_tex_bits  = s->p_tex_bits;
550
    avctx->i_count     = s->i_count;
551
    avctx->p_count     = s->p_count;
552
    avctx->skip_count  = s->skip_count;
553

  
546 554
    MPV_frame_end(s);
547 555
    s->picture_number++;
548 556
    s->picture_in_gop_number++;
......
554 562
    s->last_frame_bits= s->frame_bits;
555 563
    s->frame_bits  = (pbBufPtr(&s->pb) - s->pb.buf) * 8;
556 564
    s->total_bits += s->frame_bits;
565
    avctx->frame_bits  = s->frame_bits;
566
//printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", 
567
//s->f_code, avctx->key_frame, s->header_bits, s->mv_bits, s->misc_bits, s->frame_bits, s->i_tex_bits, s->p_tex_bits);
557 568

  
558 569
    avctx->quality = s->qscale;
559 570
    if (avctx->get_psnr) {
......
1071 1082
    int mb_x, mb_y, wrap, last_gob, pdif = 0;
1072 1083
    UINT8 *ptr;
1073 1084
    int i, motion_x, motion_y;
1085
    int bits;
1074 1086

  
1075 1087
    s->picture_number = picture_number;
1076 1088

  
......
1134 1146

  
1135 1147
        for(i=MAX_FCODE; i>1; i--){
1136 1148
            loose+= mv_num[i];
1137
            if(loose > 4) break; //FIXME this is pretty ineffective
1149
            if(loose > 10) break; //FIXME this is pretty ineffective
1138 1150
        }
1139 1151
        s->f_code= i;
1140 1152
    }else{
......
1179 1191
        convert_matrix(s->q_non_intra_matrix, s->q_non_intra_matrix16, s->non_intra_matrix, s->qscale);
1180 1192
    }
1181 1193

  
1194
    s->last_bits= get_bit_count(&s->pb);
1182 1195
    switch(s->out_format) {
1183 1196
    case FMT_MJPEG:
1184 1197
        mjpeg_picture_header(s);
......
1197 1210
        mpeg1_encode_picture_header(s, picture_number);
1198 1211
        break;
1199 1212
    }
1200
        
1213
    bits= get_bit_count(&s->pb);
1214
    s->header_bits= bits - s->last_bits;
1215
    s->last_bits= bits;
1216
    s->mv_bits=0;
1217
    s->misc_bits=0;
1218
    s->i_tex_bits=0;
1219
    s->p_tex_bits=0;
1220
    s->i_count=0;
1221
    s->p_count=0;
1222
    s->skip_count=0;
1223

  
1201 1224
    /* init last dc values */
1202 1225
    /* note: quant matrix value (8) is implied here */
1203 1226
    s->last_dc[0] = 128;
......
1372 1395
                mjpeg_encode_mb(s, s->block);
1373 1396
                break;
1374 1397
            }
1375

  
1398
            
1376 1399
            /* decompress blocks so that we keep the state of the decoder */
1377 1400
            s->mv[0][0][0] = motion_x;
1378 1401
            s->mv[0][0][1] = motion_y;
......
1394 1417
            s->first_gob_line = 0;
1395 1418
        }
1396 1419
    }
1397
    
1420

  
1398 1421
    if (s->h263_msmpeg4 && s->pict_type == I_TYPE)
1399 1422
        msmpeg4_encode_ext_header(s);
1400 1423

  
libavcodec/mpegvideo.h
178 178
    double short_term_qsum;   /* sum of recent qscales */
179 179
    double short_term_qcount; /* count of recent qscales */
180 180

  
181
    /* statistics, used for 2-pass encoding */
182
    int mv_bits;
183
    int header_bits;
184
    int i_tex_bits;
185
    int p_tex_bits;
186
    int i_count;
187
    int p_count;
188
    int skip_count;
189
    int misc_bits; // cbp, mb_type
190
    int last_bits; //temp var used for calculating the above vars
191

  
181 192
    /* H.263 specific */
182 193
    int gob_number;
183 194
    int gob_index;

Also available in: Unified diff