[FFmpeg-cvslog] fftools/ffmpeg: use last filter output pts to choose next output stream

Anton Khirnov git at videolan.org
Sat Jul 23 13:07:34 EEST 2022


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Jun 10 14:38:32 2022 +0200| [b2b9e9ccee0647b4695edaa66ae824850260ee02] | committer: Anton Khirnov

fftools/ffmpeg: use last filter output pts to choose next output stream

This will be needed in following commits that will add new buffering
stages after encoding and bitstream filtering.

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

 fftools/ffmpeg.c     | 22 +++++++++++++++++-----
 fftools/ffmpeg.h     |  2 ++
 fftools/ffmpeg_opt.c |  1 +
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index f50e745ab0..bed87a2199 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1351,6 +1351,12 @@ static int reap_filters(int flush)
                 continue;
             }
 
+            if (filtered_frame->pts != AV_NOPTS_VALUE) {
+                AVRational tb = av_buffersink_get_time_base(filter);
+                ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb,
+                                                    AV_TIME_BASE_Q);
+            }
+
             switch (av_buffersink_get_type(filter)) {
             case AVMEDIA_TYPE_VIDEO:
                 if (!ost->frame_aspect_ratio.num)
@@ -3448,13 +3454,19 @@ static OutputStream *choose_output(void)
 
     for (i = 0; i < nb_output_streams; i++) {
         OutputStream *ost = output_streams[i];
-        int64_t opts = ost->last_mux_dts == AV_NOPTS_VALUE ? INT64_MIN :
+        int64_t opts;
+
+        if (ost->filter && ost->last_filter_pts != AV_NOPTS_VALUE) {
+            opts = ost->last_filter_pts;
+        } else {
+            opts = ost->last_mux_dts == AV_NOPTS_VALUE ? INT64_MIN :
                        av_rescale_q(ost->last_mux_dts, ost->st->time_base,
                                     AV_TIME_BASE_Q);
-        if (ost->last_mux_dts == AV_NOPTS_VALUE)
-            av_log(NULL, AV_LOG_DEBUG,
-                "cur_dts is invalid st:%d (%d) [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n",
-                ost->st->index, ost->st->id, ost->initialized, ost->inputs_done, ost->finished);
+            if (ost->last_mux_dts == AV_NOPTS_VALUE)
+                av_log(NULL, AV_LOG_DEBUG,
+                    "cur_dts is invalid st:%d (%d) [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n",
+                    ost->st->index, ost->st->id, ost->initialized, ost->inputs_done, ost->finished);
+        }
 
         if (!ost->initialized && !ost->inputs_done)
             return ost->unavailable ? NULL : ost;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index ecceedbd90..7ff303e370 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -470,6 +470,8 @@ typedef struct OutputStream {
     int64_t first_pts;
     /* dts of the last packet sent to the muxer */
     int64_t last_mux_dts;
+    /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */
+    int64_t last_filter_pts;
     // the timebase of the packets sent to the muxer
     AVRational mux_timebase;
     AVRational enc_timebase;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 2998e00546..db8ec33cde 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1721,6 +1721,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
         input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
     }
     ost->last_mux_dts = AV_NOPTS_VALUE;
+    ost->last_filter_pts = AV_NOPTS_VALUE;
 
     return ost;
 }



More information about the ffmpeg-cvslog mailing list