diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index e814ab49a03eb36edc4e22a332681fffcd72072e..71140888a51b49f653e9c2a9227a3274cbf40c4c 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -138,6 +138,7 @@ struct MpegTSContext {
     int64_t last_pos;
 
     int skip_changes;
+    int skip_clear;
 
     /******************************************/
     /* private mpegts data */
@@ -177,6 +178,8 @@ static const AVOption mpegts_options[] = {
      {.i64 = 0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
     {"skip_changes", "Skip changing / adding streams / programs.", offsetof(MpegTSContext, skip_changes), AV_OPT_TYPE_INT,
      {.i64 = 0}, 0, 1, 0 },
+    {"skip_clear", "Skip clearing programs.", offsetof(MpegTSContext, skip_clear), AV_OPT_TYPE_INT,
+     {.i64 = 0}, 0, 1, 0 },
     { NULL },
 };
 
@@ -1931,7 +1934,7 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
             for (i = 0; i < ts->nb_prg; i++)
                 if (ts->prg[i].id == ts->stream->programs[j]->id)
                     break;
-            if (i==ts->nb_prg)
+            if (i==ts->nb_prg && !ts->skip_clear)
                 clear_avprogram(ts, ts->stream->programs[j]->id);
         }
     }
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3afe488f105b6992e9532791edf75aed44228afb..be888d85263b554481361d83dcb6163525f2b53a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3111,6 +3111,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
     if (!max_analyze_duration)
         max_analyze_duration = ic->max_analyze_duration;
 
+    av_opt_set(ic, "skip_clear", "1", AV_OPT_SEARCH_CHILDREN);
+
     if (!max_analyze_duration) {
         if (!strcmp(ic->iformat->name, "flv") && !(ic->ctx_flags & AVFMTCTX_NOHEADER)) {
             max_analyze_duration = 10*AV_TIME_BASE;
@@ -3396,6 +3398,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
             }
         }
     }
+    av_opt_set(ic, "skip_clear", "0", AV_OPT_SEARCH_CHILDREN);
 
     // close codecs which were opened in try_decode_frame()
     for (i = 0; i < ic->nb_streams; i++) {