[FFmpeg-cvslog] lavfi/vf_libplacebo: set time_base/frame_rate dynamically

Niklas Haas git at videolan.org
Tue Jun 20 18:11:53 EEST 2023


ffmpeg | branch: master | Niklas Haas <git at haasn.dev> | Thu Jun 15 17:02:48 2023 +0200| [9049ea676363f113eaaef4dbf21aee7df69a3988] | committer: Niklas Haas

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9049ea676363f113eaaef4dbf21aee7df69a3988
---

 libavfilter/vf_libplacebo.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 1085b6fdd0..09a24e7c29 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1158,6 +1158,11 @@ static int libplacebo_config_input(AVFilterLink *inlink)
     return 0;
 }
 
+static inline AVRational max_q(AVRational a, AVRational b)
+{
+    return av_cmp_q(a, b) < 0 ? b : a;
+}
+
 static int libplacebo_config_output(AVFilterLink *outlink)
 {
     int err;
@@ -1198,6 +1203,16 @@ static int libplacebo_config_output(AVFilterLink *outlink)
     if (s->fps.num) {
         outlink->frame_rate = s->fps;
         outlink->time_base = av_inv_q(s->fps);
+    } else {
+        outlink->frame_rate = avctx->inputs[0]->frame_rate;
+        outlink->time_base = avctx->inputs[0]->time_base;
+        for (int i = 1; i < s->nb_inputs; i++) {
+            outlink->frame_rate = max_q(outlink->frame_rate,
+                                        avctx->inputs[i]->frame_rate);
+            outlink->time_base = av_gcd_q(outlink->time_base,
+                                          avctx->inputs[i]->time_base,
+                                          AV_TIME_BASE / 2, AV_TIME_BASE_Q);
+        }
     }
 
     /* Static variables */



More information about the ffmpeg-cvslog mailing list