[FFmpeg-devel] lavf/utils: bail early if we don't see any packets in an MPEGTS stream

Submitted by Rodger Combs on May 3, 2017, 3:14 a.m.

Details

Message ID 20170503031435.91300-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs May 3, 2017, 3:14 a.m.
---
 libavformat/utils.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer May 5, 2017, 4:32 p.m.
On Tue, May 02, 2017 at 10:14:35PM -0500, Rodger Combs wrote:
> ---
>  libavformat/utils.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)

i tested this a bit and didnt find a file that this breaks


[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/utils.c b/libavformat/utils.c
index ba82a766dc..80895b31f0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3505,6 +3505,8 @@  int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
     int64_t max_analyze_duration = ic->max_analyze_duration;
     int64_t max_stream_analyze_duration;
     int64_t max_subtitle_analyze_duration;
+    int64_t max_empty_analyze_duration;
+    int skip_empty_streams = 0;
     int64_t probesize = ic->probesize;
     int eof_reached = 0;
     int *missing_streams = av_opt_ptr(ic->iformat->priv_class, ic->priv_data, "missing_streams");
@@ -3515,14 +3517,20 @@  int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
 
     max_stream_analyze_duration = max_analyze_duration;
     max_subtitle_analyze_duration = max_analyze_duration;
+    max_empty_analyze_duration = max_analyze_duration;
     if (!max_analyze_duration) {
+        max_empty_analyze_duration =
         max_stream_analyze_duration =
         max_analyze_duration        = 5*AV_TIME_BASE;
         max_subtitle_analyze_duration = 30*AV_TIME_BASE;
-        if (!strcmp(ic->iformat->name, "flv"))
+        if (!strcmp(ic->iformat->name, "flv")) {
+            max_empty_analyze_duration =
             max_stream_analyze_duration = 90*AV_TIME_BASE;
-        if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts"))
+        }
+        if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) {
             max_stream_analyze_duration = 7*AV_TIME_BASE;
+            max_empty_analyze_duration = 2*AV_TIME_BASE;
+        }
     }
 
     if (ic->pb)
@@ -3628,6 +3636,12 @@  FF_ENABLE_DEPRECATION_WARNINGS
             int fps_analyze_framecount = 20;
 
             st = ic->streams[i];
+
+            if (st->codec_info_nb_frames == 0 &&
+                st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE &&
+                skip_empty_streams)
+                continue;
+
             if (!has_codec_parameters(st, NULL))
                 break;
             /* If the timebase is coarse (like the usual millisecond precision
@@ -3791,6 +3805,10 @@  FF_ENABLE_DEPRECATION_WARNINGS
                     av_packet_unref(pkt);
                 break;
             }
+
+            if (t >= max_empty_analyze_duration)
+                skip_empty_streams = 1;
+
             if (pkt->duration) {
                 if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && pkt->pts >= st->start_time) {
                     st->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, st->info->codec_info_duration + pkt->duration);