diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index a141a475b7924bef416c375e00ea14ca8aa04bce..d486b3fd4beb3ef380b2eabe76f2ad946feb0324 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -217,6 +217,7 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
     uint8_t *yuv_line = NULL;
     int shift_h, shift_v;
 
+    s->avctx = avctx;
     s->buf_start = buf;
     s->buf = &ptr;
     s->buf_size = buf_size;