diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index c8aa8bf..45f2f85 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -68,6 +68,7 @@ typedef struct IpvideoContext {
     int line_inc;
     int stride;
     int upper_motion_limit_offset;
+    int width, height;
 
     uint32_t pal[256];
 } IpvideoContext;
@@ -975,12 +976,12 @@ static void ipvideo_decode_opcodes(IpvideoContext *s)
         s->mv_end = s->buf + s->size;
     }
     s->line_inc = s->stride - 8;
-    s->upper_motion_limit_offset = (s->avctx->height - 8) * s->current_frame.linesize[0]
-                                  + (s->avctx->width - 8) * (1 + s->is_16bpp);
+    s->upper_motion_limit_offset = (s->height - 8) * s->current_frame.linesize[0]
+                                  + (s->width - 8) * (1 + s->is_16bpp);
 
     init_get_bits(&gb, s->decoding_map, s->decoding_map_size * 8);
-    for (y = 0; y < s->avctx->height; y += 8) {
-        for (x = 0; x < s->avctx->width; x += 8) {
+    for (y = 0; y < s->height; y += 8) {
+        for (x = 0; x < s->width; x += 8) {
             opcode = get_bits(&gb, 4);
 
             av_dlog(NULL, "  block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n",
@@ -1019,6 +1020,9 @@ static av_cold int ipvideo_decode_init(AVCodecContext *avctx)
 
     dsputil_init(&s->dsp, avctx);
 
+    s->width = avctx->width;
+    s->height = avctx->height;
+
     /* decoding map contains 4 bits of information per 8x8 block */
     s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
 
@@ -1057,6 +1061,9 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
     if (!s->is_16bpp) {
         const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
         if (pal) {
+            s->decoding_map_size = s->avctx->width * s->avctx->height / (8 * 8 * 2);
+            s->width = s->avctx->width;
+            s->height = s->avctx->height;
             s->current_frame.palette_has_changed = 1;
             memcpy(s->pal, pal, AVPALETTE_SIZE);
         }
diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index 562b19a..2fa8cb0 100644
--- a/libavformat/ipmovie.c
+++ b/libavformat/ipmovie.c
@@ -601,6 +601,9 @@ static int ipmovie_read_packet(AVFormatContext *s,
     int ret;
 
     ret = process_ipmovie_chunk(ipmovie, pb, pkt);
+    s->streams[0]->codec->width = ipmovie->video_width;
+    s->streams[0]->codec->height = ipmovie->video_height;
+//    s->streams[0]->codec->bits_per_coded_sample = ipmovie->video_bpp;
     if (ret == CHUNK_BAD)
         ret = AVERROR_INVALIDDATA;
     else if (ret == CHUNK_EOF)
