History

avcodec/ratecontrol: Try to keep fps as a rational

Michael Niedermayer committed 2 years ago

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

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/ratecontrol.c+14−8
@@ -56,20 +56,25 @@ void ff_write_pass1_stats(MpegEncContext *s) · 55 unmodified lines
56 s->header_bits);56 s->header_bits);
57}57}
58 58
59static double get_fps(AVCodecContext *avctx)59static AVRational get_fpsQ(AVCodecContext *avctx)
60{60{
61 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)61 if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
62 return av_q2d(avctx->framerate);62 return avctx->framerate;
63 63
64FF_DISABLE_DEPRECATION_WARNINGS64FF_DISABLE_DEPRECATION_WARNINGS
65 return 1.0 / av_q2d(avctx->time_base)
66#if FF_API_TICKS_PER_FRAME65#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);
68#endif69#endif
69 ;
70FF_ENABLE_DEPRECATION_WARNINGS70FF_ENABLE_DEPRECATION_WARNINGS
71}71}
72 72
73static double get_fps(AVCodecContext *avctx)
74{
75 return av_q2d(get_fpsQ(avctx));
76}
77
73static inline double qp2bits(const RateControlEntry *rce, double qp)78static inline double qp2bits(const RateControlEntry *rce, double qp)
74{79{
75 if (qp <= 0.0) {80 if (qp <= 0.0) {
@@ -332,12 +337,13 @@ static int init_pass2(MpegEncContext *s) · 256 unmodified lines
332 RateControlContext *rcc = &s->rc_context;337 RateControlContext *rcc = &s->rc_context;
333 AVCodecContext *a = s->avctx;338 AVCodecContext *a = s->avctx;
334 int i, toobig;339 int i, toobig;
335 double fps = get_fps(s->avctx);340 AVRational fps = get_fpsQ(s->avctx);
336 double complexity[5] = { 0 }; // approximate bits at quant=1341 double complexity[5] = { 0 }; // approximate bits at quant=1
337 uint64_t const_bits[5] = { 0 }; // quantizer independent bits342 uint64_t const_bits[5] = { 0 }; // quantizer independent bits
338 uint64_t all_const_bits;343 uint64_t all_const_bits;
339 uint64_t all_available_bits = (uint64_t)(s->bit_rate *344 uint64_t all_available_bits = av_rescale_q(s->bit_rate,
340 (double)rcc->num_entries / fps);345 (AVRational){rcc->num_entries,1},
346 fps);
341 double rate_factor = 0;347 double rate_factor = 0;
342 double step;348 double step;
343 const int filter_size = (int)(a->qblur * 4) | 1;349 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