diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 15f0794..896ffa5 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -636,6 +636,13 @@ static int avi_write_trailer(AVFormatContext *s)
 
     for (i=0; i<s->nb_streams; i++) {
          AVIStream *avist= s->streams[i]->priv_data;
+         int dwSuggestedBufferSize = 0;
+         for (j=0; j<avist->indexes.entry; j++) {
+              AVIIentry* ie = avi_get_ientry(&avist->indexes, j);
+              dwSuggestedBufferSize = FFMAX(dwSuggestedBufferSize, ie->len);
+         }
+         avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
+         avio_wl32(pb, dwSuggestedBufferSize);
          for (j=0; j<avist->indexes.ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
               av_free(avist->indexes.cluster[j]);
          av_freep(&avist->indexes.cluster);
