mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
Implement the fields rc_max_available_vbv_use and
rc_min_vbv_overflow_use in AVCodecContext, and use their values in the ratecontrol code rather than hardcoded ones. See the thread: "[RFC] ratecontrol buffer size magic". Patch by Baptiste Coudurier. Originally committed as revision 15955 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
cd0e37d3b1
commit
3bff4d8b7a
@ -30,7 +30,7 @@
|
|||||||
#include "libavutil/avutil.h"
|
#include "libavutil/avutil.h"
|
||||||
|
|
||||||
#define LIBAVCODEC_VERSION_MAJOR 52
|
#define LIBAVCODEC_VERSION_MAJOR 52
|
||||||
#define LIBAVCODEC_VERSION_MINOR 3
|
#define LIBAVCODEC_VERSION_MINOR 4
|
||||||
#define LIBAVCODEC_VERSION_MICRO 0
|
#define LIBAVCODEC_VERSION_MICRO 0
|
||||||
|
|
||||||
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
|
||||||
@ -2283,6 +2283,20 @@ typedef struct AVCodecContext {
|
|||||||
* - decoding: Set by user.
|
* - decoding: Set by user.
|
||||||
*/
|
*/
|
||||||
int64_t request_channel_layout;
|
int64_t request_channel_layout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
|
||||||
|
* - encoding: Set by user.
|
||||||
|
* - decoding: unused.
|
||||||
|
*/
|
||||||
|
float rc_max_available_vbv_use;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
|
||||||
|
* - encoding: Set by user.
|
||||||
|
* - decoding: unused.
|
||||||
|
*/
|
||||||
|
float rc_min_vbv_overflow_use;
|
||||||
} AVCodecContext;
|
} AVCodecContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1231,7 +1231,7 @@ vbv_retry:
|
|||||||
|
|
||||||
if(avctx->rc_buffer_size){
|
if(avctx->rc_buffer_size){
|
||||||
RateControlContext *rcc= &s->rc_context;
|
RateControlContext *rcc= &s->rc_context;
|
||||||
int max_size= rcc->buffer_index/3;
|
int max_size= rcc->buffer_index * avctx->rc_max_available_vbv_use;
|
||||||
|
|
||||||
if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){
|
if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){
|
||||||
s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale);
|
s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale);
|
||||||
|
@ -461,7 +461,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
|
|||||||
else if(d<0.0001) d=0.0001;
|
else if(d<0.0001) d=0.0001;
|
||||||
q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
|
q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
|
||||||
|
|
||||||
q_limit= bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*3, 1));
|
q_limit= bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index) * s->avctx->rc_min_vbv_overflow_use, 1));
|
||||||
if(q > q_limit){
|
if(q > q_limit){
|
||||||
if(s->avctx->debug&FF_DEBUG_RC){
|
if(s->avctx->debug&FF_DEBUG_RC){
|
||||||
av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
|
av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
|
||||||
@ -476,7 +476,7 @@ static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q,
|
|||||||
else if(d<0.0001) d=0.0001;
|
else if(d<0.0001) d=0.0001;
|
||||||
q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
|
q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
|
||||||
|
|
||||||
q_limit= bits2qp(rce, FFMAX(rcc->buffer_index/3, 1));
|
q_limit= bits2qp(rce, FFMAX(rcc->buffer_index * s->avctx->rc_max_available_vbv_use, 1));
|
||||||
if(q < q_limit){
|
if(q < q_limit){
|
||||||
if(s->avctx->debug&FF_DEBUG_RC){
|
if(s->avctx->debug&FF_DEBUG_RC){
|
||||||
av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
|
av_log(s->avctx, AV_LOG_DEBUG, "limiting QP %f -> %f\n", q, q_limit);
|
||||||
|
@ -743,6 +743,8 @@ static const AVOption options[]={
|
|||||||
{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
|
{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
|
||||||
{"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"},
|
{"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"},
|
||||||
{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"},
|
{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"},
|
||||||
|
{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), FF_OPT_TYPE_FLOAT, 1.0/3, 0.0, FLT_MAX, V|E},
|
||||||
|
{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), FF_OPT_TYPE_FLOAT, 3, 0.0, FLT_MAX, V|E},
|
||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user