diff --git a/libavformat/mov.c b/libavformat/mov.c
index 785d284b86bb3cdd79f8336b457e698ea2dcd25a..0e9566fe3a984bcf4f4a80c76c8b9c7ca28324cb 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1830,7 +1830,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
 
         current_dts -= sc->dts_shift;
 
-        if (!sc->sample_count)
+        if (!sc->sample_count || st->nb_index_entries)
             return;
         if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries))
             return;