diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 3646994c43f59076f9cc24200909ccfaae98664b..53e3772c6180e090aceba9eb1f19c5a3d9892363 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -5304,6 +5304,7 @@ static int mov_write_header(AVFormatContext *s)
         !(mov->flags & FF_MOV_FLAG_DELAY_MOOV)) {
         if ((ret = mov_write_moov_tag(pb, mov, s)) < 0)
             return ret;
+        avio_flush(pb);
         mov->moov_written = 1;
         if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)
             mov->reserved_header_pos = avio_tell(pb);