]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '16216b713f9a21865cc07993961cf5d0ece24916'
authorHendrik Leppkes <h.leppkes@gmail.com>
Fri, 18 Dec 2015 13:39:15 +0000 (14:39 +0100)
committerHendrik Leppkes <h.leppkes@gmail.com>
Fri, 18 Dec 2015 13:39:15 +0000 (14:39 +0100)
* commit '16216b713f9a21865cc07993961cf5d0ece24916':
  lavc: Drop exporting 2-pass encoding stats

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavcodec/aacenc.c
libavcodec/avcodec.h
libavcodec/mpegvideo_enc.c
libavcodec/options_table.h
libavcodec/version.h

index ec09063e84b9d1707b220fa17bc44a6ba2237d4f,c247c5b39028b484baa42bea1c965b447c14b8ce..3b7dc164da13553b945167f3bf76df288699861d
@@@ -757,70 -644,25 +757,76 @@@ static int aac_encode_frame(AVCodecCont
              break;
          }
  
 -        s->lambda *= avctx->bit_rate * 1024.0f / avctx->sample_rate / frame_bits;
 +        /* rate control stuff
 +         * allow between the nominal bitrate, and what psy's bit reservoir says to target
 +         * but drift towards the nominal bitrate always
 +         */
 +        frame_bits = put_bits_count(&s->pb);
 +        rate_bits = avctx->bit_rate * 1024 / avctx->sample_rate;
 +        rate_bits = FFMIN(rate_bits, 6144 * s->channels - 3);
 +        too_many_bits = FFMAX(target_bits, rate_bits);
 +        too_many_bits = FFMIN(too_many_bits, 6144 * s->channels - 3);
 +        too_few_bits = FFMIN(FFMAX(rate_bits - rate_bits/4, target_bits), too_many_bits);
 +
 +        /* When using ABR, be strict (but only for increasing) */
 +        too_few_bits = too_few_bits - too_few_bits/8;
 +        too_many_bits = too_many_bits + too_many_bits/2;
 +
 +        if (   its == 0 /* for steady-state Q-scale tracking */
 +            || (its < 5 && (frame_bits < too_few_bits || frame_bits > too_many_bits))
 +            || frame_bits >= 6144 * s->channels - 3  )
 +        {
 +            float ratio = ((float)rate_bits) / frame_bits;
 +
 +            if (frame_bits >= too_few_bits && frame_bits <= too_many_bits) {
 +                /*
 +                 * This path is for steady-state Q-scale tracking
 +                 * When frame bits fall within the stable range, we still need to adjust
 +                 * lambda to maintain it like so in a stable fashion (large jumps in lambda
 +                 * create artifacts and should be avoided), but slowly
 +                 */
 +                ratio = sqrtf(sqrtf(ratio));
 +                ratio = av_clipf(ratio, 0.9f, 1.1f);
 +            } else {
 +                /* Not so fast though */
 +                ratio = sqrtf(ratio);
 +            }
 +            s->lambda = FFMIN(s->lambda * ratio, 65536.f);
  
 +            /* Keep iterating if we must reduce and lambda is in the sky */
 +            if (ratio > 0.9f && ratio < 1.1f) {
 +                break;
 +            } else {
 +                if (is_mode || ms_mode || tns_mode || pred_mode) {
 +                    for (i = 0; i < s->chan_map[0]; i++) {
 +                        // Must restore coeffs
 +                        chans = tag == TYPE_CPE ? 2 : 1;
 +                        cpe = &s->cpe[i];
 +                        for (ch = 0; ch < chans; ch++)
 +                            memcpy(cpe->ch[ch].coeffs, cpe->ch[ch].pcoeffs, sizeof(cpe->ch[ch].coeffs));
 +                    }
 +                }
 +                its++;
 +            }
 +        } else {
 +            break;
 +        }
      } while (1);
  
 +    if (s->options.ltp && s->coder->ltp_insert_new_frame)
 +        s->coder->ltp_insert_new_frame(s);
 +
      put_bits(&s->pb, 3, TYPE_END);
      flush_put_bits(&s->pb);
 -    frame_bits = put_bits_count(&s->pb);
++
+ #if FF_API_STAT_BITS
+ FF_DISABLE_DEPRECATION_WARNINGS
 -    avctx->frame_bits = frame_bits;
 +    avctx->frame_bits = put_bits_count(&s->pb);
+ FF_ENABLE_DEPRECATION_WARNINGS
+ #endif
 -    // rate control stuff
 -    if (!(avctx->flags & AV_CODEC_FLAG_QSCALE)) {
 -        float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / frame_bits;
 -        s->lambda *= ratio;
 -        s->lambda = FFMIN(s->lambda, 65536.f);
 -    }
 +    s->lambda_sum += s->lambda;
 +    s->lambda_count++;
  
      if (!frame)
          s->last_frame++;
Simple merge
index 83a43c788cc5d045f588d3e69d3c4cef1cf49305,6f5858554da5566a654d5bd99c919f9625b32c30..a550685e4fe9c84344b0656a7c886ec661ac164f
@@@ -1826,15 -1656,11 +1826,17 @@@ int ff_mpv_encode_picture(AVCodecContex
          if (ret < 0)
              return ret;
  vbv_retry:
 -        if (encode_picture(s, s->picture_number) < 0)
 +        ret = encode_picture(s, s->picture_number);
 +        if (growing_buffer) {
 +            av_assert0(s->pb.buf == avctx->internal->byte_buffer);
 +            pkt->data = s->pb.buf;
 +            pkt->size = avctx->internal->byte_buffer_size;
 +        }
 +        if (ret < 0)
              return -1;
  
+ #if FF_API_STAT_BITS
+ FF_DISABLE_DEPRECATION_WARNINGS
          avctx->header_bits = s->header_bits;
          avctx->mv_bits     = s->mv_bits;
          avctx->misc_bits   = s->misc_bits;
@@@ -1899,15 -1729,11 +1903,15 @@@ FF_ENABLE_DEPRECATION_WARNING
              s->current_picture_ptr->encoding_error[i] = s->current_picture.encoding_error[i];
              avctx->error[i] += s->current_picture_ptr->encoding_error[i];
          }
 +        ff_side_data_set_encoder_stats(pkt, s->current_picture.f->quality,
 +                                       s->current_picture_ptr->encoding_error,
 +                                       (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? 4 : 0,
 +                                       s->pict_type);
  
          if (s->avctx->flags & AV_CODEC_FLAG_PASS1)
-             assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits +
-                    avctx->i_tex_bits + avctx->p_tex_bits ==
-                        put_bits_count(&s->pb));
+             assert(put_bits_count(&s->pb) == s->header_bits + s->mv_bits +
+                                              s->misc_bits + s->i_tex_bits +
+                                              s->p_tex_bits);
          flush_put_bits(&s->pb);
          s->frame_bits  = put_bits_count(&s->pb);
  
Simple merge
Simple merge