This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 25a955f91a9ce493a521d622238f4b952c258516
Author:     Philip Langdale <[email protected]>
AuthorDate: Sat Apr 6 09:19:53 2024 -0700
Commit:     Philip Langdale <[email protected]>
CommitDate: Sat Aug 29 16:37:09 2026 -0700

    avfilter/vf_nvoffruc: add support for `source_fps` expressions
    
    The current code can only accept absolute values for the requested fps,
    but it's often useful to specify a multiple of the video frame rate.
    
    I've borrowed the code from `vf_fps` to implement this. You can read the
    documentation for that filter to see how to use it, but the TLDR is you
    can now use `fps=source_fps*2` or a similar expression. It also supports
    the `ntsc`, `pal`, `film`, and `ntsc_film` aliases from `vf_fps`.
---
 libavfilter/vf_nvoffruc.c | 47 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_nvoffruc.c b/libavfilter/vf_nvoffruc.c
index 94abb63a20..5f0ef859f0 100644
--- a/libavfilter/vf_nvoffruc.c
+++ b/libavfilter/vf_nvoffruc.c
@@ -27,6 +27,7 @@
 
 #include <dlfcn.h>
 #include "libavutil/avassert.h"
+#include "libavutil/eval.h"
 #include "libavutil/cuda_check.h"
 #include "libavutil/hwcontext.h"
 #include "libavutil/hwcontext_cuda_internal.h"
@@ -46,6 +47,29 @@
  */
 #include "NvOFFRUC.h"
 
+static const char *const var_names[] = {
+  "source_fps",
+  "ntsc",
+  "pal",
+  "film",
+  "ntsc_film",
+  NULL
+};
+
+enum var_name {
+  VAR_SOURCE_FPS,
+  VAR_FPS_NTSC,
+  VAR_FPS_PAL,
+  VAR_FPS_FILM,
+  VAR_FPS_NTSC_FILM,
+  VARS_NB
+};
+
+static const double ntsc_fps = 30000.0 / 1001.0;
+static const double pal_fps = 25.0;
+static const double film_fps = 24.0;
+static const double ntsc_film_fps = 24000.0 / 1001.0;
+
 typedef struct FRUCContext {
     const AVClass *class;
 
@@ -58,6 +82,7 @@ typedef struct FRUCContext {
     CUarray   c1;                       ///< CUarray for f1
     CUarray   cw;                       ///< CUarray for work
 
+    char *requested_frame_rate;         ///< expression that defines the 
target framerate
     AVRational dest_frame_rate;
     int interp_start;                   ///< start of range to apply 
interpolation
     int interp_end;                     ///< end of range to apply 
interpolation
@@ -94,10 +119,9 @@ typedef struct FRUCContext {
 #define FRAMERATE_FLAG_SCD 01
 
 static const AVOption nvoffruc_options[] = {
-    {"fps",                 "required output frames per second rate", 
OFFSET(dest_frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="50"},             0,    
   INT_MAX, V|F },
-
-    {"interp_start",        "point to start linear interpolation",    
OFFSET(interp_start),    AV_OPT_TYPE_INT,      {.i64=15},                 0,    
   255,     V|F },
-    {"interp_end",          "point to end linear interpolation",      
OFFSET(interp_end),      AV_OPT_TYPE_INT,      {.i64=240},                0,    
   255,     V|F },
+    {"fps",             "A string describing desired output framerate", 
OFFSET(requested_frame_rate),   AV_OPT_TYPE_STRING, { .str = "50" },    0,  0,  
    V|F },
+    {"interp_start",    "point to start linear interpolation",          
OFFSET(interp_start),           AV_OPT_TYPE_INT,    {.i64=15},          0,  
255,    V|F },
+    {"interp_end",      "point to end linear interpolation",            
OFFSET(interp_end),             AV_OPT_TYPE_INT,    {.i64=240},         0,  
255,    V|F },
 
     {NULL}
 };
@@ -482,6 +506,7 @@ static int config_output(AVFilterLink *outlink)
     NvOFFRUC_CREATE_PARAM create_param = {0,};
     NvOFFRUC_REGISTER_RESOURCE_PARAM register_param = {0,};
     NvOFFRUC_STATUS status;
+    double var_values[VARS_NB], res;
     int exact;
     int ret;
 
@@ -492,6 +517,20 @@ static int config_output(AVFilterLink *outlink)
            ctx->inputs[0]->time_base.num,ctx->inputs[0]->time_base.den,
            av_q2d(ctx->inputs[0]->time_base));
 
+
+    var_values[VAR_SOURCE_FPS]    = av_q2d(inlink->frame_rate);
+    var_values[VAR_FPS_NTSC]      = ntsc_fps;
+    var_values[VAR_FPS_PAL]       = pal_fps;
+    var_values[VAR_FPS_FILM]      = film_fps;
+    var_values[VAR_FPS_NTSC_FILM] = ntsc_film_fps;
+    ret = av_expr_parse_and_eval(&res, s->requested_frame_rate,
+                                 var_names, var_values,
+                                 NULL, NULL, NULL, NULL, NULL, 0, ctx);
+    if (ret < 0)
+        return ret;
+
+    s->dest_frame_rate = av_d2q(res, INT_MAX);
+
     // make sure timebase is small enough to hold the framerate
 
     exact = av_reduce(&s->dest_time_base.num, &s->dest_time_base.den,

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to