[FFmpeg-cvslog] fftools/ffmpeg_filter: pass framerate through InputFilterOptions

Anton Khirnov git at videolan.org
Wed Feb 21 11:45:15 EET 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Feb 13 12:18:27 2024 +0100| [826cfd9997ff0d27ec120700330854b58d3d9848] | committer: Anton Khirnov

fftools/ffmpeg_filter: pass framerate through InputFilterOptions

Rather than read it directly from InputStream.

This is a step towards avoiding the assumption that filtergraph inputs
are always fed by demuxers.

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

 fftools/ffmpeg.h        | 10 ++++++++--
 fftools/ffmpeg_demux.c  | 10 +++++++---
 fftools/ffmpeg_filter.c |  9 +++------
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b4cba521f6..26615eb433 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -253,6 +253,7 @@ typedef struct OptionsContext {
 enum IFilterFlags {
     IFILTER_FLAG_AUTOROTATE     = (1 << 0),
     IFILTER_FLAG_REINIT         = (1 << 1),
+    IFILTER_FLAG_CFR            = (1 << 2),
 };
 
 typedef struct InputFilterOptions {
@@ -261,6 +262,13 @@ typedef struct InputFilterOptions {
 
     uint8_t            *name;
 
+    /* When IFILTER_FLAG_CFR is set, the stream is guaranteed to be CFR with
+     * this framerate.
+     *
+     * Otherwise, this is an estimate that should not be relied upon to be
+     * accurate */
+    AVRational          framerate;
+
     int                 sub2video_width;
     int                 sub2video_height;
 
@@ -365,8 +373,6 @@ typedef struct InputStream {
     Decoder              *decoder;
     const AVCodec        *dec;
 
-    AVRational            framerate_guessed;
-
     /* framerate forced with -r */
     AVRational            framerate;
 #if FFMPEG_OPT_TOP
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 317e27e294..e543c4215c 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -992,7 +992,13 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
     if (ret < 0)
         return ret;
 
-    if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+    if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) {
+        if (ist->framerate.num > 0 && ist->framerate.den > 0) {
+            opts->framerate = ist->framerate;
+            opts->flags |= IFILTER_FLAG_CFR;
+        } else
+            opts->framerate = av_guess_frame_rate(d->f.ctx, ist->st, NULL);
+    } else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
         /* Compute the size of the canvas for the subtitles stream.
            If the subtitles codecpar has set a size, use it. Otherwise use the
            maximum dimensions of the video streams in the same file. */
@@ -1359,8 +1365,6 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
         MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
 #endif
 
-        ist->framerate_guessed = av_guess_frame_rate(ic, st, NULL);
-
         break;
     case AVMEDIA_TYPE_AUDIO: {
         int guess_layout_max = INT_MAX;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 56aa3edd78..dc65b441a6 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1486,7 +1486,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
     const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
     const AVPixFmtDescriptor *desc;
     InputStream *ist = ifp->ist;
-    AVRational fr = ist->framerate;
+    AVRational fr = ifp->opts.framerate;
     AVRational sar;
     AVBPrint args;
     char name[255];
@@ -1495,14 +1495,11 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
     if (!par)
         return AVERROR(ENOMEM);
 
-    if (!fr.num)
-        fr = ist->framerate_guessed;
-
     if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE)
         sub2video_prepare(ifp);
 
-    ifp->time_base =  ist->framerate.num ? av_inv_q(ist->framerate) :
-                                           ist->st->time_base;
+    ifp->time_base = (ifp->opts.flags & IFILTER_FLAG_CFR) ?
+                     av_inv_q(ifp->opts.framerate) : ist->st->time_base;
 
     sar = ifp->sample_aspect_ratio;
     if(!sar.den)



More information about the ffmpeg-cvslog mailing list