[FFmpeg-devel] libavformat: fix inputs initialization in mpegts muxer with filters

Submitted by Oliver Collyer via ffmpeg-devel on April 17, 2019, 8:28 p.m.

Details

Message ID jRzoL0KjL31zklYt43MvgTc2buYK7XH38ej-aaY74b33er3doVIn08-ifynosdFEKSc7On7TgrV1IC3pkY4GRUrvpCC_0qjc3F2L1vzBNSo=@protonmail.com
State New
Headers show

Commit Message

Oliver Collyer via ffmpeg-devel April 17, 2019, 8:28 p.m.
This patch solves the initialization of the inputs when using filters (a graph filter) with the mpegts muxer.

This bug seems to be generated by a simple forgetting to copy. The same code is repeated two times, but only in one case the variable “inputs_done” is initialized. Compare the two blocks:
- Correct: https://github.com/FFmpeg/FFmpeg/blob/a0559fcd81f42f446c93357a943699f9d44eeb79/fftools/ffmpeg.c#L4627
- Incorrect: https://github.com/FFmpeg/FFmpeg/blob/a0559fcd81f42f446c93357a943699f9d44eeb79/fftools/ffmpeg.c#L4616

In addition, the patch includes a more detailed version of two LOG lines. These lines include useful information to detect this error. And they can help to discover other related errors (specifically related to the “cur_dts is invalid” bug that often appears in some user logs).

Regards.
A.H.
From af81338c21c67c0ef2c30ab2009c7094b32327f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20H=C3=A5kon?= <andreas.hakon@protonmail.com>
Date: Wed, 17 Apr 2019 21:22:43 +0100
Subject: [PATCH] libavformat: input init fix mpegts filters

---
 fftools/ffmpeg.c    |    8 ++++++--
 libavformat/utils.c |    4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Carl Eugen Hoyos April 17, 2019, 10:13 p.m.
2019-04-17 22:28 GMT+02:00, Andreas Håkon via ffmpeg-devel
<ffmpeg-devel@ffmpeg.org>:
> This patch solves the initialization of the inputs when using filters (a
> graph filter) with the mpegts muxer.
>
> This bug seems to be generated by a simple forgetting to copy. The same code
> is repeated two times, but only in one case the variable “inputs_done” is
> initialized. Compare the two blocks:
> - Correct:
> https://github.com/FFmpeg/FFmpeg/blob/a0559fcd81f42f446c93357a943699f9d44eeb79/fftools/ffmpeg.c#L4627
> - Incorrect:
> https://github.com/FFmpeg/FFmpeg/blob/a0559fcd81f42f446c93357a943699f9d44eeb79/fftools/ffmpeg.c#L4616
>
> In addition, the patch includes a more detailed version of two LOG lines.

Please split the patch.

Carl Eugen
Michael Niedermayer April 18, 2019, 10:10 a.m.
On Wed, Apr 17, 2019 at 08:28:39PM +0000, Andreas Håkon via ffmpeg-devel wrote:
> This patch solves the initialization of the inputs when using filters (a graph filter) with the mpegts muxer.
> 
> This bug seems to be generated by a simple forgetting to copy. The same code is repeated two times, but only in one case the variable “inputs_done” is initialized. Compare the two blocks:

This text should be in the commit message.
also a testcase would be usefull, a fate test even better

thx

[...]

Patch hide | download patch | download mbox

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0f157d6..b74a209 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3875,7 +3875,9 @@  static OutputStream *choose_output(void)
                        av_rescale_q(ost->st->cur_dts, ost->st->time_base,
                                     AV_TIME_BASE_Q);
         if (ost->st->cur_dts == AV_NOPTS_VALUE)
-            av_log(NULL, AV_LOG_DEBUG, "cur_dts is invalid (this is harmless if it occurs once at the start per stream)\n");
+            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;
@@ -4613,8 +4615,10 @@  static int transcode_step(void)
         }
         if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0)
             return ret;
-        if (!ist)
+        if (!ist) {
+            ost->inputs_done = 1;
             return 0;
+        }
     } else if (ost->filter) {
         int i;
         for (i = 0; i < ost->filter->graph->nb_inputs; i++) {
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9b3f0d2..6ef9423 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1402,8 +1402,8 @@  static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
         st->cur_dts = pkt->dts;
 
     if (s->debug & FF_FDEBUG_TS)
-        av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s\n",
-            presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts));
+        av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n",
+            presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), st->index, st->id);
 
     /* update flags */
     if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || is_intra_only(st->codecpar->codec_id))