mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-27 17:53:13 +00:00
avcodec/ratecontrol: Try to keep fps as a rational
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
f81602fb3a
commit
eb9c96a82f
@ -56,20 +56,25 @@ void ff_write_pass1_stats(MpegEncContext *s)
|
|||||||
s->header_bits);
|
s->header_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double get_fps(AVCodecContext *avctx)
|
static AVRational get_fpsQ(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
|
if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
|
||||||
return av_q2d(avctx->framerate);
|
return avctx->framerate;
|
||||||
|
|
||||||
FF_DISABLE_DEPRECATION_WARNINGS
|
FF_DISABLE_DEPRECATION_WARNINGS
|
||||||
return 1.0 / av_q2d(avctx->time_base)
|
|
||||||
#if FF_API_TICKS_PER_FRAME
|
#if FF_API_TICKS_PER_FRAME
|
||||||
/ FFMAX(avctx->ticks_per_frame, 1)
|
return av_div_q((AVRational){1, FFMAX(avctx->ticks_per_frame, 1)}, avctx->time_base);
|
||||||
|
#else
|
||||||
|
return av_inv_q(avctx->time_base);
|
||||||
#endif
|
#endif
|
||||||
;
|
|
||||||
FF_ENABLE_DEPRECATION_WARNINGS
|
FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double get_fps(AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
return av_q2d(get_fpsQ(avctx));
|
||||||
|
}
|
||||||
|
|
||||||
static inline double qp2bits(const RateControlEntry *rce, double qp)
|
static inline double qp2bits(const RateControlEntry *rce, double qp)
|
||||||
{
|
{
|
||||||
if (qp <= 0.0) {
|
if (qp <= 0.0) {
|
||||||
@ -332,12 +337,13 @@ static int init_pass2(MpegEncContext *s)
|
|||||||
RateControlContext *rcc = &s->rc_context;
|
RateControlContext *rcc = &s->rc_context;
|
||||||
AVCodecContext *a = s->avctx;
|
AVCodecContext *a = s->avctx;
|
||||||
int i, toobig;
|
int i, toobig;
|
||||||
double fps = get_fps(s->avctx);
|
AVRational fps = get_fpsQ(s->avctx);
|
||||||
double complexity[5] = { 0 }; // approximate bits at quant=1
|
double complexity[5] = { 0 }; // approximate bits at quant=1
|
||||||
uint64_t const_bits[5] = { 0 }; // quantizer independent bits
|
uint64_t const_bits[5] = { 0 }; // quantizer independent bits
|
||||||
uint64_t all_const_bits;
|
uint64_t all_const_bits;
|
||||||
uint64_t all_available_bits = (uint64_t)(s->bit_rate *
|
uint64_t all_available_bits = av_rescale_q(s->bit_rate,
|
||||||
(double)rcc->num_entries / fps);
|
(AVRational){rcc->num_entries,1},
|
||||||
|
fps);
|
||||||
double rate_factor = 0;
|
double rate_factor = 0;
|
||||||
double step;
|
double step;
|
||||||
const int filter_size = (int)(a->qblur * 4) | 1;
|
const int filter_size = (int)(a->qblur * 4) | 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user