[FFmpeg-devel] [PATCH 1/3] avfilter/vf_fps: add way to get CFR output without knowing input frame rate

Paul B Mahol onemda at gmail.com
Tue Oct 29 19:00:55 EET 2019


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 doc/filters.texi     |  3 +++
 libavfilter/vf_fps.c | 10 +++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 11f715319a..1e815bf940 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10737,6 +10737,9 @@ Pass through last frame if input duration has not been reached yet.
 @end table
 The default is @code{round}.
 
+ at item input
+Pick output frame rate from input if it is available. The default is disabled.
+Useful to change input to constant frame rate without needing to know input frame rate.
 @end table
 
 Alternatively, the options can be specified as a flat string:
diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index cf1e36726a..7c9762864b 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -70,6 +70,7 @@ typedef struct FPSContext {
     int frames_out;            ///< number of frames on output
     int dup;                   ///< number of frames duplicated
     int drop;                  ///< number of framed dropped
+    int input;                 ///< should filter use input framerate if one is set
 } FPSContext;
 
 #define OFFSET(x) offsetof(FPSContext, x)
@@ -87,6 +88,7 @@ static const AVOption fps_options[] = {
     { "eof_action", "action performed for last frame", OFFSET(eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_ROUND }, 0, EOF_ACTION_NB-1, V|F, "eof_action" },
         { "round", "round similar to other frames",  0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ROUND }, 0, 0, V|F, "eof_action" },
         { "pass",  "pass through last frame",        0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS  }, 0, 0, V|F, "eof_action" },
+    { "input", "use input framerate if available", OFFSET(input), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, V|F },
     { NULL }
 };
 
@@ -99,7 +101,6 @@ static av_cold int init(AVFilterContext *ctx)
     s->status_pts   = AV_NOPTS_VALUE;
     s->next_pts     = AV_NOPTS_VALUE;
 
-    av_log(ctx, AV_LOG_VERBOSE, "fps=%d/%d\n", s->framerate.num, s->framerate.den);
     return 0;
 }
 
@@ -153,8 +154,15 @@ static int config_props(AVFilterLink* outlink)
     AVFilterLink    *inlink = ctx->inputs[0];
     FPSContext      *s      = ctx->priv;
 
+    if (s->input && inlink->frame_rate.num > 0 && inlink->frame_rate.den > 0) {
+        outlink->time_base  = av_inv_q(inlink->frame_rate);
+        outlink->frame_rate = inlink->frame_rate;
+    } else {
     outlink->time_base  = av_inv_q(s->framerate);
     outlink->frame_rate = s->framerate;
+    }
+
+    av_log(ctx, AV_LOG_VERBOSE, "fps=%d/%d\n", outlink->frame_rate.num, outlink->frame_rate.den);
 
     /* Calculate the input and output pts offsets for start_time */
     if (s->start_time != DBL_MAX && s->start_time != AV_NOPTS_VALUE) {
-- 
2.17.1



More information about the ffmpeg-devel mailing list