diff --git a/libavformat/utils.c b/libavformat/utils.c
index b0b5e164a6e10fa52f5d049e45592b3780a58059..a72f0a482e24f7c98d014c0a97e36028795a2e01 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3869,7 +3869,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                 break;
             }
             if (pkt->duration) {
-                if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && pkt->pts >= st->start_time) {
+                if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != 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);
                 } else
                     st->info->codec_info_duration += pkt->duration;