diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index bcfe018..57bfb7f 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -165,6 +165,8 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
         bytestream_put_le16(&riff_extradata, 0xacde);
     } else if (enc->codec_id == AV_CODEC_ID_GSM_MS ||
                enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
+        if (!frame_size && enc->extradata_size == 2)
+            frame_size = AV_RL16(enc->extradata);
         hdrsize += 2;
         /* wSamplesPerBlock */
         bytestream_put_le16(&riff_extradata, frame_size);
