diff --git a/libavcodec/012v.c b/libavcodec/012v.c
index f0197cd8f9..fa5eb0f95e 100644
--- a/libavcodec/012v.c
+++ b/libavcodec/012v.c
@@ -65,7 +65,7 @@ static int zero12v_decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
 
     pic->pict_type = AV_PICTURE_TYPE_I;
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
 
     line_end = avpkt->data + stride;
     for (line = 0; line < avctx->height; line++) {
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index fab3fb5b77..411e50da7c 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -957,7 +957,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
         return AVERROR_INVALIDDATA;
     }
 
-    picture->key_frame = picture->pict_type == AV_PICTURE_TYPE_I;
+    if (picture->pict_type == AV_PICTURE_TYPE_I)
+        picture->flags |= AV_FRAME_FLAG_KEY;
+    else
+        picture->flags &= ~AV_FRAME_FLAG_KEY;
 
     av_image_copy_plane(picture->data[0], picture->linesize[0],
                         (const uint8_t*)f->frame_buffer,  avctx->width * 2,
diff --git a/libavcodec/agm.c b/libavcodec/agm.c
index b37f1a42c9..55cf0b47c8 100644
--- a/libavcodec/agm.c
+++ b/libavcodec/agm.c
@@ -1100,7 +1100,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return AVERROR_INVALIDDATA;
 
     s->key_frame = (avpkt->flags & AV_PKT_FLAG_KEY);
-    frame->key_frame = s->key_frame;
+    if (s->key_frame)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
     frame->pict_type = s->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     if (!s->key_frame) {
@@ -1171,7 +1174,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
         return ret;
 
-    if (frame->key_frame) {
+    if (frame->flags & AV_FRAME_FLAG_KEY) {
         if (!s->dct && !s->rgb)
             ret = decode_raw_intra(avctx, gbyte, frame);
         else if (!s->dct && s->rgb)
diff --git a/libavcodec/aic.c b/libavcodec/aic.c
index 7ba1c02fdd..f8b0f60354 100644
--- a/libavcodec/aic.c
+++ b/libavcodec/aic.c
@@ -393,7 +393,7 @@ static int aic_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     ctx->frame            = frame;
     ctx->frame->pict_type = AV_PICTURE_TYPE_I;
-    ctx->frame->key_frame = 1;
+    ctx->frame->flags |= AV_FRAME_FLAG_KEY;
 
     off = FFALIGN(AIC_HDR_SIZE + ctx->num_x_slices * ctx->mb_height * 2, 4);
 
diff --git a/libavcodec/aliaspixdec.c b/libavcodec/aliaspixdec.c
index 45155d79cd..72f810d408 100644
--- a/libavcodec/aliaspixdec.c
+++ b/libavcodec/aliaspixdec.c
@@ -70,7 +70,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *f,
         return ret;
 
     f->pict_type = AV_PICTURE_TYPE_I;
-    f->key_frame = 1;
+    f->flags |= AV_FRAME_FLAG_KEY;
 
     x = 0;
     y = 1;
diff --git a/libavcodec/arbc.c b/libavcodec/arbc.c
index 343c56695e..1b349f4dd6 100644
--- a/libavcodec/arbc.c
+++ b/libavcodec/arbc.c
@@ -171,7 +171,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return ret;
 
     frame->pict_type = prev_pixels <= 0 ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
-    frame->key_frame = prev_pixels <= 0;
+    if (prev_pixels <= 0)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/argo.c b/libavcodec/argo.c
index 9bedb1394d..589feed410 100644
--- a/libavcodec/argo.c
+++ b/libavcodec/argo.c
@@ -666,7 +666,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         return ret;
 
     frame->pict_type = s->key ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
-    frame->key_frame = s->key;
+    if (s->key)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index 699aab9f8f..62295b2dbb 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -245,7 +245,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     if (avctx->codec_id == AV_CODEC_ID_ASV1) {
         av_fast_padded_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size,
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 807852e317..c90c9c1a69 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -846,7 +846,10 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f)
         goto fail;
 
     frame = f->f;
-    frame->key_frame = header->frame_type == AV1_FRAME_KEY;
+    if (header->frame_type == AV1_FRAME_KEY)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
 
     switch (header->frame_type) {
     case AV1_FRAME_KEY:
diff --git a/libavcodec/avrndec.c b/libavcodec/avrndec.c
index ef194058fc..97d2824625 100644
--- a/libavcodec/avrndec.c
+++ b/libavcodec/avrndec.c
@@ -68,7 +68,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type= AV_PICTURE_TYPE_I;
-    p->key_frame= 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     if(a->interlace) {
         buf += (true_height - avctx->height)*avctx->width;
diff --git a/libavcodec/avs.c b/libavcodec/avs.c
index a1c9d3c436..b53175f640 100644
--- a/libavcodec/avs.c
+++ b/libavcodec/avs.c
@@ -61,7 +61,7 @@ static int avs_decode_frame(AVCodecContext * avctx, AVFrame *picture,
     if ((ret = ff_reget_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_P;
-    p->key_frame = 0;
+    p->flags &= ~AV_FRAME_FLAG_KEY;
 
     out    = p->data[0];
     stride = p->linesize[0];
@@ -97,7 +97,7 @@ static int avs_decode_frame(AVCodecContext * avctx, AVFrame *picture,
     switch (sub_type) {
     case AVS_I_FRAME:
         p->pict_type = AV_PICTURE_TYPE_I;
-        p->key_frame = 1;
+        p->flags |= AV_FRAME_FLAG_KEY;
     case AVS_P_FRAME_3X3:
         vect_w = 3;
         vect_h = 3;
diff --git a/libavcodec/avuidec.c b/libavcodec/avuidec.c
index ba157e167c..48b23d4875 100644
--- a/libavcodec/avuidec.c
+++ b/libavcodec/avuidec.c
@@ -71,7 +71,7 @@ static int avui_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     if (!interlaced) {
diff --git a/libavcodec/bfi.c b/libavcodec/bfi.c
index c268272451..55429d4b7c 100644
--- a/libavcodec/bfi.c
+++ b/libavcodec/bfi.c
@@ -68,7 +68,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     /* Set frame parameters and palette, if necessary */
     if (!avctx->frame_num) {
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         /* Setting the palette */
         if (avctx->extradata_size > 768) {
             av_log(avctx, AV_LOG_ERROR, "Palette is too large.\n");
@@ -87,7 +87,7 @@ static int bfi_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         frame->palette_has_changed = 1;
     } else {
         frame->pict_type = AV_PICTURE_TYPE_P;
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->palette_has_changed = 0;
         memcpy(frame->data[1], bfi->pal, sizeof(bfi->pal));
     }
diff --git a/libavcodec/bitpacked_dec.c b/libavcodec/bitpacked_dec.c
index a1ffef185c..c88f861993 100644
--- a/libavcodec/bitpacked_dec.c
+++ b/libavcodec/bitpacked_dec.c
@@ -134,7 +134,7 @@ static int bitpacked_decode(AVCodecContext *avctx, AVFrame *frame,
         return res;
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     *got_frame = 1;
     return buf_size;
diff --git a/libavcodec/bmp.c b/libavcodec/bmp.c
index d7e01f0725..d117c06cf4 100644
--- a/libavcodec/bmp.c
+++ b/libavcodec/bmp.c
@@ -210,7 +210,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     buf   = buf0 + hsize;
     dsize = buf_size - hsize;
diff --git a/libavcodec/brenderpix.c b/libavcodec/brenderpix.c
index e95ab3d4af..85eb55f50b 100644
--- a/libavcodec/brenderpix.c
+++ b/libavcodec/brenderpix.c
@@ -278,7 +278,7 @@ static int pix_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                         bytes_per_scanline, hdr.height);
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/c93.c b/libavcodec/c93.c
index bfcbc7c150..b872f95e9b 100644
--- a/libavcodec/c93.c
+++ b/libavcodec/c93.c
@@ -147,10 +147,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     b = bytestream2_get_byte(&gb);
     if (b & C93_FIRST_FRAME) {
         newpic->pict_type = AV_PICTURE_TYPE_I;
-        newpic->key_frame = 1;
+        newpic->flags |= AV_FRAME_FLAG_KEY;
     } else {
         newpic->pict_type = AV_PICTURE_TYPE_P;
-        newpic->key_frame = 0;
+        newpic->flags &= ~AV_FRAME_FLAG_KEY;
     }
 
     for (y = 0; y < HEIGHT; y += 8) {
diff --git a/libavcodec/cdxl.c b/libavcodec/cdxl.c
index 6b3b3e85e0..885047af84 100644
--- a/libavcodec/cdxl.c
+++ b/libavcodec/cdxl.c
@@ -305,7 +305,7 @@ static int cdxl_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     if (encoding) {
         av_fast_padded_malloc(&c->new_video, &c->new_video_size,
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index 282614fd1d..e91f2f1012 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -379,7 +379,7 @@ static int cinepak_decode (CinepakContext *s)
 
     num_strips = FFMIN(num_strips, MAX_STRIPS);
 
-    s->frame->key_frame = 0;
+    s->frame->flags &= ~AV_FRAME_FLAG_KEY;
 
     for (i=0; i < num_strips; i++) {
         if ((s->data + 12) > eod)
@@ -395,7 +395,7 @@ static int cinepak_decode (CinepakContext *s)
         s->strips[i].x2 = AV_RB16 (&s->data[10]);
 
         if (s->strips[i].id == 0x10)
-            s->frame->key_frame = 1;
+            s->frame->flags |= AV_FRAME_FLAG_KEY;
 
         strip_size = AV_RB24 (&s->data[1]) - 12;
         if (strip_size < 0)
diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c
index e77661d187..f84e3e6ea4 100644
--- a/libavcodec/clearvideo.c
+++ b/libavcodec/clearvideo.c
@@ -511,7 +511,7 @@ static int clv_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
             return ret;
 
-        c->pic->key_frame = 1;
+        c->pic->flags |= AV_FRAME_FLAG_KEY;
         c->pic->pict_type = AV_PICTURE_TYPE_I;
 
         bytestream2_get_be32(&gb); // frame size;
@@ -605,7 +605,7 @@ static int clv_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         }
         extend_edges(c->pic, c->tile_size);
 
-        c->pic->key_frame = 0;
+        c->pic->flags &= ~AV_FRAME_FLAG_KEY;
         c->pic->pict_type = AV_PICTURE_TYPE_P;
     }
 
diff --git a/libavcodec/cljrdec.c b/libavcodec/cljrdec.c
index 914f853c8f..a4baa015f6 100644
--- a/libavcodec/cljrdec.c
+++ b/libavcodec/cljrdec.c
@@ -51,7 +51,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     init_get_bits(&gb, buf, buf_size * 8);
 
diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c
index 911717b68d..52cb86e50b 100644
--- a/libavcodec/cllc.c
+++ b/libavcodec/cllc.c
@@ -460,7 +460,7 @@ static int cllc_decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return AVERROR_INVALIDDATA;
     }
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     *got_picture_ptr = 1;
diff --git a/libavcodec/cpia.c b/libavcodec/cpia.c
index bfd270dae2..f62100c419 100644
--- a/libavcodec/cpia.c
+++ b/libavcodec/cpia.c
@@ -94,10 +94,10 @@ static int cpia_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     if (header[28] == NOT_COMPRESSED) {
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
     } else {
         frame->pict_type = AV_PICTURE_TYPE_P;
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
     }
 
     // Get buffer filled with previous frame
diff --git a/libavcodec/cri.c b/libavcodec/cri.c
index 5761152c2d..0380a0c665 100644
--- a/libavcodec/cri.c
+++ b/libavcodec/cri.c
@@ -408,7 +408,7 @@ skip:
     }
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     *got_frame = 1;
 
diff --git a/libavcodec/cscd.c b/libavcodec/cscd.c
index b4ed3332a9..23dd2df99e 100644
--- a/libavcodec/cscd.c
+++ b/libavcodec/cscd.c
@@ -110,12 +110,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     // flip upside down, add difference frame
     if (buf[0] & 1) { // keyframe
         c->pic->pict_type = AV_PICTURE_TYPE_I;
-        c->pic->key_frame = 1;
+        c->pic->flags |= AV_FRAME_FLAG_KEY;
               copy_frame_default(c->pic, c->decomp_buf,
                                  c->linelen, c->height);
     } else {
         c->pic->pict_type = AV_PICTURE_TYPE_P;
-        c->pic->key_frame = 0;
+        c->pic->flags &= ~AV_FRAME_FLAG_KEY;
               add_frame_default(c->pic, c->decomp_buf,
                                 c->linelen, c->height);
     }
diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 76e70aa648..32ebda01e5 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -599,7 +599,10 @@ static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
             goto error;
         }
 
-        frame->key_frame = ctx->key_frame[parsed_frame.dispinfo.picture_index];
+        if (ctx->key_frame[parsed_frame.dispinfo.picture_index])
+            frame->flags |= AV_FRAME_FLAG_KEY;
+        else
+            frame->flags &= ~AV_FRAME_FLAG_KEY;
         ctx->key_frame[parsed_frame.dispinfo.picture_index] = 0;
 
         frame->width = avctx->width;
diff --git a/libavcodec/dds.c b/libavcodec/dds.c
index 4bb425dbb3..670a42fbf9 100644
--- a/libavcodec/dds.c
+++ b/libavcodec/dds.c
@@ -702,7 +702,7 @@ static int dds_decode(AVCodecContext *avctx, AVFrame *frame,
 
     /* Frame is ready to be output. */
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 40f5a3ba59..edc6a6acba 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -570,6 +570,9 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
     }
 
     if (!ret) {
+        if (avctx->codec_type != AVMEDIA_TYPE_VIDEO)
+            frame->flags |= AV_FRAME_FLAG_KEY;
+        frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY);
         frame->best_effort_timestamp = guess_correct_pts(avctx,
                                                          frame->pts,
                                                          frame->pkt_dts);
diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index 0ae582befe..277c730cc7 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -2230,7 +2230,10 @@ static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int
         s->hq_picture    = (parse_code & 0xF8) == 0xE8;          /* [DIRAC_STD] is_hq_picture()       */
         s->dc_prediction = (parse_code & 0x28) == 0x08;          /* [DIRAC_STD] using_dc_prediction() */
         pic->reference   = (parse_code & 0x0C) == 0x0C;          /* [DIRAC_STD] is_reference()        */
-        pic->avframe->key_frame = s->num_refs == 0;              /* [DIRAC_STD] is_intra()            */
+        if (s->num_refs == 0)                                    /* [DIRAC_STD] is_intra()            */
+             pic->avframe->flags |= AV_FRAME_FLAG_KEY;
+        else
+             pic->avframe->flags &= ~AV_FRAME_FLAG_KEY;
         pic->avframe->pict_type = s->num_refs + 1;               /* Definition of AVPictureType in avutil.h */
 
         /* VC-2 Low Delay has a different parse code than the Dirac Low Delay */
diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 7cc4f94c7f..942aaed67a 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -652,7 +652,7 @@ decode_coding_unit:
         if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
             return ret;
         picture->pict_type = AV_PICTURE_TYPE_I;
-        picture->key_frame = 1;
+        picture->flags |= AV_FRAME_FLAG_KEY;
     }
 
     ctx->buf_size = buf_size - ctx->data_offset;
diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index afc4bb0bcd..36840986ab 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -646,7 +646,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     }
 
     s->frame            = frame;
-    frame->key_frame    = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     frame->pict_type    = AV_PICTURE_TYPE_I;
     avctx->pix_fmt      = s->sys->pix_fmt;
     avctx->framerate    = av_inv_q(s->sys->time_base);
diff --git a/libavcodec/dxa.c b/libavcodec/dxa.c
index 8d2d2d771b..ecb48c9d3f 100644
--- a/libavcodec/dxa.c
+++ b/libavcodec/dxa.c
@@ -258,19 +258,19 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     switch(compr){
     case -1:
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
         if (c->prev->data[0])
             memcpy(frame->data[0], c->prev->data[0], frame->linesize[0] * avctx->height);
         else{ // Should happen only when first frame is 'NULL'
             memset(frame->data[0], 0, frame->linesize[0] * avctx->height);
-            frame->key_frame = 1;
+            frame->flags |= AV_FRAME_FLAG_KEY;
             frame->pict_type = AV_PICTURE_TYPE_I;
         }
         break;
     case 2:
     case 4:
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
         for (j = 0; j < avctx->height; j++) {
                 memcpy(outptr, srcptr, avctx->width);
@@ -285,7 +285,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
             if (!(avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL))
                 return AVERROR_INVALIDDATA;
         }
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
         for (j = 0; j < avctx->height; j++) {
             if(tmpptr){
@@ -300,7 +300,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         break;
     case 12: // ScummVM coding
     case 13:
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
         if (!c->prev->data[0]) {
             av_log(avctx, AV_LOG_ERROR, "Missing reference frame\n");
diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index e13d274862..f36420cdd9 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -864,7 +864,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
 
     pic->pict_type = AV_PICTURE_TYPE_I;
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 7c84874229..5923811b29 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -1220,7 +1220,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 
     /* Frame is ready to be output. */
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/eacmv.c b/libavcodec/eacmv.c
index 18f27dfdf0..e73e310c4a 100644
--- a/libavcodec/eacmv.c
+++ b/libavcodec/eacmv.c
@@ -202,10 +202,10 @@ static int cmv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     buf += EA_PREAMBLE_SIZE;
     if ((buf[0]&1)) {  // subtype
         cmv_decode_inter(s, frame, buf+2, buf_end);
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
     }else{
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
         cmv_decode_intra(s, frame, buf+2, buf_end);
     }
diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index 01e1acd4e4..0f0ed3585f 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -237,7 +237,7 @@ static int tgq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     frame->pict_type = AV_PICTURE_TYPE_I;
 
     for (y = 0; y < FFALIGN(avctx->height, 16) >> 4; y++)
diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c
index 29f7ee12f5..a2aead46eb 100644
--- a/libavcodec/eatgv.c
+++ b/libavcodec/eatgv.c
@@ -310,7 +310,7 @@ static int tgv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     if (chunk_type == kVGT_TAG) {
         int y;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
 
         if (!s->frame_buffer &&
@@ -330,7 +330,7 @@ static int tgv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             av_log(avctx, AV_LOG_WARNING, "inter frame without corresponding intra frame\n");
             return buf_size;
         }
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
         if (tgv_decode_inter(s, frame, buf, buf_end) < 0) {
             av_log(avctx, AV_LOG_WARNING, "truncated inter frame\n");
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 041fc7670e..d3c0bf6aad 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -192,6 +192,9 @@ int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
 
     av_frame_move_ref(frame, avci->buffer_frame);
 
+    if (frame->key_frame)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+
     return 0;
 }
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a3f9302233..98fa0a8ea5 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -264,16 +264,16 @@ static int decode_slice(AVCodecContext *c, void *arg)
     for( si=0; fs != f->slice_context[si]; si ++)
         ;
 
-    if(f->fsrc && !p->key_frame)
+    if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY))
         ff_thread_await_progress(&f->last_picture, si, 0);
 
-    if(f->fsrc && !p->key_frame) {
+    if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
         FFV1Context *fssrc = f->fsrc->slice_context[si];
         FFV1Context *fsdst = f->slice_context[si];
         av_assert1(fsdst->plane_count == fssrc->plane_count);
         av_assert1(fsdst == fs);
 
-        if (!p->key_frame)
+        if (!(p->flags & AV_FRAME_FLAG_KEY))
             fsdst->slice_damaged |= fssrc->slice_damaged;
 
         for (i = 0; i < f->plane_count; i++) {
@@ -310,7 +310,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
     }
     if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
         return ret;
-    if (f->cur->key_frame || fs->slice_reset_contexts) {
+    if ((f->cur->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
         ff_ffv1_clear_slice_state(f, fs);
     } else if (fs->slice_damaged) {
         return AVERROR_INVALIDDATA;
@@ -892,7 +892,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
     if (get_rac(c, &keystate)) {
-        p->key_frame    = 1;
+        p->flags |= AV_FRAME_FLAG_KEY;
         f->key_frame_ok = 0;
         if ((ret = read_header(f)) < 0)
             return ret;
@@ -903,7 +903,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                    "Cannot decode non-keyframe without valid keyframe\n");
             return AVERROR_INVALIDDATA;
         }
-        p->key_frame = 0;
+        p->flags &= ~AV_FRAME_FLAG_KEY;
     }
 
     if (f->ac != AC_GOLOMB_RICE) {
@@ -927,7 +927,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     if (avctx->debug & FF_DEBUG_PICT_INFO)
         av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d slices:%d bps:%d\n",
-               f->version, p->key_frame, f->ac, f->ec, f->slice_count, f->avctx->bits_per_raw_sample);
+               f->version, !!(p->flags & AV_FRAME_FLAG_KEY), f->ac, f->ec, f->slice_count, f->avctx->bits_per_raw_sample);
 
     ff_thread_finish_setup(avctx);
 
diff --git a/libavcodec/fic.c b/libavcodec/fic.c
index 94cf42887f..fb99802137 100644
--- a/libavcodec/fic.c
+++ b/libavcodec/fic.c
@@ -406,11 +406,11 @@ static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                               NULL, nslices, sizeof(ctx->slice_data[0]))) < 0)
         return ret;
 
-    ctx->frame->key_frame = 1;
+    ctx->frame->flags |= AV_FRAME_FLAG_KEY;
     ctx->frame->pict_type = AV_PICTURE_TYPE_I;
     for (slice = 0; slice < nslices; slice++) {
         if (ctx->slice_data[slice].p_frame) {
-            ctx->frame->key_frame = 0;
+            ctx->frame->flags &= ~AV_FRAME_FLAG_KEY;
             ctx->frame->pict_type = AV_PICTURE_TYPE_P;
             break;
         }
diff --git a/libavcodec/fitsdec.c b/libavcodec/fitsdec.c
index b9c51e70c3..44135309f2 100644
--- a/libavcodec/fitsdec.c
+++ b/libavcodec/fitsdec.c
@@ -301,7 +301,7 @@ static int fits_decode_frame(AVCodecContext *avctx, AVFrame *p,
         }
     }
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame = 1;
diff --git a/libavcodec/fmvc.c b/libavcodec/fmvc.c
index 3ee915cc4c..5e26a541ca 100644
--- a/libavcodec/fmvc.c
+++ b/libavcodec/fmvc.c
@@ -433,7 +433,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
             return ret;
 
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
 
         src = s->buffer;
@@ -519,7 +519,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
             return ret;
 
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
 
         ssrc = s->buffer;
diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 4c4c46b602..e7a23f20fe 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -216,7 +216,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *f,
     }
 
     f->pict_type = AV_PICTURE_TYPE_I;
-    f->key_frame = 1;
+    f->flags |= AV_FRAME_FLAG_KEY;
 
     avctx->pix_fmt = version & 1 ? is_pal ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_BGR24 : AV_PIX_FMT_YUVJ420P;
     avctx->color_range = version & 1 ? AVCOL_RANGE_UNSPECIFIED
diff --git a/libavcodec/frwu.c b/libavcodec/frwu.c
index cf183f8410..70bc136765 100644
--- a/libavcodec/frwu.c
+++ b/libavcodec/frwu.c
@@ -63,7 +63,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
 
     pic->pict_type = AV_PICTURE_TYPE_I;
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
 
     for (field = 0; field < 2; field++) {
         int i;
diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index 32b966e8ef..134cdc8ff6 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -1560,7 +1560,10 @@ static int g2m_decode_frame(AVCodecContext *avctx, AVFrame *pic,
         if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
             return ret;
 
-        pic->key_frame = got_header;
+        if (got_header)
+            pic->flags |= AV_FRAME_FLAG_KEY;
+        else
+            pic->flags &= ~AV_FRAME_FLAG_KEY;
         pic->pict_type = got_header ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
         for (i = 0; i < avctx->height; i++)
diff --git a/libavcodec/gemdec.c b/libavcodec/gemdec.c
index c8fd8dcdcd..73e907c041 100644
--- a/libavcodec/gemdec.c
+++ b/libavcodec/gemdec.c
@@ -180,7 +180,7 @@ static int gem_decode_frame(AVCodecContext *avctx, AVFrame *p,
         return ret;
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->palette_has_changed = 1;
     palette = (uint32_t  *)p->data[1];
 
diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
index f47390c3bd..0835c5bdd0 100644
--- a/libavcodec/gifdec.c
+++ b/libavcodec/gifdec.c
@@ -501,7 +501,7 @@ static int gif_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
             return AVERROR(ENOMEM);
 
         s->frame->pict_type = AV_PICTURE_TYPE_I;
-        s->frame->key_frame = 1;
+        s->frame->flags |= AV_FRAME_FLAG_KEY;
         s->keyframe_ok = 1;
     } else {
         if (!s->keyframe_ok) {
@@ -513,7 +513,7 @@ static int gif_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
             return ret;
 
         s->frame->pict_type = AV_PICTURE_TYPE_P;
-        s->frame->key_frame = 0;
+        s->frame->flags &= ~AV_FRAME_FLAG_KEY;
     }
 
     ret = gif_parse_next_image(s, s->frame);
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 8496293964..620b7eef83 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -643,7 +643,10 @@ retry:
 
     // for skipping the frame
     s->current_picture.f->pict_type = s->pict_type;
-    s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+    if (s->pict_type == AV_PICTURE_TYPE_I)
+        s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
 
     if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
         (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 7767e16cf1..40d5188ac9 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -501,7 +501,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
      * in later.
      * See decode_nal_units().
      */
-    pic->f->key_frame = 0;
+    pic->f->flags   &= ~AV_FRAME_FLAG_KEY;
     pic->mmco_reset  = 0;
     pic->recovered   = 0;
     pic->invalid_gap = 0;
@@ -1319,7 +1319,7 @@ static int h264_select_output_frame(H264Context *h)
     out     = h->delayed_pic[0];
     out_idx = 0;
     for (i = 1; h->delayed_pic[i] &&
-                !h->delayed_pic[i]->f->key_frame &&
+                !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) &&
                 !h->delayed_pic[i]->mmco_reset;
          i++)
         if (h->delayed_pic[i]->poc < out->poc) {
@@ -1327,7 +1327,7 @@ static int h264_select_output_frame(H264Context *h)
             out_idx = i;
         }
     if (h->avctx->has_b_frames == 0 &&
-        (h->delayed_pic[0]->f->key_frame || h->delayed_pic[0]->mmco_reset))
+        ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset))
         h->next_outputed_poc = INT_MIN;
     out_of_order = out->poc < h->next_outputed_poc;
 
@@ -1338,7 +1338,7 @@ static int h264_select_output_frame(H264Context *h)
     }
     if (!out_of_order && pics > h->avctx->has_b_frames) {
         h->next_output_pic = out;
-        if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f->key_frame || h->delayed_pic[0]->mmco_reset)) {
+        if (out_idx == 0 && h->delayed_pic[0] && ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset)) {
             h->next_outputed_poc = INT_MIN;
         } else
             h->next_outputed_poc = out->poc;
@@ -1628,7 +1628,7 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl,
         }
     }
 
-    h->cur_pic_ptr->f->key_frame |= (nal->type == H264_NAL_IDR_SLICE);
+    h->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY * !!(nal->type == H264_NAL_IDR_SLICE);
 
     if (nal->type == H264_NAL_IDR_SLICE ||
         (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) {
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 2d691731c5..cdd4b98c83 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -849,7 +849,7 @@ static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
     av_dict_set(&dst->metadata, "stereo_mode", ff_h264_sei_stereo_mode(&h->sei.common.frame_packing), 0);
 
     if (srcp->sei_recovery_frame_cnt == 0)
-        dst->key_frame = 1;
+        dst->flags |= AV_FRAME_FLAG_KEY;
 
     if (h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) {
         ret = h264_export_enc_params(dst, srcp);
@@ -951,7 +951,7 @@ static int send_next_delayed_frame(H264Context *h, AVFrame *dst_frame,
     out_idx = 0;
     for (i = 1;
          h->delayed_pic[i] &&
-         !h->delayed_pic[i]->f->key_frame &&
+         !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) &&
          !h->delayed_pic[i]->mmco_reset;
          i++)
         if (h->delayed_pic[i]->poc < out->poc) {
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index 3df69e6335..fee3c04d84 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -328,7 +328,7 @@ static int hap_decode(AVCodecContext *avctx, AVFrame *frame,
 
     /* Frame is ready to be output */
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/hdrdec.c b/libavcodec/hdrdec.c
index 998227744b..9b6395bb6d 100644
--- a/libavcodec/hdrdec.c
+++ b/libavcodec/hdrdec.c
@@ -212,7 +212,7 @@ convert:
         }
     }
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame   = 1;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 1a0beac901..8af46ea9bc 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2914,7 +2914,10 @@ static int hevc_frame_start(HEVCContext *s)
         goto fail;
     }
 
-    s->ref->frame->key_frame = IS_IRAP(s);
+    if (IS_IRAP(s))
+        s->ref->frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->ref->frame->flags &= ~AV_FRAME_FLAG_KEY;
 
     s->ref->needs_fg = s->sei.common.film_grain_characteristics.present &&
         !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
diff --git a/libavcodec/hnm4video.c b/libavcodec/hnm4video.c
index f223bb82fc..51e75789d2 100644
--- a/libavcodec/hnm4video.c
+++ b/libavcodec/hnm4video.c
@@ -420,7 +420,7 @@ static int hnm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             postprocess_current_frame(avctx);
         copy_processed_frame(avctx, frame);
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         memcpy(frame->data[1], hnm->palette, 256 * 4);
         *got_frame = 1;
     } else if (chunk_id == HNM4_CHUNK_ID_IU) {
@@ -438,7 +438,7 @@ static int hnm_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         }
         copy_processed_frame(avctx, frame);
         frame->pict_type = AV_PICTURE_TYPE_P;
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         memcpy(frame->data[1], hnm->palette, 256 * 4);
         *got_frame = 1;
         FFSWAP(uint8_t *, hnm->current, hnm->previous);
diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index 6ce73b7ae4..db0ac7d9e4 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -354,7 +354,7 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
     }
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame = 1;
diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index 6083946550..6554b15ec6 100644
--- a/libavcodec/hqx.c
+++ b/libavcodec/hqx.c
@@ -504,7 +504,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     avctx->execute2(avctx, decode_slice_thread, NULL, NULL, 16);
 
-    ctx->pic->key_frame = 1;
+    ctx->pic->flags |= AV_FRAME_FLAG_KEY;
     ctx->pic->pict_type = AV_PICTURE_TYPE_I;
 
     *got_picture_ptr = 1;
diff --git a/libavcodec/iff.c b/libavcodec/iff.c
index e02d2e77e5..faf4e21c42 100644
--- a/libavcodec/iff.c
+++ b/libavcodec/iff.c
@@ -1887,10 +1887,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     }
 
     if (avpkt->flags & AV_PKT_FLAG_KEY) {
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
     } else {
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
     }
 
diff --git a/libavcodec/imm4.c b/libavcodec/imm4.c
index ccec5dff43..b95ad86921 100644
--- a/libavcodec/imm4.c
+++ b/libavcodec/imm4.c
@@ -420,11 +420,11 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     switch (type) {
     case 0x19781977:
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
         break;
     case 0x12250926:
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
         break;
     default:
@@ -434,7 +434,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     if (avctx->width  != width ||
         avctx->height != height) {
-        if (!frame->key_frame) {
+        if (!(frame->flags & AV_FRAME_FLAG_KEY)) {
             av_log(avctx, AV_LOG_ERROR, "Frame size change is unsupported.\n");
             return AVERROR_INVALIDDATA;
         }
@@ -445,10 +445,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (ret < 0)
         return ret;
 
-    if ((ret = ff_get_buffer(avctx, frame, frame->key_frame ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
+    if ((ret = ff_get_buffer(avctx, frame, (frame->flags & AV_FRAME_FLAG_KEY) ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
         return ret;
 
-    if (frame->key_frame) {
+    if (frame->flags & AV_FRAME_FLAG_KEY) {
         ret = decode_intra(avctx, gb, frame);
         if (ret < 0)
             return ret;
diff --git a/libavcodec/imx.c b/libavcodec/imx.c
index 44bab23c27..4ae68eb93c 100644
--- a/libavcodec/imx.c
+++ b/libavcodec/imx.c
@@ -59,9 +59,9 @@ static int imx_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     if (ff_copy_palette(imx->pal, avpkt, avctx)) {
         frame->palette_has_changed = 1;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
     } else {
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->palette_has_changed = 0;
     }
 
@@ -92,7 +92,7 @@ static int imx_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                     break;
             }
 
-            frame->key_frame = 0;
+            frame->flags &= ~AV_FRAME_FLAG_KEY;
             break;
         case 1:
             if (len == 0) {
@@ -114,7 +114,7 @@ static int imx_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                         break;
                 }
 
-                frame->key_frame = 0;
+                frame->flags &= ~AV_FRAME_FLAG_KEY;
             } else {
                 while (len > 0) {
                     fill = bytestream2_get_byte(&gb);
@@ -150,7 +150,7 @@ static int imx_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         }
     }
 
-    frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+    frame->pict_type = (frame->flags & AV_FRAME_FLAG_KEY) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     if ((ret = av_frame_ref(rframe, frame)) < 0)
         return ret;
diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index c2b81ec103..bfd95e117b 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -2532,7 +2532,7 @@ static int jpeg2000_decode_frame(AVCodecContext *avctx, AVFrame *picture,
     if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
         goto end;
     picture->pict_type = AV_PICTURE_TYPE_I;
-    picture->key_frame = 1;
+    picture->flags |= AV_FRAME_FLAG_KEY;
 
     if (ret = jpeg2000_read_bitstream_packets(s))
         goto end;
diff --git a/libavcodec/jvdec.c b/libavcodec/jvdec.c
index e0287a9cb9..f44b21af11 100644
--- a/libavcodec/jvdec.c
+++ b/libavcodec/jvdec.c
@@ -211,7 +211,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     }
 
     if (video_size) {
-        s->frame->key_frame           = 1;
+        s->frame->flags |= AV_FRAME_FLAG_KEY;
         s->frame->pict_type           = AV_PICTURE_TYPE_I;
         s->frame->palette_has_changed = s->palette_has_changed;
         s->palette_has_changed        = 0;
diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c
index 153cea03b9..de01f6b75b 100644
--- a/libavcodec/kmvc.c
+++ b/libavcodec/kmvc.c
@@ -288,10 +288,10 @@ static int decode_frame(AVCodecContext * avctx, AVFrame *frame,
     }
 
     if (header & KMVC_KEYFRAME) {
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
     } else {
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
     }
 
diff --git a/libavcodec/lagarith.c b/libavcodec/lagarith.c
index 78ccbc15b9..ebc1f7613a 100644
--- a/libavcodec/lagarith.c
+++ b/libavcodec/lagarith.c
@@ -550,7 +550,7 @@ static int lag_decode_frame(AVCodecContext *avctx, AVFrame *p,
     int i, j, planes = 3;
     int ret = 0;
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     frametype = buf[0];
diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c
index 5cc0a29bcd..d8b17d5a7c 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -464,7 +464,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return AVERROR_INVALIDDATA;
     }
 
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     frame->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame = 1;
diff --git a/libavcodec/libaomdec.c b/libavcodec/libaomdec.c
index 53982559d9..767c216aa9 100644
--- a/libavcodec/libaomdec.c
+++ b/libavcodec/libaomdec.c
@@ -185,7 +185,10 @@ static int aom_decode(AVCodecContext *avctx, AVFrame *picture,
             aom_codec_frame_flags_t flags;
             ret = aom_codec_control(&ctx->decoder, AOMD_GET_FRAME_FLAGS, &flags);
             if (ret == AOM_CODEC_OK) {
-                picture->key_frame = !!(flags & AOM_FRAME_IS_KEY);
+                if (flags & AOM_FRAME_IS_KEY)
+                    picture->flags |= AV_FRAME_FLAG_KEY;
+                else
+                    picture->flags &= ~AV_FRAME_FLAG_KEY;
                 if (flags & (AOM_FRAME_IS_KEY | AOM_FRAME_IS_INTRAONLY))
                     picture->pict_type = AV_PICTURE_TYPE_I;
                 else if (flags & AOM_FRAME_IS_SWITCH)
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index ddf2311a41..87aed16749 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -463,7 +463,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
         goto fail;
 
     frame->pkt_dts = pkt->pts;
-    frame->key_frame = p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY;
+    if (p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
 
     switch (p->frame_hdr->frame_type) {
     case DAV1D_FRAME_TYPE_KEY:
diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index 045a1535f9..65966b7b57 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -411,7 +411,7 @@ static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_f
             /* full image is one frame, even if animated */
             av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
             frame->pict_type = AV_PICTURE_TYPE_I;
-            frame->key_frame = 1;
+            frame->flags |= AV_FRAME_FLAG_KEY;
             if (ctx->iccp) {
                 AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp);
                 if (!sd)
diff --git a/libavcodec/librsvgdec.c b/libavcodec/librsvgdec.c
index 9c8aa2dedc..2f160edcdf 100644
--- a/libavcodec/librsvgdec.c
+++ b/libavcodec/librsvgdec.c
@@ -73,7 +73,7 @@ static int librsvg_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = ff_get_buffer(avctx, frame, 0)))
         return ret;
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     image = cairo_image_surface_create_for_data(frame->data[0], CAIRO_FORMAT_ARGB32,
                                                 frame->width, frame->height,
diff --git a/libavcodec/libuavs3d.c b/libavcodec/libuavs3d.c
index 5c08d2b8d3..66e8d31001 100644
--- a/libavcodec/libuavs3d.c
+++ b/libavcodec/libuavs3d.c
@@ -96,7 +96,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
         av_log(NULL, AV_LOG_WARNING, "Error frame type in uavs3d: %d.\n", dec_frame->type);
     } else {
         frm->pict_type = ff_avs3_image_type[dec_frame->type];
-        frm->key_frame = (frm->pict_type == AV_PICTURE_TYPE_I);
+        if (frm->pict_type == AV_PICTURE_TYPE_I)
+            frm->flags |= AV_FRAME_FLAG_KEY;
+        else
+            frm->flags &= ~AV_FRAME_FLAG_KEY;
     }
 
     for (i = 0; i < 3; i++) {
diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index d57a67317a..3d11823284 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -206,7 +206,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
 
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
 #define ADVANCE_BY_DECODED do { \
     if (decoded < 0 || decoded >= buf_size) goto buf_too_small; \
diff --git a/libavcodec/lscrdec.c b/libavcodec/lscrdec.c
index 76a46751f0..415914bf0a 100644
--- a/libavcodec/lscrdec.c
+++ b/libavcodec/lscrdec.c
@@ -154,10 +154,13 @@ static int decode_frame_lscr(AVCodecContext *avctx, AVFrame *rframe,
 
         size = bytestream2_get_le32(gb);
 
-        frame->key_frame = (nb_blocks == 1) &&
-                           (w == avctx->width) &&
-                           (h == avctx->height) &&
-                           (x == 0) && (y == 0);
+        if ((nb_blocks == 1) &&
+            (w == avctx->width) &&
+            (h == avctx->height) &&
+            (x == 0) && (y == 0))
+            frame->flags |= AV_FRAME_FLAG_KEY;
+        else
+            frame->flags &= ~AV_FRAME_FLAG_KEY;
 
         bytestream2_seek(gb, 2 + nb_blocks * 12 + offset, SEEK_SET);
         csize = bytestream2_get_be32(gb);
@@ -199,7 +202,7 @@ static int decode_frame_lscr(AVCodecContext *avctx, AVFrame *rframe,
         }
     }
 
-    frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+    frame->pict_type = (frame->flags & AV_FRAME_FLAG_KEY) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     if ((ret = av_frame_ref(rframe, frame)) < 0)
         return ret;
diff --git a/libavcodec/m101.c b/libavcodec/m101.c
index 3def577b74..e3e8ca43e5 100644
--- a/libavcodec/m101.c
+++ b/libavcodec/m101.c
@@ -67,7 +67,7 @@ static int m101_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     frame->interlaced_frame = ((avctx->extradata[3*4] & 3) != 3);
     if (frame->interlaced_frame)
         frame->top_field_first = avctx->extradata[3*4] & 1;
diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 62263409b1..7898cd5be4 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -637,7 +637,7 @@ static int magy_decode_frame(AVCodecContext *avctx, AVFrame *p,
         return ret;
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0)
         return ret;
diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 640b671a0f..44b12471a9 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -177,7 +177,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = ff_thread_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     av_fast_padded_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size);
     if (!a->bitstream_buffer)
diff --git a/libavcodec/midivid.c b/libavcodec/midivid.c
index 599d5c8f8f..70730231b5 100644
--- a/libavcodec/midivid.c
+++ b/libavcodec/midivid.c
@@ -222,7 +222,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         return ret;
 
     frame->pict_type = key ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
-    frame->key_frame = key;
+    if (key)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 3fc18aac73..9117149471 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -723,7 +723,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
 
         if (s->avctx->skip_frame == AVDISCARD_ALL) {
             s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
-            s->picture_ptr->key_frame = 1;
+            s->picture_ptr->flags |= AV_FRAME_FLAG_KEY;
             s->got_picture            = 1;
             return 0;
         }
@@ -732,7 +732,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
         if (ff_get_buffer(s->avctx, s->picture_ptr, AV_GET_BUFFER_FLAG_REF) < 0)
             return -1;
         s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
-        s->picture_ptr->key_frame = 1;
+        s->picture_ptr->flags |= AV_FRAME_FLAG_KEY;
         s->got_picture            = 1;
 
         // Lets clear the palette to avoid leaving uninitialized values in it
diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
index c3b2383dbc..381b492de3 100644
--- a/libavcodec/mobiclip.c
+++ b/libavcodec/mobiclip.c
@@ -1235,7 +1235,7 @@ static int mobiclip_decode(AVCodecContext *avctx, AVFrame *rframe,
 
     if (get_bits1(gb)) {
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         s->moflex = get_bits1(gb);
         s->dct_tab_idx = get_bits1(gb);
 
@@ -1256,7 +1256,7 @@ static int mobiclip_decode(AVCodecContext *avctx, AVFrame *rframe,
         memset(motion, 0, s->motion_size);
 
         frame->pict_type = AV_PICTURE_TYPE_P;
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         s->dct_tab_idx = 0;
 
         ret = setup_qtables(avctx, s->quantizer + (int64_t)get_se_golomb(gb));
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 6c4cbccc59..ebde68a4dd 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1343,7 +1343,10 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
         s->mpeg_f_code[1][1] = f_code;
     }
     s->current_picture.f->pict_type = s->pict_type;
-    s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+    if (s->pict_type == AV_PICTURE_TYPE_I)
+        s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
 
     if (avctx->debug & FF_DEBUG_PICT_INFO)
         av_log(avctx, AV_LOG_DEBUG,
@@ -1525,7 +1528,10 @@ static int mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
         } else
             s->pict_type = AV_PICTURE_TYPE_B;
         s->current_picture.f->pict_type = s->pict_type;
-        s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+        if (s->pict_type == AV_PICTURE_TYPE_I)
+            s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+        else
+            s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
     }
 
     s->intra_dc_precision         = get_bits(&s->gb, 2);
@@ -3046,7 +3052,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return AVERROR_INVALIDDATA;
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index a932b59678..9c5f48d00c 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -290,7 +290,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
     AVRational aspect_ratio = s->avctx->sample_aspect_ratio;
     int aspect_ratio_info;
 
-    if (!s->current_picture.f->key_frame)
+    if (!(s->current_picture.f->flags & AV_FRAME_FLAG_KEY))
         return;
 
     if (aspect_ratio.num == 0 || aspect_ratio.den == 0)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 522a0aada5..df169a559a 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -343,7 +343,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
     s->current_picture_ptr->field_picture      =  s->picture_structure != PICT_FRAME;
 
     s->current_picture_ptr->f->pict_type = s->pict_type;
-    s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+    if (s->pict_type == AV_PICTURE_TYPE_I)
+        s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
 
     if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
                                    s->current_picture_ptr)) < 0)
@@ -382,7 +385,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         s->last_picture_ptr = &s->picture[idx];
 
         s->last_picture_ptr->reference    = 3;
-        s->last_picture_ptr->f->key_frame = 0;
+        s->last_picture_ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
         s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
 
         if (alloc_picture(s, s->last_picture_ptr) < 0) {
@@ -424,7 +427,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         s->next_picture_ptr = &s->picture[idx];
 
         s->next_picture_ptr->reference   = 3;
-        s->next_picture_ptr->f->key_frame = 0;
+        s->next_picture_ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
         s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
 
         if (alloc_picture(s, s->next_picture_ptr) < 0) {
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 7d3c8875f2..e0a7f09dc5 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1696,7 +1696,10 @@ static int frame_start(MpegEncContext *s)
     }
 
     s->current_picture_ptr->f->pict_type = s->pict_type;
-    s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+    if (s->pict_type == AV_PICTURE_TYPE_I)
+        s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
 
     ff_mpeg_unref_picture(s->avctx, &s->current_picture);
     if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
@@ -1972,7 +1975,7 @@ vbv_retry:
                 return ret;
         }
 
-        if (s->current_picture.f->key_frame)
+        if (s->current_picture.f->flags & AV_FRAME_FLAG_KEY)
             pkt->flags |= AV_PKT_FLAG_KEY;
         if (s->mb_info)
             av_packet_shrink_side_data(pkt, AV_PKT_DATA_H263_MB_INFO, s->mb_info_size);
@@ -3776,12 +3779,17 @@ static int encode_picture(MpegEncContext *s)
     }
 
     //FIXME var duplication
-    s->current_picture_ptr->f->key_frame =
-    s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I; //FIXME pic_ptr
+    if (s->pict_type == AV_PICTURE_TYPE_I) {
+        s->current_picture_ptr->f->flags |= AV_FRAME_FLAG_KEY; //FIXME pic_ptr
+        s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+    } else {
+        s->current_picture_ptr->f->flags &= ~AV_FRAME_FLAG_KEY; //FIXME pic_ptr
+        s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
+    }
     s->current_picture_ptr->f->pict_type =
     s->current_picture.f->pict_type = s->pict_type;
 
-    if (s->current_picture.f->key_frame)
+    if (s->current_picture.f->flags & AV_FRAME_FLAG_KEY)
         s->picture_in_gop_number=0;
 
     s->mb_x = s->mb_y = 0;
diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c
index e8406aa268..1844664477 100644
--- a/libavcodec/mscc.c
+++ b/libavcodec/mscc.c
@@ -200,7 +200,7 @@ inflate_error:
                s->uncomp_buf + s->bpp * j * avctx->width, s->bpp * avctx->width);
     }
 
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     frame->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame = 1;
diff --git a/libavcodec/msp2dec.c b/libavcodec/msp2dec.c
index 9c51c35c61..30a2825e47 100644
--- a/libavcodec/msp2dec.c
+++ b/libavcodec/msp2dec.c
@@ -47,7 +47,7 @@ static int msp2_decode_frame(AVCodecContext *avctx, AVFrame *p,
         return ret;
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     bytestream2_init(&idx, buf, 2 * avctx->height);
     buf += 2 * avctx->height;
diff --git a/libavcodec/mss1.c b/libavcodec/mss1.c
index 775852102a..dc06a9e236 100644
--- a/libavcodec/mss1.c
+++ b/libavcodec/mss1.c
@@ -165,12 +165,12 @@ static int mss1_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         c->corrupted = 0;
         ff_mss12_slicecontext_reset(&ctx->sc);
         pal_changed        = decode_pal(c, &acoder);
-        ctx->pic->key_frame = 1;
+        ctx->pic->flags |= AV_FRAME_FLAG_KEY;
         ctx->pic->pict_type = AV_PICTURE_TYPE_I;
     } else {
         if (c->corrupted)
             return AVERROR_INVALIDDATA;
-        ctx->pic->key_frame = 0;
+        ctx->pic->flags &= ~AV_FRAME_FLAG_KEY;
         ctx->pic->pict_type = AV_PICTURE_TYPE_P;
     }
     c->corrupted = ff_mss12_decode_rect(&ctx->sc, &acoder, 0, 0,
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 1d1ed11f54..98103f7fed 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -660,7 +660,10 @@ static int mss2_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                     frame->linesize[0] * (avctx->height - 1);
     c->rgb_stride = -frame->linesize[0];
 
-    frame->key_frame = keyframe;
+    if (keyframe)
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
     frame->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     if (is_555) {
diff --git a/libavcodec/mss3.c b/libavcodec/mss3.c
index 023f110ec8..2701e9b912 100644
--- a/libavcodec/mss3.c
+++ b/libavcodec/mss3.c
@@ -740,7 +740,10 @@ static int mss3_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
         return ret;
-    c->pic->key_frame = keyframe;
+    if (keyframe)
+        c->pic->flags |= AV_FRAME_FLAG_KEY;
+    else
+        c->pic->flags &= ~AV_FRAME_FLAG_KEY;
     c->pic->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
     if (!bytestream2_get_bytes_left(&gb)) {
         if ((ret = av_frame_ref(rframe, c->pic)) < 0)
diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c
index dceb42da25..75f31beda6 100644
--- a/libavcodec/mss4.c
+++ b/libavcodec/mss4.c
@@ -503,7 +503,10 @@ static int mss4_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
         return ret;
-    c->pic->key_frame = (frame_type == INTRA_FRAME);
+    if (frame_type == INTRA_FRAME)
+        c->pic->flags |= AV_FRAME_FLAG_KEY;
+    else
+        c->pic->flags &= ~AV_FRAME_FLAG_KEY;
     c->pic->pict_type = (frame_type == INTRA_FRAME) ? AV_PICTURE_TYPE_I
                                                    : AV_PICTURE_TYPE_P;
     if (frame_type == SKIP_FRAME) {
diff --git a/libavcodec/mv30.c b/libavcodec/mv30.c
index 24b04400fd..c2d0547053 100644
--- a/libavcodec/mv30.c
+++ b/libavcodec/mv30.c
@@ -623,9 +623,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     get_qtable(s->intraq_tab[0], s->intra_quant, luma_tab);
     get_qtable(s->intraq_tab[1], s->intra_quant, chroma_tab);
 
-    frame->key_frame = s->is_inter == 0;
-
-    if (frame->key_frame) {
+    if (s->is_inter == 0) {
+        frame->flags |= AV_FRAME_FLAG_KEY;
         ret = decode_intra(avctx, gb, frame);
         if (ret < 0)
             return ret;
@@ -638,6 +637,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
             return AVERROR_INVALIDDATA;
         }
 
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         ret = decode_inter(avctx, gb, frame, s->prev_frame);
         if (ret < 0)
             return ret;
diff --git a/libavcodec/mvcdec.c b/libavcodec/mvcdec.c
index 1e99f44a7d..6c971f709e 100644
--- a/libavcodec/mvcdec.c
+++ b/libavcodec/mvcdec.c
@@ -247,7 +247,7 @@ static int mvc_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return ret;
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     *got_frame = 1;
 
diff --git a/libavcodec/mvha.c b/libavcodec/mvha.c
index 55056c91cf..8fb4a69e9e 100644
--- a/libavcodec/mvha.c
+++ b/libavcodec/mvha.c
@@ -272,7 +272,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     }
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/mwsc.c b/libavcodec/mwsc.c
index f57648bb15..c7045ac793 100644
--- a/libavcodec/mwsc.c
+++ b/libavcodec/mwsc.c
@@ -119,10 +119,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     bytestream2_init(&gbp, s->prev_frame->data[0], avctx->height * s->prev_frame->linesize[0]);
     bytestream2_init_writer(&pb, frame->data[0], avctx->height * frame->linesize[0]);
 
-    frame->key_frame = rle_uncompress(&gb, &pb, &gbp, avctx->width, avctx->height, avctx->width * 3,
-                                      frame->linesize[0], s->prev_frame->linesize[0]);
+    if (rle_uncompress(&gb, &pb, &gbp, avctx->width, avctx->height, avctx->width * 3,
+                       frame->linesize[0], s->prev_frame->linesize[0]))
+        frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
 
-    frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+    frame->pict_type = (frame->flags & AV_FRAME_FLAG_KEY) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     av_frame_unref(s->prev_frame);
     if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c
index 760b12f0cc..73df2ff9ff 100644
--- a/libavcodec/mxpegdec.c
+++ b/libavcodec/mxpegdec.c
@@ -286,11 +286,11 @@ static int mxpeg_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                                              AV_GET_BUFFER_FLAG_REF)) < 0)
                         return ret;
                     jpg->picture_ptr->pict_type = AV_PICTURE_TYPE_P;
-                    jpg->picture_ptr->key_frame = 0;
+                    jpg->picture_ptr->flags &= ~AV_FRAME_FLAG_KEY;
                     jpg->got_picture = 1;
                 } else {
                     jpg->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
-                    jpg->picture_ptr->key_frame = 1;
+                    jpg->picture_ptr->flags |= AV_FRAME_FLAG_KEY;
                 }
 
                 if (s->got_mxm_bitmask) {
diff --git a/libavcodec/notchlc.c b/libavcodec/notchlc.c
index 90704e1aeb..d973c83ac7 100644
--- a/libavcodec/notchlc.c
+++ b/libavcodec/notchlc.c
@@ -514,7 +514,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
         return ret;
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     *got_frame = 1;
 
diff --git a/libavcodec/nuv.c b/libavcodec/nuv.c
index d5391eee54..82048e9326 100644
--- a/libavcodec/nuv.c
+++ b/libavcodec/nuv.c
@@ -263,7 +263,10 @@ retry:
     }
 
     c->pic->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
-    c->pic->key_frame = keyframe;
+    if (keyframe)
+        c->pic->flags |= AV_FRAME_FLAG_KEY;
+    else
+        c->pic->flags &= ~AV_FRAME_FLAG_KEY;
     // decompress/copy/whatever data
     switch (comptype) {
     case NUV_LZO:
diff --git a/libavcodec/pafvideo.c b/libavcodec/pafvideo.c
index 458fe9ff47..fa914ccbaa 100644
--- a/libavcodec/pafvideo.c
+++ b/libavcodec/pafvideo.c
@@ -296,10 +296,10 @@ static int paf_video_decode(AVCodecContext *avctx, AVFrame *rframe,
     if (code & 0x20) {  // frame is keyframe
         memset(c->pic->data[1], 0, AVPALETTE_SIZE);
         c->current_frame  = 0;
-        c->pic->key_frame = 1;
+        c->pic->flags |= AV_FRAME_FLAG_KEY;
         c->pic->pict_type = AV_PICTURE_TYPE_I;
     } else {
-        c->pic->key_frame = 0;
+        c->pic->flags &= ~AV_FRAME_FLAG_KEY;
         c->pic->pict_type = AV_PICTURE_TYPE_P;
     }
 
diff --git a/libavcodec/pgxdec.c b/libavcodec/pgxdec.c
index e5d1df784e..cc7cdb8c9a 100644
--- a/libavcodec/pgxdec.c
+++ b/libavcodec/pgxdec.c
@@ -140,7 +140,7 @@ static int pgx_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     avctx->bits_per_raw_sample = depth;
     if (bpp == 8)
         write_frame_8(p, &g, width, height, sign, depth);
diff --git a/libavcodec/photocd.c b/libavcodec/photocd.c
index 3030a80e0d..3a09b81908 100644
--- a/libavcodec/photocd.c
+++ b/libavcodec/photocd.c
@@ -332,7 +332,7 @@ static int photocd_decode_frame(AVCodecContext *avctx, AVFrame *p,
         return ret;
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     bytestream2_init(gb, avpkt->data, avpkt->size);
 
diff --git a/libavcodec/pixlet.c b/libavcodec/pixlet.c
index b349d397f4..6e925308b8 100644
--- a/libavcodec/pixlet.c
+++ b/libavcodec/pixlet.c
@@ -667,7 +667,7 @@ static int pixlet_decode_frame(AVCodecContext *avctx, AVFrame *p,
     bytestream2_skip(&ctx->gb, 8);
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->color_range = AVCOL_RANGE_JPEG;
 
     ret = ff_thread_get_buffer(avctx, p, 0);
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 8fbb71f60f..ae6f118fb4 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -840,7 +840,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
         }
 
         p->pict_type        = AV_PICTURE_TYPE_I;
-        p->key_frame        = 1;
+        p->flags           |= AV_FRAME_FLAG_KEY;
         p->interlaced_frame = !!s->interlace_type;
 
         if ((ret = populate_avctx_color_fields(avctx, p)) < 0)
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index 978e4c037e..72bc83b272 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -65,7 +65,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     avctx->bits_per_raw_sample = av_log2(s->maxval) + 1;
 
     switch (avctx->pix_fmt) {
diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c
index c821a07849..e333f70455 100644
--- a/libavcodec/proresdec2.c
+++ b/libavcodec/proresdec2.c
@@ -792,7 +792,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     ctx->frame = frame;
     ctx->frame->pict_type = AV_PICTURE_TYPE_I;
-    ctx->frame->key_frame = 1;
+    ctx->frame->flags |= AV_FRAME_FLAG_KEY;
     ctx->first_field = 1;
 
     buf += 8;
diff --git a/libavcodec/prosumer.c b/libavcodec/prosumer.c
index e199d1aaa9..a1ed6a9e53 100644
--- a/libavcodec/prosumer.c
+++ b/libavcodec/prosumer.c
@@ -195,7 +195,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     }
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/qdrw.c b/libavcodec/qdrw.c
index e41451e9a7..65e7269e5d 100644
--- a/libavcodec/qdrw.c
+++ b/libavcodec/qdrw.c
@@ -503,7 +503,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
 
     if (*got_frame) {
         p->pict_type = AV_PICTURE_TYPE_I;
-        p->key_frame = 1;
+        p->flags |= AV_FRAME_FLAG_KEY;
 
         return avpkt->size;
     } else {
diff --git a/libavcodec/qoidec.c b/libavcodec/qoidec.c
index 9414d2fbe9..37bc2084c0 100644
--- a/libavcodec/qoidec.c
+++ b/libavcodec/qoidec.c
@@ -106,7 +106,7 @@ static int qoi_decode_frame(AVCodecContext *avctx, AVFrame *p,
         memcpy(&dst[off_x * channels], px, channels);
     }
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame   = 1;
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index 5bca338acf..43a24fab08 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -304,7 +304,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = av_frame_ref(ref, p)) < 0)
         return ret;
 
-    p->key_frame = intra;
+    if (intra)
+        p->flags |= AV_FRAME_FLAG_KEY;
+    else
+        p->flags &= ~AV_FRAME_FLAG_KEY;
     p->pict_type = intra ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     *got_frame      = 1;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 6bc85116ad..1c18f715d6 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -834,8 +834,12 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
             !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
         frame->pict_type = ff_qsv_map_pictype(aframe.frame->dec_info.FrameType);
         //Key frame is IDR frame is only suitable for H264. For HEVC, IRAPs are key frames.
-        if (avctx->codec_id == AV_CODEC_ID_H264)
-            frame->key_frame = !!(aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR);
+        if (avctx->codec_id == AV_CODEC_ID_H264) {
+            if (aframe.frame->dec_info.FrameType & MFX_FRAMETYPE_IDR)
+                frame->flags |= AV_FRAME_FLAG_KEY;
+            else
+                frame->flags &= ~AV_FRAME_FLAG_KEY;
+        }
 
         /* update the surface properties */
         if (avctx->pix_fmt == AV_PIX_FMT_QSV)
diff --git a/libavcodec/r210dec.c b/libavcodec/r210dec.c
index ae80f46eb6..fe6a025988 100644
--- a/libavcodec/r210dec.c
+++ b/libavcodec/r210dec.c
@@ -57,7 +57,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
 
     pic->pict_type = AV_PICTURE_TYPE_I;
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     g_line = pic->data[0];
     b_line = pic->data[1];
     r_line = pic->data[2];
diff --git a/libavcodec/rasc.c b/libavcodec/rasc.c
index cfa3d6b079..4d057e80e7 100644
--- a/libavcodec/rasc.c
+++ b/libavcodec/rasc.c
@@ -740,7 +740,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (!s->skip_cursor)
         draw_cursor(avctx);
 
-    s->frame->key_frame = intra;
+    if (intra)
+        s->frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->frame->flags &= ~AV_FRAME_FLAG_KEY;
     s->frame->pict_type = intra ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     *got_frame = 1;
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index c20c317fed..9762536639 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -227,7 +227,7 @@ static int raw_decode(AVCodecContext *avctx, AVFrame *frame,
     need_copy = !avpkt->buf || context->is_1_2_4_8_bpp || context->is_yuv2 || context->is_lt_16bpp;
 
     frame->pict_type        = AV_PICTURE_TYPE_I;
-    frame->key_frame        = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     res = ff_decode_frame_props(avctx, frame);
     if (res < 0)
diff --git a/libavcodec/rscc.c b/libavcodec/rscc.c
index 61a25df382..2ae8899977 100644
--- a/libavcodec/rscc.c
+++ b/libavcodec/rscc.c
@@ -339,7 +339,7 @@ static int rscc_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     /* Keyframe when the number of pixels updated matches the whole surface */
     if (pixel_size == ctx->inflated_size) {
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
     } else {
         frame->pict_type = AV_PICTURE_TYPE_P;
     }
diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index bec3c770ec..b70daab7ac 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -1484,11 +1484,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
             return ret;
 
         ctx->rotate_code = header.rotate_code;
-        if ((ctx->frame->key_frame = !header.seq_num)) {
+        if (!header.seq_num) {
+            ctx->frame->flags |= AV_FRAME_FLAG_KEY;
             ctx->frame->pict_type = AV_PICTURE_TYPE_I;
             fill_frame(ctx->frm1, ctx->npixels, header.bg_color);
             fill_frame(ctx->frm2, ctx->npixels, header.bg_color);
         } else {
+            ctx->frame->flags &= ~AV_FRAME_FLAG_KEY;
             ctx->frame->pict_type = AV_PICTURE_TYPE_P;
         }
 
diff --git a/libavcodec/scpr.c b/libavcodec/scpr.c
index 7630adb3e0..b096965de5 100644
--- a/libavcodec/scpr.c
+++ b/libavcodec/scpr.c
@@ -516,18 +516,18 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         s->version = 1;
         s->get_freq = get_freq0;
         s->decode = decode0;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         ret = decompress_i(avctx, (uint32_t *)s->current_frame->data[0],
                            s->current_frame->linesize[0] / 4);
     } else if (type == 18) {
         s->version = 2;
         s->get_freq = get_freq;
         s->decode = decode;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         ret = decompress_i(avctx, (uint32_t *)s->current_frame->data[0],
                            s->current_frame->linesize[0] / 4);
     } else if (type == 34) {
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         s->version = 3;
         ret = decompress_i3(avctx, (uint32_t *)s->current_frame->data[0],
                             s->current_frame->linesize[0] / 4);
@@ -538,7 +538,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         if (bytestream2_get_bytes_left(gb) < 3)
             return AVERROR_INVALIDDATA;
 
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         bytestream2_skip(gb, 1);
         if (avctx->bits_per_coded_sample == 16) {
             uint16_t value = bytestream2_get_le16(gb);
@@ -557,7 +557,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
             dst += s->current_frame->linesize[0] / 4;
         }
     } else if (type == 0 || type == 1) {
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
 
         if (s->version == 1 || s->version == 2)
             ret = decompress_p(avctx, (uint32_t *)s->current_frame->data[0],
@@ -612,7 +612,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         }
     }
 
-    frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+    frame->pict_type = (frame->flags & AV_FRAME_FLAG_KEY) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     FFSWAP(AVFrame *, s->current_frame, s->last_frame);
 
diff --git a/libavcodec/screenpresso.c b/libavcodec/screenpresso.c
index 0d9e485043..b27154991c 100644
--- a/libavcodec/screenpresso.c
+++ b/libavcodec/screenpresso.c
@@ -173,7 +173,7 @@ static int screenpresso_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     /* Usual properties */
     if (keyframe) {
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
     } else {
         frame->pict_type = AV_PICTURE_TYPE_P;
     }
diff --git a/libavcodec/sga.c b/libavcodec/sga.c
index d3f4924298..16442b40be 100644
--- a/libavcodec/sga.c
+++ b/libavcodec/sga.c
@@ -499,7 +499,7 @@ static int sga_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);
     frame->palette_has_changed = 1;
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     *got_frame = 1;
 
diff --git a/libavcodec/sgidec.c b/libavcodec/sgidec.c
index 92083f23de..04a347c51e 100644
--- a/libavcodec/sgidec.c
+++ b/libavcodec/sgidec.c
@@ -249,7 +249,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
         break;
     }
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     /* Skip header. */
     bytestream2_seek(&g, SGI_HEADER_SIZE, SEEK_SET);
diff --git a/libavcodec/sgirledec.c b/libavcodec/sgirledec.c
index 9e3a220ad4..18bf8081fc 100644
--- a/libavcodec/sgirledec.c
+++ b/libavcodec/sgirledec.c
@@ -124,7 +124,7 @@ static int sgirle_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return ret;
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     *got_frame = 1;
 
diff --git a/libavcodec/sheervideo.c b/libavcodec/sheervideo.c
index eee6014742..d9c94ea9eb 100644
--- a/libavcodec/sheervideo.c
+++ b/libavcodec/sheervideo.c
@@ -1973,7 +1973,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     }
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0)
         return ret;
diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index ecc27e9b67..9a128c10ca 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -393,11 +393,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     bytestream2_init(&gb2, avpkt->data, avpkt->size);
     flags = bytestream2_get_byteu(&gb2);
     smk->pic->palette_has_changed = flags & 1;
-    smk->pic->key_frame = !!(flags & 2);
-    if (smk->pic->key_frame)
+    if (flags & 2) {
+        smk->pic->flags |= AV_FRAME_FLAG_KEY;
         smk->pic->pict_type = AV_PICTURE_TYPE_I;
-    else
+    } else {
+        smk->pic->flags &= ~AV_FRAME_FLAG_KEY;
         smk->pic->pict_type = AV_PICTURE_TYPE_P;
+    }
 
     for(i = 0; i < 256; i++)
         *pal++ = 0xFFU << 24 | bytestream2_get_be24u(&gb2);
diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index b6c8d5e256..5eb3ee1e9e 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -606,7 +606,7 @@ int ff_snow_frame_start(SnowContext *s){
     }else{
         int i;
         for(i=0; i<s->max_ref_frames && s->last_picture[i]->data[0]; i++)
-            if(i && s->last_picture[i-1]->key_frame)
+            if(i && (s->last_picture[i-1]->flags & AV_FRAME_FLAG_KEY))
                 break;
         s->ref_frames= i;
         if(s->ref_frames==0){
@@ -617,7 +617,10 @@ int ff_snow_frame_start(SnowContext *s){
     if ((ret = ff_snow_get_buffer(s, s->current_picture)) < 0)
         return ret;
 
-    s->current_picture->key_frame= s->keyframe;
+    if (s->keyframe)
+        s->current_picture->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_picture->flags &= ~AV_FRAME_FLAG_KEY;
 
     return 0;
 }
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 4cf7ff1145..99afcfeb54 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1761,7 +1761,7 @@ redo_frame:
                 ff_build_rac_states(c, (1LL<<32)/20, 256-8);
                 pic->pict_type= AV_PICTURE_TYPE_I;
                 s->keyframe=1;
-                s->current_picture->key_frame=1;
+                s->current_picture->flags |= AV_FRAME_FLAG_KEY;
                 goto redo_frame;
             }
 
@@ -1889,7 +1889,7 @@ redo_frame:
     }
 
     pkt->size = ff_rac_terminate(c, 0);
-    if (s->current_picture->key_frame)
+    if (s->current_picture->flags & AV_FRAME_FLAG_KEY)
         pkt->flags |= AV_PKT_FLAG_KEY;
     *got_packet = 1;
 
diff --git a/libavcodec/speedhqdec.c b/libavcodec/speedhqdec.c
index e1e6f9a5f5..ff106009a9 100644
--- a/libavcodec/speedhqdec.c
+++ b/libavcodec/speedhqdec.c
@@ -436,7 +436,7 @@ static int speedhq_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
         return ret;
     }
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     if (second_field_offset == 4 || second_field_offset == (buf_size-4)) {
         /*
diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
index df514030b9..2d03dbc457 100644
--- a/libavcodec/svq3.c
+++ b/libavcodec/svq3.c
@@ -1408,7 +1408,10 @@ static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     /* for skipping the frame */
     s->cur_pic->f->pict_type = s->pict_type;
-    s->cur_pic->f->key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
+    if (s->pict_type == AV_PICTURE_TYPE_I)
+        s->cur_pic->f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->cur_pic->f->flags &= ~AV_FRAME_FLAG_KEY;
 
     ret = get_buffer(avctx, s->cur_pic);
     if (ret < 0)
diff --git a/libavcodec/targa_y216dec.c b/libavcodec/targa_y216dec.c
index d5234c16ae..2874a51aae 100644
--- a/libavcodec/targa_y216dec.c
+++ b/libavcodec/targa_y216dec.c
@@ -47,7 +47,7 @@ static int y216_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     y = (uint16_t *)pic->data[0];
diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c
index b5ab2e171b..739738d9b1 100644
--- a/libavcodec/tdsc.c
+++ b/libavcodec/tdsc.c
@@ -612,7 +612,7 @@ static int tdsc_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     /* Frame is ready to be output */
     if (keyframe) {
         frame->pict_type = AV_PICTURE_TYPE_I;
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
     } else {
         frame->pict_type = AV_PICTURE_TYPE_P;
     }
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 1a1879de89..560cb3e5b3 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1036,7 +1036,7 @@ static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame,
 
     /* Frame is ready to be output */
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     return avpkt->size;
 }
@@ -2379,6 +2379,7 @@ again:
         }
     }
 
+    p->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/tmv.c b/libavcodec/tmv.c
index cdb83452e5..582b6ddd02 100644
--- a/libavcodec/tmv.c
+++ b/libavcodec/tmv.c
@@ -57,7 +57,7 @@ static int tmv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     }
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     dst              = frame->data[0];
 
     frame->palette_has_changed = 1;
diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index b168b9cda1..73c93359da 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -930,11 +930,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
         }
         offset += t;
     }
-    p->key_frame = tm2_decode_blocks(l, p);
-    if (p->key_frame)
+    if (tm2_decode_blocks(l, p)) {
+        p->flags |= AV_FRAME_FLAG_KEY;
         p->pict_type = AV_PICTURE_TYPE_I;
-    else
+    } else {
+        p->flags &= ~AV_FRAME_FLAG_KEY;
         p->pict_type = AV_PICTURE_TYPE_P;
+    }
 
     l->cur = !l->cur;
     *got_frame      = 1;
diff --git a/libavcodec/truemotion2rt.c b/libavcodec/truemotion2rt.c
index c6015b278a..4f8590fc82 100644
--- a/libavcodec/truemotion2rt.c
+++ b/libavcodec/truemotion2rt.c
@@ -202,7 +202,7 @@ static int truemotion2rt_decode_frame(AVCodecContext *avctx, AVFrame *p,
     }
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     *got_frame = 1;
 
     return avpkt->size;
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index 83120d1b22..876b5614e6 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -869,7 +869,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         break;
     }
 
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
     frame->pict_type = AV_PICTURE_TYPE_I;
     frame->interlaced_frame = !!c->interlaced;
 
diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
index 43b92f6ec9..09aa04f2da 100644
--- a/libavcodec/v210dec.c
+++ b/libavcodec/v210dec.c
@@ -187,7 +187,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
 
     pic->pict_type = AV_PICTURE_TYPE_I;
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
 
     if (stride) {
         td.stride = stride;
diff --git a/libavcodec/v210x.c b/libavcodec/v210x.c
index 96594e2a43..55630fa2fb 100644
--- a/libavcodec/v210x.c
+++ b/libavcodec/v210x.c
@@ -62,7 +62,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *pic,
     vdst = (uint16_t *)pic->data[2];
     yend = ydst + width;
     pic->pict_type = AV_PICTURE_TYPE_I;
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
 
     for (;;) {
         uint32_t v = av_be2ne32(*src++);
diff --git a/libavcodec/v308dec.c b/libavcodec/v308dec.c
index a81771fc5f..4bc4ea4e21 100644
--- a/libavcodec/v308dec.c
+++ b/libavcodec/v308dec.c
@@ -48,7 +48,7 @@ static int v308_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     y = pic->data[0];
diff --git a/libavcodec/v408dec.c b/libavcodec/v408dec.c
index edc9976d94..191c050fb2 100644
--- a/libavcodec/v408dec.c
+++ b/libavcodec/v408dec.c
@@ -51,7 +51,7 @@ static int v408_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     y = pic->data[0];
diff --git a/libavcodec/v410dec.c b/libavcodec/v410dec.c
index fb859e8cca..35e4a8ae03 100644
--- a/libavcodec/v410dec.c
+++ b/libavcodec/v410dec.c
@@ -102,7 +102,7 @@ static int v410_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_thread_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     td.buf = src;
diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 3f5471067a..2277135699 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -427,7 +427,8 @@ int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
         return ret;
 
     /* 2. get frame information */
-    frame->key_frame = !!(avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME);
+    if (avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME)
+        frame->flags |= AV_FRAME_FLAG_KEY;
     frame->color_primaries = v4l2_get_color_primaries(avbuf);
     frame->colorspace = v4l2_get_color_space(avbuf);
     frame->color_range = v4l2_get_color_range(avbuf);
diff --git a/libavcodec/vble.c b/libavcodec/vble.c
index 9307b0d165..7711bf1bb1 100644
--- a/libavcodec/vble.c
+++ b/libavcodec/vble.c
@@ -135,7 +135,7 @@ static int vble_decode_frame(AVCodecContext *avctx, AVFrame *pic,
         return ret;
 
     /* Set flags */
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     /* Version should always be 1 */
diff --git a/libavcodec/vbndec.c b/libavcodec/vbndec.c
index d92dcd46b9..02ed43f874 100644
--- a/libavcodec/vbndec.c
+++ b/libavcodec/vbndec.c
@@ -151,7 +151,7 @@ static int vbn_decode_frame(AVCodecContext *avctx,
         goto out;
 
     frame->pict_type = AV_PICTURE_TYPE_I;
-    frame->key_frame = 1;
+    frame->flags |= AV_FRAME_FLAG_KEY;
 
     if (format == VBN_FORMAT_RAW) {
         uint8_t *flipped = frame->data[0] + frame->linesize[0] * (frame->height - 1);
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 18fb616fff..0eee5ab9c5 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1060,7 +1060,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
 
     // for skipping the frame
     s->current_picture.f->pict_type = s->pict_type;
-    s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
+    if (s->pict_type == AV_PICTURE_TYPE_I)
+        s->current_picture.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_picture.f->flags &= ~AV_FRAME_FLAG_KEY;
 
     /* skip B-frames if we don't have reference frames */
     if (!s->last_picture_ptr && s->pict_type == AV_PICTURE_TYPE_B) {
diff --git a/libavcodec/vcr1.c b/libavcodec/vcr1.c
index 853d4459a8..771337e262 100644
--- a/libavcodec/vcr1.c
+++ b/libavcodec/vcr1.c
@@ -63,7 +63,7 @@ static int vcr1_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     for (i = 0; i < 16; i++) {
         a->delta[i] = *bytestream++;
diff --git a/libavcodec/vmnc.c b/libavcodec/vmnc.c
index 8daaf08c5d..17e3a2f3c1 100644
--- a/libavcodec/vmnc.c
+++ b/libavcodec/vmnc.c
@@ -339,7 +339,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     if ((ret = ff_reget_buffer(avctx, c->pic, 0)) < 0)
         return ret;
 
-    c->pic->key_frame = 0;
+    c->pic->flags &= ~AV_FRAME_FLAG_KEY;
     c->pic->pict_type = AV_PICTURE_TYPE_P;
 
     // restore screen after cursor
@@ -441,7 +441,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
             bytestream2_skip(gb, 4);
             break;
         case MAGIC_WMVi: // ServerInitialization struct
-            c->pic->key_frame = 1;
+            c->pic->flags |= AV_FRAME_FLAG_KEY;
             c->pic->pict_type = AV_PICTURE_TYPE_I;
             depth = bytestream2_get_byte(gb);
             if (depth != c->bpp) {
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 2234855946..9e097c8905 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -2677,7 +2677,10 @@ static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     s->current_frame.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I
                                                 : AV_PICTURE_TYPE_P;
-    s->current_frame.f->key_frame = s->keyframe;
+    if (s->keyframe)
+        s->current_frame.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->current_frame.f->flags &= ~AV_FRAME_FLAG_KEY;
     if ((ret = ff_thread_get_ext_buffer(avctx, &s->current_frame,
                                         AV_GET_BUFFER_FLAG_REF)) < 0)
         goto error;
diff --git a/libavcodec/vp5.c b/libavcodec/vp5.c
index 579333506a..78d4b38ce3 100644
--- a/libavcodec/vp5.c
+++ b/libavcodec/vp5.c
@@ -44,10 +44,13 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
     ret = ff_vpx_init_range_decoder(&s->c, buf, buf_size);
     if (ret < 0)
         return ret;
-    s->frames[VP56_FRAME_CURRENT]->key_frame = !vpx_rac_get(c);
+    if (!vpx_rac_get(c))
+        s->frames[VP56_FRAME_CURRENT]->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->frames[VP56_FRAME_CURRENT]->flags &= ~AV_FRAME_FLAG_KEY;
     vpx_rac_get(c);
     ff_vp56_init_dequant(s, vp56_rac_gets(c, 6));
-    if (s->frames[VP56_FRAME_CURRENT]->key_frame)
+    if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)
     {
         int render_x, render_y;
 
@@ -148,7 +151,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
             if (vpx_rac_get_prob_branchy(c, vp5_dccv_pct[pt][node])) {
                 def_prob[node] = vp56_rac_gets_nn(c, 7);
                 model->coeff_dccv[pt][node] = def_prob[node];
-            } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
+            } else if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) {
                 model->coeff_dccv[pt][node] = def_prob[node];
             }
 
@@ -159,7 +162,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
                     if (vpx_rac_get_prob_branchy(c, vp5_ract_pct[ct][pt][cg][node])) {
                         def_prob[node] = vp56_rac_gets_nn(c, 7);
                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
-                    } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
+                    } else if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) {
                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
                     }
 
diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c
index bd994428a4..a5c5b23622 100644
--- a/libavcodec/vp56.c
+++ b/libavcodec/vp56.c
@@ -350,7 +350,7 @@ static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
 
     if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
         (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
-         && !s->frames[VP56_FRAME_CURRENT]->key_frame))
+         && !(s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)))
         deblock_filtering = 0;
 
     dx = s->mv[b].x / s->vp56_coord_div[b];
@@ -493,7 +493,7 @@ static int vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
     VP56mb mb_type;
     int ret;
 
-    if (s->frames[VP56_FRAME_CURRENT]->key_frame)
+    if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)
         mb_type = VP56_MB_INTRA;
     else
         mb_type = vp56_decode_mv(s, row, col);
@@ -511,7 +511,7 @@ static int vp56_conceal_mb(VP56Context *s, int row, int col, int is_alpha)
 {
     VP56mb mb_type;
 
-    if (s->frames[VP56_FRAME_CURRENT]->key_frame)
+    if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)
         mb_type = VP56_MB_INTRA;
     else
         mb_type = vp56_conceal_mv(s, row, col);
@@ -596,6 +596,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
             if (s->alpha_context)
                 av_frame_unref(s->alpha_context->frames[i]);
         }
+        s->frames[VP56_FRAME_CURRENT]->flags |= AV_FRAME_FLAG_KEY; //FIXME
     }
 
     ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF);
@@ -670,7 +671,7 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
     int res;
     int damaged = 0;
 
-    if (p->key_frame) {
+    if (p->flags & AV_FRAME_FLAG_KEY) {
         p->pict_type = AV_PICTURE_TYPE_I;
         s->default_models_init(s);
         for (block=0; block<s->mb_height*s->mb_width; block++)
@@ -762,7 +763,7 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
         s->have_undamaged_frame = 1;
 
 next:
-    if (p->key_frame || s->golden_frame) {
+    if ((p->flags & AV_FRAME_FLAG_KEY) || s->golden_frame) {
         av_frame_unref(s->frames[VP56_FRAME_GOLDEN]);
         if ((res = av_frame_ref(s->frames[VP56_FRAME_GOLDEN], p)) < 0)
             return res;
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index 9bbfa0eb5d..7a519cf10d 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -57,10 +57,13 @@ static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
     int ret;
     int separated_coeff = buf[0] & 1;
 
-    s->frames[VP56_FRAME_CURRENT]->key_frame = !(buf[0] & 0x80);
+    if (!(buf[0] & 0x80))
+        s->frames[VP56_FRAME_CURRENT]->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->frames[VP56_FRAME_CURRENT]->flags &= ~AV_FRAME_FLAG_KEY;
     ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F);
 
-    if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
+    if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) {
         sub_version = buf[1] >> 3;
         if (sub_version > 8)
             return AVERROR_INVALIDDATA;
@@ -299,7 +302,7 @@ static int vp6_parse_coeff_models(VP56Context *s)
             if (vpx_rac_get_prob_branchy(c, vp6_dccv_pct[pt][node])) {
                 def_prob[node] = vp56_rac_gets_nn(c, 7);
                 model->coeff_dccv[pt][node] = def_prob[node];
-            } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
+            } else if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) {
                 model->coeff_dccv[pt][node] = def_prob[node];
             }
 
@@ -322,7 +325,7 @@ static int vp6_parse_coeff_models(VP56Context *s)
                     if (vpx_rac_get_prob_branchy(c, vp6_ract_pct[ct][pt][cg][node])) {
                         def_prob[node] = vp56_rac_gets_nn(c, 7);
                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
-                    } else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
+                    } else if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) {
                         model->coeff_ract[pt][ct][cg][node] = def_prob[node];
                     }
 
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index db2419deaf..2ab06c8293 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2732,7 +2732,10 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame,
         goto err;
     }
 
-    curframe->tf.f->key_frame = s->keyframe;
+    if (s->keyframe)
+        curframe->tf.f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        curframe->tf.f->flags &= ~AV_FRAME_FLAG_KEY;
     curframe->tf.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I
                                             : AV_PICTURE_TYPE_P;
     if ((ret = vp8_alloc_frame(s, curframe, referenced)) < 0)
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 7ff387faf4..d8a31507fa 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -1613,7 +1613,10 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if ((ret = vp9_frame_alloc(avctx, &s->s.frames[CUR_FRAME])) < 0)
         return ret;
     f = s->s.frames[CUR_FRAME].tf.f;
-    f->key_frame = s->s.h.keyframe;
+    if (s->s.h.keyframe)
+        f->flags |= AV_FRAME_FLAG_KEY;
+    else
+        f->flags &= ~AV_FRAME_FLAG_KEY;
     f->pict_type = (s->s.h.keyframe || s->s.h.intraonly) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     if (s->s.frames[REF_FRAME_SEGMAP].tf.f->buf[0] &&
diff --git a/libavcodec/wbmpdec.c b/libavcodec/wbmpdec.c
index 8b105bc135..3b5753abcd 100644
--- a/libavcodec/wbmpdec.c
+++ b/libavcodec/wbmpdec.c
@@ -74,7 +74,7 @@ static int wbmp_decode_frame(AVCodecContext *avctx, AVFrame *p,
     else
         readbits(p->data[0], width, height, p->linesize[0], gb.buffer, gb.buffer_end - gb.buffer);
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame   = 1;
diff --git a/libavcodec/wcmv.c b/libavcodec/wcmv.c
index 097ac8b8e9..b2413ee9c0 100644
--- a/libavcodec/wcmv.c
+++ b/libavcodec/wcmv.c
@@ -195,7 +195,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         }
     }
 
-    s->prev_frame->key_frame = intra;
+    if (intra)
+        s->prev_frame->flags |= AV_FRAME_FLAG_KEY;
+    else
+        s->prev_frame->flags &= ~AV_FRAME_FLAG_KEY;
     s->prev_frame->pict_type = intra ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
     if ((ret = av_frame_ref(frame, s->prev_frame)) < 0)
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index b4357f95d5..d35cb66f8d 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1186,7 +1186,7 @@ static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p,
 
     *got_frame   = 1;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     ret          = data_size;
 
 free_and_return:
diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index 88532ee426..5c57db0054 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -69,7 +69,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
 
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     if ((ret = init_get_bits8(&gb, buf + 8, buf_size - 8)) < 0)
         return ret;
diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c
index a0cc1cb8c6..ecfc957a3f 100644
--- a/libavcodec/xbmdec.c
+++ b/libavcodec/xbmdec.c
@@ -130,7 +130,7 @@ static int xbm_decode_frame(AVCodecContext *avctx, AVFrame *p,
         }
     }
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame       = 1;
diff --git a/libavcodec/xl.c b/libavcodec/xl.c
index 283cd39aa7..f008d56e89 100644
--- a/libavcodec/xl.c
+++ b/libavcodec/xl.c
@@ -60,7 +60,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
 
     Y = p->data[0];
     U = p->data[1];
diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c
index 2550afb9d6..5bc02378c8 100644
--- a/libavcodec/xpmdec.c
+++ b/libavcodec/xpmdec.c
@@ -422,7 +422,7 @@ static int xpm_decode_frame(AVCodecContext *avctx, AVFrame *p,
         ptr += mod_strcspn(ptr, ",") + 1;
     }
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     *got_frame = 1;
diff --git a/libavcodec/xwddec.c b/libavcodec/xwddec.c
index 6c5bc44a02..f691587be9 100644
--- a/libavcodec/xwddec.c
+++ b/libavcodec/xwddec.c
@@ -216,7 +216,7 @@ static int xwd_decode_frame(AVCodecContext *avctx, AVFrame *p,
     if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
         return ret;
 
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     p->pict_type = AV_PICTURE_TYPE_I;
 
     if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
diff --git a/libavcodec/y41pdec.c b/libavcodec/y41pdec.c
index b461f349ad..14e36dc998 100644
--- a/libavcodec/y41pdec.c
+++ b/libavcodec/y41pdec.c
@@ -51,7 +51,7 @@ static int y41p_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     for (i = avctx->height - 1; i >= 0 ; i--) {
diff --git a/libavcodec/ylc.c b/libavcodec/ylc.c
index 29c10f05da..c0c4d27c09 100644
--- a/libavcodec/ylc.c
+++ b/libavcodec/ylc.c
@@ -427,7 +427,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
     }
 
     p->pict_type = AV_PICTURE_TYPE_I;
-    p->key_frame = 1;
+    p->flags |= AV_FRAME_FLAG_KEY;
     *got_frame   = 1;
 
     return avpkt->size;
diff --git a/libavcodec/yuv4dec.c b/libavcodec/yuv4dec.c
index 15424b1940..ad83a2125c 100644
--- a/libavcodec/yuv4dec.c
+++ b/libavcodec/yuv4dec.c
@@ -46,7 +46,7 @@ static int yuv4_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
         return ret;
 
-    pic->key_frame = 1;
+    pic->flags |= AV_FRAME_FLAG_KEY;
     pic->pict_type = AV_PICTURE_TYPE_I;
 
     y = pic->data[0];
diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c
index 42fb24ff6c..6c3bcebce0 100644
--- a/libavcodec/zerocodec.c
+++ b/libavcodec/zerocodec.c
@@ -40,7 +40,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     int i, j, zret, ret;
 
     if (avpkt->flags & AV_PKT_FLAG_KEY) {
-        pic->key_frame = 1;
+        pic->flags |= AV_FRAME_FLAG_KEY;
         pic->pict_type = AV_PICTURE_TYPE_I;
     } else {
         if (!prev) {
@@ -50,7 +50,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, AVFrame *pic,
 
         prev += (avctx->height - 1) * prev_pic->linesize[0];
 
-        pic->key_frame = 0;
+        pic->flags &= ~AV_FRAME_FLAG_KEY;
         pic->pict_type = AV_PICTURE_TYPE_P;
     }
 
diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c
index 0b44851811..d309a8612b 100644
--- a/libavcodec/zmbv.c
+++ b/libavcodec/zmbv.c
@@ -559,11 +559,11 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         return ret;
 
     if (c->flags & ZMBV_KEYFRAME) {
-        frame->key_frame = 1;
+        frame->flags |= AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_I;
         zmbv_decode_intra(c);
     } else {
-        frame->key_frame = 0;
+        frame->flags &= ~AV_FRAME_FLAG_KEY;
         frame->pict_type = AV_PICTURE_TYPE_P;
         if (c->decomp_len < 2LL * ((c->width + c->bw - 1) / c->bw) * ((c->height + c->bh - 1) / c->bh))
             return AVERROR_INVALIDDATA;
