diff options
Diffstat (limited to 'libavcodec/ratecontrol.c')
-rw-r--r-- | libavcodec/ratecontrol.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 5e4b49a..9d98b9a 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -3,20 +3,20 @@ * * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -125,6 +125,8 @@ int ff_rate_control_init(MpegEncContext *s) rcc->last_qscale_for[i]=FF_QP2LAMBDA * 5; } rcc->buffer_index= s->avctx->rc_initial_buffer_occupancy; + if (!rcc->buffer_index) + rcc->buffer_index = s->avctx->rc_buffer_size * 3 / 4; if(s->flags&CODEC_FLAG_PASS2){ int i; @@ -537,8 +539,8 @@ static void adaptive_quantization(MpegEncContext *s, double q){ const float border_masking = s->avctx->border_masking; float bits_sum= 0.0; float cplx_sum= 0.0; - float cplx_tab[s->mb_num]; - float bits_tab[s->mb_num]; + float *cplx_tab = av_malloc(s->mb_num * sizeof(*cplx_tab)); + float *bits_tab = av_malloc(s->mb_num * sizeof(*bits_tab)); const int qmin= s->avctx->mb_lmin; const int qmax= s->avctx->mb_lmax; Picture * const pic= &s->current_picture; @@ -639,6 +641,9 @@ static void adaptive_quantization(MpegEncContext *s, double q){ //printf("%2d%3d ", intq, ff_sqrt(s->mc_mb_var[i])); s->lambda_table[mb_xy]= intq; } + + av_free(cplx_tab); + av_free(bits_tab); } void ff_get_2pass_fcode(MpegEncContext *s){ @@ -705,7 +710,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) dts_pic= s->last_picture_ptr; //if(dts_pic) -// av_log(NULL, AV_LOG_ERROR, "%Ld %Ld %Ld %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number); +// av_log(NULL, AV_LOG_ERROR, "%"PRId64" %"PRId64" %"PRId64" %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number); if (!dts_pic || dts_pic->f.pts == AV_NOPTS_VALUE) wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); @@ -868,6 +873,12 @@ static int init_pass2(MpegEncContext *s) assert(filter_size%2==1); /* fixed I/B QP relative to P mode */ + for(i=FFMAX(0, rcc->num_entries-300); i<rcc->num_entries; i++){ + RateControlEntry *rce= &rcc->entry[i]; + + qscale[i]= get_diff_limited_q(s, rce, qscale[i]); + } + for(i=rcc->num_entries-1; i>=0; i--){ RateControlEntry *rce= &rcc->entry[i]; |