diff mbox

[FFmpeg-devel,v2,1/2] avformat/utils: ignore outlier durations on subtitle/data streams as well

Message ID 20180419235134.76459-1-ffmpeg@tmm1.net
State Accepted
Commit fd6e89586c01d068fc8d2cea24292bf8ae836f74
Headers show

Commit Message

Aman Gupta April 19, 2018, 11:51 p.m. UTC
From: Aman Gupta <aman@tmm1.net>

Similar to 4c9c4fe8b21, but for durations. This fixes #7151, where
the report duration and bitrate on a mpegts stream is wildly off
due to the dvb_teletext stream's timings.
---
 libavformat/utils.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer April 20, 2018, 8:46 a.m. UTC | #1
On Thu, Apr 19, 2018 at 04:51:33PM -0700, Aman Gupta wrote:
> From: Aman Gupta <aman@tmm1.net>
> 
> Similar to 4c9c4fe8b21, but for durations. This fixes #7151, where
> the report duration and bitrate on a mpegts stream is wildly off
> due to the dvb_teletext stream's timings.
> ---
>  libavformat/utils.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)

patches should be ok

thx
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index f2f2cc4239..705b79031d 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2618,7 +2618,7 @@  static int has_duration(AVFormatContext *ic)
 static void update_stream_timings(AVFormatContext *ic)
 {
     int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
-    int64_t duration, duration1, filesize;
+    int64_t duration, duration1, duration_text, filesize;
     int i;
     AVStream *st;
     AVProgram *p;
@@ -2628,6 +2628,8 @@  static void update_stream_timings(AVFormatContext *ic)
     end_time   = INT64_MIN;
     end_time_text   = INT64_MIN;
     duration   = INT64_MIN;
+    duration_text = INT64_MIN;
+
     for (i = 0; i < ic->nb_streams; i++) {
         st = ic->streams[i];
         if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) {
@@ -2658,7 +2660,10 @@  static void update_stream_timings(AVFormatContext *ic)
         if (st->duration != AV_NOPTS_VALUE) {
             duration1 = av_rescale_q(st->duration, st->time_base,
                                      AV_TIME_BASE_Q);
-            duration  = FFMAX(duration, duration1);
+            if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
+                duration_text = FFMAX(duration_text, duration1);
+            else
+                duration = FFMAX(duration, duration1);
         }
     }
     if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text < AV_TIME_BASE))
@@ -2672,6 +2677,11 @@  static void update_stream_timings(AVFormatContext *ic)
         av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE);
     }
 
+     if (duration == INT64_MIN || (duration < duration_text && duration_text - duration < AV_TIME_BASE))
+         duration = duration_text;
+     else if (duration < duration_text)
+         av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE);
+
     if (start_time != INT64_MAX) {
         ic->start_time = start_time;
         if (end_time != INT64_MIN) {