History

lavfi/vf_libplacebo: set time_base/frame_rate dynamically

Use the gcd of all input timebases to ensure PTS accuracy. For the framerate, just pick the highest of all the inputs, under the assumption that we will render frames with approximately this frequency. Of course, this is not 100% accurate, in particular if the input frames are badly misaligned. But this field is informational to begin with. Importantly, it covers the "common" case of combining high FPS and low FPS streams with aligned frames.

Niklas Haas committed 3 years ago

Commit 9049ea61 parent 1b2c6c91 file · +15 −0Browse files

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

Unified · Split

libavfilter/vf_libplacebo.c+15−0
@@ -1158,6 +1158,11 @@ static int libplacebo_config_input(AVFilterLink *inlink) · 1157 unmodified lines
11581158 return 0;
11591159 }
11601160
1161+static inline AVRational max_q(AVRational a, AVRational b)
1162+{
1163+ return av_cmp_q(a, b) < 0 ? b : a;
1164+}
1165+
11611166 static int libplacebo_config_output(AVFilterLink *outlink)
11621167 {
11631168 int err;
@@ -1198,6 +1203,16 @@ static int libplacebo_config_output(AVFilterLink *outlink) · 34 unmodified lines
11981203 if (s->fps.num) {
11991204 outlink->frame_rate = s->fps;
12001205 outlink->time_base = av_inv_q(s->fps);
1206+ } else {
1207+ outlink->frame_rate = avctx->inputs[0]->frame_rate;
1208+ outlink->time_base = avctx->inputs[0]->time_base;
1209+ for (int i = 1; i < s->nb_inputs; i++) {
1210+ outlink->frame_rate = max_q(outlink->frame_rate,
1211+ avctx->inputs[i]->frame_rate);
1212+ outlink->time_base = av_gcd_q(outlink->time_base,
1213+ avctx->inputs[i]->time_base,
1214+ AV_TIME_BASE / 2, AV_TIME_BASE_Q);
1215+ }
12011216 }
12021217
12031218 /* Static variables */

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