[06/11] lavfi/setpts: add FRAME_RATE constant

Message ID 1446050917-7419-2-git-send-email-stebbins@jetheaddev.com
State New
Headers show

Commit Message

John Stebbins Oct. 28, 2015, 4:48 p.m.
From: Stefano Sabatini <stefasab@gmail.com>

Useful for dealing with constant frame-rate video.

(cherry picked from ffmpeg commit 722762f7e1212b4d02142778fabfdd73375722e0)
---
 doc/filters.texi     | 3 +++
 libavfilter/setpts.c | 6 ++++++
 2 files changed, 9 insertions(+)

Comments

Anton Khirnov Oct. 29, 2015, 6:55 p.m. | #1
Quoting John Stebbins (2015-10-28 17:48:35)
> From: Stefano Sabatini <stefasab@gmail.com>
> 
> Useful for dealing with constant frame-rate video.
> 
> (cherry picked from ffmpeg commit 722762f7e1212b4d02142778fabfdd73375722e0)
> ---
>  doc/filters.texi     | 3 +++
>  libavfilter/setpts.c | 6 ++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index d9874b6..9804c0e 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -209,6 +209,9 @@ The expression is evaluated through the eval API and can contain the following
>  constants:
>  
>  @table @option
> +@item FRAME_RATE
> +frame rate, only defined for constant frame-rate video
> +
>  @item PTS
>  the presentation timestamp in input
>  
> diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
> index 98bafc2..ab3674a 100644
> --- a/libavfilter/setpts.c
> +++ b/libavfilter/setpts.c
> @@ -41,6 +41,7 @@
>  
>  static const char *const var_names[] = {
>      "E",           ///< Euler number
> +    "FRAME_RATE",  ///< defined only for constant frame-rate video
>      "INTERLACED",  ///< tell if the current frame is interlaced
>      "N",           ///< frame / sample number (starting at zero)
>      "PHI",         ///< golden ratio
> @@ -59,6 +60,7 @@ static const char *const var_names[] = {
>  
>  enum var_name {
>      VAR_E,
> +    VAR_FRAME_RATE,
>      VAR_INTERLACED,
>      VAR_N,
>      VAR_PHI,
> @@ -115,6 +117,10 @@ static int config_input(AVFilterLink *inlink)
>          setpts->var_values[VAR_SR] = inlink->sample_rate;
>      }
>  
> +    setpts->var_values[VAR_FRAME_RATE] = inlink->frame_rate.num &&
> +                                         inlink->frame_rate.den ?
> +                                            av_q2d(inlink->frame_rate) : NAN;
> +
>      av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts->var_values[VAR_TB]);
>      return 0;
>  }
> -- 
> 2.4.3

I think this filter should also set the output framerate to
zero/undefined, since we have no idea if the output is still CFR.
John Stebbins Oct. 29, 2015, 8:40 p.m. | #2
On Thu, 2015-10-29 at 19:55 +0100, Anton Khirnov wrote:
> Quoting John Stebbins (2015-10-28 17:48:35)
> > From: Stefano Sabatini <stefasab@gmail.com>
> > 
> > Useful for dealing with constant frame-rate video.
> > 
> > (cherry picked from ffmpeg commit
> > 722762f7e1212b4d02142778fabfdd73375722e0)
> > ---
> >  doc/filters.texi     | 3 +++
> >  libavfilter/setpts.c | 6 ++++++
> >  2 files changed, 9 insertions(+)
> > 
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index d9874b6..9804c0e 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -209,6 +209,9 @@ The expression is evaluated through the eval API
> > and can contain the following
> >  constants:
> >  
> >  @table @option
> > +@item FRAME_RATE
> > +frame rate, only defined for constant frame-rate video
> > +
> >  @item PTS
> >  the presentation timestamp in input
> >  
> > diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
> > index 98bafc2..ab3674a 100644
> > --- a/libavfilter/setpts.c
> > +++ b/libavfilter/setpts.c
> > @@ -41,6 +41,7 @@
> >  
> >  static const char *const var_names[] = {
> >      "E",           ///< Euler number
> > +    "FRAME_RATE",  ///< defined only for constant frame-rate video
> >      "INTERLACED",  ///< tell if the current frame is interlaced
> >      "N",           ///< frame / sample number (starting at zero)
> >      "PHI",         ///< golden ratio
> > @@ -59,6 +60,7 @@ static const char *const var_names[] = {
> >  
> >  enum var_name {
> >      VAR_E,
> > +    VAR_FRAME_RATE,
> >      VAR_INTERLACED,
> >      VAR_N,
> >      VAR_PHI,
> > @@ -115,6 +117,10 @@ static int config_input(AVFilterLink *inlink)
> >          setpts->var_values[VAR_SR] = inlink->sample_rate;
> >      }
> >  
> > +    setpts->var_values[VAR_FRAME_RATE] = inlink->frame_rate.num &&
> > +                                         inlink->frame_rate.den ?
> > +                                            av_q2d(inlink
> > ->frame_rate) : NAN;
> > +
> >      av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts
> > ->var_values[VAR_TB]);
> >      return 0;
> >  }
> > -- 
> > 2.4.3
> 
> I think this filter should also set the output framerate to
> zero/undefined, since we have no idea if the output is still CFR.
> 

Ah, yes.  Good point.  

One thing to note that I forgot to mention previously.  There are
filters (e.g. framepack) the currently modify frame_rate without
checking if it is 1/0.  So in the case of framepack, 1/0 in will result
in 2/0 out.  Do we care?  Should we either fix this or document that X/0
is "unknown" at the output stage?

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index d9874b6..9804c0e 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -209,6 +209,9 @@  The expression is evaluated through the eval API and can contain the following
 constants:
 
 @table @option
+@item FRAME_RATE
+frame rate, only defined for constant frame-rate video
+
 @item PTS
 the presentation timestamp in input
 
diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
index 98bafc2..ab3674a 100644
--- a/libavfilter/setpts.c
+++ b/libavfilter/setpts.c
@@ -41,6 +41,7 @@ 
 
 static const char *const var_names[] = {
     "E",           ///< Euler number
+    "FRAME_RATE",  ///< defined only for constant frame-rate video
     "INTERLACED",  ///< tell if the current frame is interlaced
     "N",           ///< frame / sample number (starting at zero)
     "PHI",         ///< golden ratio
@@ -59,6 +60,7 @@  static const char *const var_names[] = {
 
 enum var_name {
     VAR_E,
+    VAR_FRAME_RATE,
     VAR_INTERLACED,
     VAR_N,
     VAR_PHI,
@@ -115,6 +117,10 @@  static int config_input(AVFilterLink *inlink)
         setpts->var_values[VAR_SR] = inlink->sample_rate;
     }
 
+    setpts->var_values[VAR_FRAME_RATE] = inlink->frame_rate.num &&
+                                         inlink->frame_rate.den ?
+                                            av_q2d(inlink->frame_rate) : NAN;
+
     av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts->var_values[VAR_TB]);
     return 0;
 }