diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index dfd396c..816102b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -840,6 +840,7 @@ typedef struct AVPanScan{
 
 enum AVPacketSideDataType {
     AV_PKT_DATA_PALETTE,
+    AV_PKT_DATA_FRAME_SIZE,
 };
 
 typedef struct AVPacket {
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index c8aa8bf..c91069e 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -1039,6 +1039,12 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
     int buf_size = avpkt->size;
     IpvideoContext *s = avctx->priv_data;
 
+    const unsigned int *size = (unsigned int *)av_packet_get_side_data(avpkt, AV_PKT_DATA_FRAME_SIZE, NULL);
+    if (size) {
+        av_log(NULL, AV_LOG_ERROR, "%dx%d\n", size[0], size[1]);
+        avcodec_set_dimensions(avctx, size[0], size[1]);
+        s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
+    }
     /* compressed buffer needs to be large enough to at least hold an entire
      * decoding map */
     if (buf_size < s->decoding_map_size)
diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index 562b19a..7b651aa 100644
--- a/libavformat/ipmovie.c
+++ b/libavformat/ipmovie.c
@@ -88,6 +88,7 @@ typedef struct IPMVEContext {
     int64_t video_pts;
     uint32_t     palette[256];
     int          has_palette;
+    int          changed;
 
     unsigned int audio_bits;
     unsigned int audio_channels;
@@ -162,6 +163,15 @@ static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb,
             }
         }
 
+        unsigned int *frame_size;
+        if (s->changed) {
+            frame_size = (unsigned int *)av_packet_new_side_data(pkt, AV_PKT_DATA_FRAME_SIZE, 2 * sizeof(unsigned int));
+            if (frame_size) {
+                frame_size[0] = s->video_width;
+                frame_size[1] = s->video_height;
+            }
+            s->changed = 0;
+        }
         pkt->pos= s->decode_map_chunk_offset;
         avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET);
         s->decode_map_chunk_offset = 0;
@@ -217,6 +227,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
     int first_color, last_color;
     int audio_flags;
     unsigned char r, g, b;
+    unsigned int width, height;
 
     /* see if there are any pending packets */
     chunk_type = load_ipmovie_packet(s, pb, pkt);
@@ -373,8 +384,16 @@ static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->video_width = AV_RL16(&scratch[0]) * 8;
-            s->video_height = AV_RL16(&scratch[2]) * 8;
+            width = AV_RL16(&scratch[0]) * 8;
+            height = AV_RL16(&scratch[2]) * 8;
+            if (width != s->video_width) {
+                s->video_width = width;
+                s->changed++;
+            }
+            if (height != s->video_height) {
+                s->video_height = height;
+                s->changed++;
+            }
             if (opcode_version < 2 || !AV_RL16(&scratch[6])) {
                 s->video_bpp = 8;
             } else {
