History

avcodec/ratecontrol: Try to keep fps as a rational

Michael Niedermayer committed 2 years ago

Commit eb9c96a1 parent f81602f1 file · +14 −8Browse files

Unified · Split

libavcodec/ratecontrol.c+14−8
@@ -56,20 +56,25 @@ void ff_write_pass1_stats(MpegEncContext *s) · 55 unmodified lines
5656 s->header_bits);
5757 }
5858
59−static double get_fps(AVCodecContext *avctx)
59+static AVRational get_fpsQ(AVCodecContext *avctx)
6060 {
6161 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
62− return av_q2d(avctx->framerate);
62+ return avctx->framerate;
6363
6464 FF_DISABLE_DEPRECATION_WARNINGS
65− return 1.0 / av_q2d(avctx->time_base)
6665 #if FF_API_TICKS_PER_FRAME
67− / FFMAX(avctx->ticks_per_frame, 1)
66+ return av_div_q((AVRational){1, FFMAX(avctx->ticks_per_frame, 1)}, avctx->time_base);
67+#else
68+ return av_inv_q(avctx->time_base);
6869 #endif
69− ;
7070 FF_ENABLE_DEPRECATION_WARNINGS
7171 }
7272
73+static double get_fps(AVCodecContext *avctx)
74+{
75+ return av_q2d(get_fpsQ(avctx));
76+}
77+
7378 static inline double qp2bits(const RateControlEntry *rce, double qp)
7479 {
7580 if (qp <= 0.0) {
@@ -332,12 +337,13 @@ static int init_pass2(MpegEncContext *s) · 256 unmodified lines
332337 RateControlContext *rcc = &s->rc_context;
333338 AVCodecContext *a = s->avctx;
334339 int i, toobig;
335− double fps = get_fps(s->avctx);
340+ AVRational fps = get_fpsQ(s->avctx);
336341 double complexity[5] = { 0 }; // approximate bits at quant=1
337342 uint64_t const_bits[5] = { 0 }; // quantizer independent bits
338343 uint64_t all_const_bits;
339− uint64_t all_available_bits = (uint64_t)(s->bit_rate *
340− (double)rcc->num_entries / fps);
344+ uint64_t all_available_bits = av_rescale_q(s->bit_rate,
345+ (AVRational){rcc->num_entries,1},
346+ fps);
341347 double rate_factor = 0;
342348 double step;
343349 const int filter_size = (int)(a->qblur * 4) | 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t