diff --git a/libavformat/utils.c b/libavformat/utils.c
index b5893de799d4f754c7b65e43e02679d725792cdc..417e81c5d760ea21b841b0518a37657f2e420807 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -633,7 +633,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
             st->last_IP_pts= pkt->pts;
             /* cannot compute PTS if not present (we can compute it only
             by knowing the futur */
-        } else {
+        } else if(pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE || pkt->duration){
             if(pkt->pts != AV_NOPTS_VALUE && pkt->duration){
                 int64_t old_diff= FFABS(st->cur_dts - pkt->duration - pkt->pts);
                 int64_t new_diff= FFABS(st->cur_dts - pkt->pts);