Allocating coded_frame is what most encoders do anyway, so it makes
sense to always allocate it in a single place. This bring uniformity to
encoder behaviour and prevents applications from erroneusly accessing
this field when not allocated.

Additionally this helps isolating encoders that export information with
it, and it heavily simplifies its deprecation.

Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com>
---
 libavcodec/a64multienc.c        |  7 -------
 libavcodec/alacenc.c            |  7 -------
 libavcodec/aliaspixenc.c        | 16 ----------------
 libavcodec/asvenc.c             | 18 ++----------------
 libavcodec/bmpenc.c             | 11 -----------
 libavcodec/cljrenc.c            | 17 -----------------
 libavcodec/dnxhdenc.c           |  6 ------
 libavcodec/dpxenc.c             | 11 -----------
 libavcodec/dvenc.c              | 11 -----------
 libavcodec/ffv1enc.c            |  5 -----
 libavcodec/flashsvenc.c         |  8 --------
 libavcodec/gif.c                |  6 ------
 libavcodec/huffyuvenc.c         |  6 ------
 libavcodec/jpeglsenc.c          | 11 -----------
 libavcodec/lclenc.c             |  6 ------
 libavcodec/libopencore-amr.c    |  1 -
 libavcodec/libopenjpegenc.c     |  8 --------
 libavcodec/libschroedingerenc.c |  6 ------
 libavcodec/libtheoraenc.c       |  6 ------
 libavcodec/libvpxenc.c          |  7 -------
 libavcodec/libx264.c            |  6 ------
 libavcodec/libx265.c            |  8 --------
 libavcodec/libxavs.c            |  6 ------
 libavcodec/libxvid.c            |  4 ----
 libavcodec/ljpegenc.c           |  5 -----
 libavcodec/mpegvideo_enc.c      |  3 +--
 libavcodec/pamenc.c             | 11 -----------
 libavcodec/pcm.c                | 11 -----------
 libavcodec/pcxenc.c             | 11 -----------
 libavcodec/pngenc.c             | 11 -----------
 libavcodec/pnmenc.c             | 14 --------------
 libavcodec/proresenc.c          |  5 -----
 libavcodec/qsvenc.c             |  6 ------
 libavcodec/qtrleenc.c           |  8 --------
 libavcodec/rawenc.c             | 11 -----------
 libavcodec/sgienc.c             | 11 -----------
 libavcodec/sunrastenc.c         | 11 -----------
 libavcodec/svq1enc.c            |  4 +---
 libavcodec/targaenc.c           | 11 -----------
 libavcodec/tiffenc.c            | 11 -----------
 libavcodec/utils.c              | 12 ++++++++++--
 libavcodec/utvideoenc.c         |  9 ---------
 libavcodec/v210enc.c            | 12 ------------
 libavcodec/v410enc.c            | 15 ---------------
 libavcodec/xbmenc.c             | 11 -----------
 libavcodec/xwdenc.c             | 18 ------------------
 libavcodec/zmbvenc.c            |  8 --------
 47 files changed, 14 insertions(+), 413 deletions(-)

diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index 969a071..f065ebb 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -166,7 +166,6 @@ static void render_charset(AVCodecContext *avctx, uint8_t 
*charset,
 static av_cold int a64multi_close_encoder(AVCodecContext *avctx)
 {
     A64Context *c = avctx->priv_data;
-    av_frame_free(&avctx->coded_frame);
     av_free(c->mc_meta_charset);
     av_free(c->mc_best_cb);
     av_free(c->mc_charset);
@@ -218,12 +217,6 @@ static av_cold int a64multi_encode_init(AVCodecContext 
*avctx)
     AV_WB32(avctx->extradata, c->mc_lifetime);
     AV_WB32(avctx->extradata + 16, INTERLACED);
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        a64multi_close_encoder(avctx);
-        return AVERROR(ENOMEM);
-    }
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
     if (!avctx->codec_tag)
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index 401f26f..7777cf7 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -483,7 +483,6 @@ static av_cold int alac_encode_close(AVCodecContext *avctx)
     ff_lpc_end(&s->lpc_ctx);
     av_freep(&avctx->extradata);
     avctx->extradata_size = 0;
-    av_freep(&avctx->coded_frame);
     return 0;
 }
 
@@ -579,12 +578,6 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
         goto error;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        ret = AVERROR(ENOMEM);
-        goto error;
-    }
-
     s->avctx = avctx;
 
     if ((ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size,
diff --git a/libavcodec/aliaspixenc.c b/libavcodec/aliaspixenc.c
index 47e0612..5e3bcb4 100644
--- a/libavcodec/aliaspixenc.c
+++ b/libavcodec/aliaspixenc.c
@@ -27,14 +27,6 @@
 
 #define ALIAS_HEADER_SIZE 10
 
-static av_cold int encode_init(AVCodecContext *avctx)
-{
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-    return 0;
-}
-
 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                         const AVFrame *frame, int *got_packet)
 {
@@ -114,20 +106,12 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
     return 0;
 }
 
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_alias_pix_encoder = {
     .name      = "alias_pix",
     .long_name = NULL_IF_CONFIG_SMALL("Alias/Wavefront PIX image"),
     .type      = AVMEDIA_TYPE_VIDEO,
     .id        = AV_CODEC_ID_ALIAS_PIX,
-    .init      = encode_init,
     .encode2   = encode_frame,
-    .close     = encode_close,
     .pix_fmts  = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_BGR24, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
     },
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index f8c52af..c10d9fe 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -282,9 +282,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     int i;
     const int scale = avctx->codec_id == AV_CODEC_ID_ASV1 ? 1 : 2;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
@@ -311,13 +308,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     return 0;
 }
 
-static av_cold int asv_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-
-    return 0;
-}
-
 #if CONFIG_ASV1_ENCODER
 AVCodec ff_asv1_encoder = {
     .name           = "asv1",
@@ -327,11 +317,9 @@ AVCodec ff_asv1_encoder = {
     .priv_data_size = sizeof(ASV1Context),
     .init           = encode_init,
     .encode2        = encode_frame,
-    .close          = asv_encode_close,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                      AV_PIX_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE |
-                      FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
 
@@ -344,10 +332,8 @@ AVCodec ff_asv2_encoder = {
     .priv_data_size = sizeof(ASV1Context),
     .init           = encode_init,
     .encode2        = encode_frame,
-    .close          = asv_encode_close,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
                                                      AV_PIX_FMT_NONE },
-    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE |
-                      FF_CODEC_CAP_INIT_CLEANUP,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
 #endif
diff --git a/libavcodec/bmpenc.c b/libavcodec/bmpenc.c
index a14fc61..7260baa 100644
--- a/libavcodec/bmpenc.c
+++ b/libavcodec/bmpenc.c
@@ -56,10 +56,6 @@ static av_cold int bmp_encode_init(AVCodecContext *avctx){
         return -1;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     return 0;
 }
 
@@ -157,12 +153,6 @@ static int bmp_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
     return 0;
 }
 
-static av_cold int bmp_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_bmp_encoder = {
     .name           = "bmp",
     .long_name      = NULL_IF_CONFIG_SMALL("BMP (Windows and OS/2 bitmap)"),
@@ -170,7 +160,6 @@ AVCodec ff_bmp_encoder = {
     .id             = AV_CODEC_ID_BMP,
     .init           = bmp_encode_init,
     .encode2        = bmp_encode_frame,
-    .close          = bmp_encode_close,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_BGR24,
         AV_PIX_FMT_RGB555, AV_PIX_FMT_RGB444, AV_PIX_FMT_RGB565,
diff --git a/libavcodec/cljrenc.c b/libavcodec/cljrenc.c
index 2c31555..e2db7a6 100644
--- a/libavcodec/cljrenc.c
+++ b/libavcodec/cljrenc.c
@@ -30,21 +30,6 @@
 #include "internal.h"
 #include "put_bits.h"
 
-static av_cold int encode_init(AVCodecContext *avctx)
-{
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
-    return 0;
-}
-
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                         const AVFrame *p, int *got_packet)
 {
@@ -89,9 +74,7 @@ AVCodec ff_cljr_encoder = {
     .long_name      = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_CLJR,
-    .init           = encode_init,
     .encode2        = encode_frame,
-    .close          = encode_close,
     .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV411P,
                                                    AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index f28c338..0c98c56 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -364,10 +364,6 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
     FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale,
                       ctx->m.mb_num * sizeof(uint8_t), fail);
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->key_frame = 1;
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
@@ -1118,8 +1114,6 @@ static av_cold int dnxhd_encode_end(AVCodecContext *avctx)
     for (i = 1; i < avctx->thread_count; i++)
         av_freep(&ctx->thread[i]);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c
index 2b1ead3..aaa5d93 100644
--- a/libavcodec/dpxenc.c
+++ b/libavcodec/dpxenc.c
@@ -35,10 +35,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
 {
     DPXContext *s = avctx->priv_data;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
@@ -177,12 +173,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
     return 0;
 }
 
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_dpx_encoder = {
     .name = "dpx",
     .long_name = NULL_IF_CONFIG_SMALL("DPX image"),
@@ -191,7 +181,6 @@ AVCodec ff_dpx_encoder = {
     .priv_data_size = sizeof(DPXContext),
     .init   = encode_init,
     .encode2 = encode_frame,
-    .close   = encode_close,
     .pix_fmts = (const enum AVPixelFormat[]){
         AV_PIX_FMT_RGB24,
         AV_PIX_FMT_RGBA,
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index 6d98d49..3bbcaf0 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -61,10 +61,6 @@ static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
         return ret;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     dv_vlc_map_tableinit();
 
     ff_fdctdsp_init(&fdsp, avctx);
@@ -737,12 +733,6 @@ static int dvvideo_encode_frame(AVCodecContext *c, 
AVPacket *pkt,
     return 0;
 }
 
-static int dvvideo_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_dvvideo_encoder = {
     .name           = "dvvideo",
     .long_name      = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
@@ -751,7 +741,6 @@ AVCodec ff_dvvideo_encoder = {
     .priv_data_size = sizeof(DVVideoContext),
     .init           = dvvideo_encode_init,
     .encode2        = dvvideo_encode_frame,
-    .close          = dvvideo_encode_close,
     .capabilities   = CODEC_CAP_SLICE_THREADS,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV422P,
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 7099c16..33d1391 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -721,10 +721,6 @@ static av_cold int ffv1_encode_init(AVCodecContext *avctx)
     if ((ret = ffv1_allocate_initial_states(s)) < 0)
         return ret;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
     if (!s->transparency)
@@ -1061,7 +1057,6 @@ static int ffv1_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 
 static av_cold int ffv1_encode_close(AVCodecContext *avctx)
 {
-    av_frame_free(&avctx->coded_frame);
     ffv1_close(avctx);
     return 0;
 }
diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
index 971ce1b..a2f89dc 100644
--- a/libavcodec/flashsvenc.c
+++ b/libavcodec/flashsvenc.c
@@ -98,8 +98,6 @@ static av_cold int flashsv_encode_end(AVCodecContext *avctx)
     av_free(s->previous_frame);
     av_free(s->tmpblock);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
@@ -131,12 +129,6 @@ static av_cold int flashsv_encode_init(AVCodecContext 
*avctx)
         return AVERROR(ENOMEM);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        flashsv_encode_end(avctx);
-        return AVERROR(ENOMEM);
-    }
-
     return 0;
 }
 
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index ae7fdfd..cb1c71b 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -130,10 +130,6 @@ static av_cold int gif_encode_init(AVCodecContext *avctx)
 {
     GIFContext *s = avctx->priv_data;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
@@ -174,8 +170,6 @@ static int gif_encode_close(AVCodecContext *avctx)
 {
     GIFContext *s = avctx->priv_data;
 
-    av_frame_free(&avctx->coded_frame);
-
     av_freep(&s->lzw);
     av_freep(&s->buf);
     return 0;
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index 6b3ff76..3b40404 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -154,10 +154,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     avctx->stats_out = av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) 
= 16132
     s->version = 2;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
@@ -680,8 +676,6 @@ static av_cold int encode_end(AVCodecContext *avctx)
     av_freep(&avctx->extradata);
     av_freep(&avctx->stats_out);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
index 839b540..3021394 100644
--- a/libavcodec/jpeglsenc.c
+++ b/libavcodec/jpeglsenc.c
@@ -413,18 +413,8 @@ memfail:
     return AVERROR(ENOMEM);
 }
 
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 static av_cold int encode_init_ls(AVCodecContext *ctx)
 {
-    ctx->coded_frame = av_frame_alloc();
-    if (!ctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     ctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     ctx->coded_frame->key_frame = 1;
 
@@ -445,7 +435,6 @@ AVCodec ff_jpegls_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_JPEGLS,
     .init           = encode_init_ls,
-    .close          = encode_close,
     .encode2        = encode_picture_ls,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24,
diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c
index 20841bc..35543ac 100644
--- a/libavcodec/lclenc.c
+++ b/libavcodec/lclenc.c
@@ -136,10 +136,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     avctx->extradata= av_mallocz(8);
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
@@ -183,8 +179,6 @@ static av_cold int encode_end(AVCodecContext *avctx)
     av_freep(&avctx->extradata);
     deflateEnd(&c->zstream);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 72e0bbb..ac6976f 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -206,7 +206,6 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
     s->enc_state = Encoder_Interface_init(s->enc_dtx);
     if (!s->enc_state) {
         av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
-        av_freep(&avctx->coded_frame);
         return -1;
     }
 
diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
index 00c0ed6..58aa3cf 100644
--- a/libavcodec/libopenjpegenc.c
+++ b/libavcodec/libopenjpegenc.c
@@ -169,12 +169,6 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext 
*avctx)
         return AVERROR(ENOMEM);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n");
-        goto fail;
-    }
-
     ctx->image = libopenjpeg_create_image(avctx, &ctx->enc_params);
     if (!ctx->image) {
         av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
@@ -191,7 +185,6 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext 
*avctx)
 
 fail:
     av_freep(&ctx->compress);
-    av_freep(&avctx->coded_frame);
     return err;
 }
 
@@ -371,7 +364,6 @@ static av_cold int libopenjpeg_encode_close(AVCodecContext 
*avctx)
 
     opj_destroy_compress(ctx->compress);
     opj_image_destroy(ctx->image);
-    av_freep(&avctx->coded_frame);
     return 0;
 }
 
diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c
index d99ba69..3e648d0 100644
--- a/libavcodec/libschroedingerenc.c
+++ b/libavcodec/libschroedingerenc.c
@@ -158,10 +158,6 @@ static av_cold int 
libschroedinger_encode_init(AVCodecContext *avctx)
                                                     avctx->width,
                                                     avctx->height);
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     if (!avctx->gop_size) {
         schro_encoder_setting_set_double(p_schro_params->encoder,
                                          "gop_structure",
@@ -436,8 +432,6 @@ static int libschroedinger_encode_close(AVCodecContext 
*avctx)
     /* Free the video format structure. */
     av_freep(&p_schro_params->format);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 3781043..7087322 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -258,11 +258,6 @@ static av_cold int encode_init(AVCodecContext* avc_context)
 
     th_comment_clear(&t_comment);
 
-    /* Set up the output AVFrame */
-    avc_context->coded_frame = av_frame_alloc();
-    if (!avc_context->coded_frame)
-        return AVERROR(ENOMEM);
-
     return 0;
 }
 
@@ -356,7 +351,6 @@ static av_cold int encode_close(AVCodecContext* avc_context)
 
     th_encode_free(h->t_state);
     av_freep(&h->stats);
-    av_freep(&avc_context->coded_frame);
     av_freep(&avc_context->stats_out);
     av_freep(&avc_context->extradata);
     avc_context->extradata_size = 0;
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 21f47aa..49d0511 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -210,7 +210,6 @@ static av_cold int vp8_free(AVCodecContext *avctx)
 
     vpx_codec_destroy(&ctx->encoder);
     av_freep(&ctx->twopass_stats.buf);
-    av_freep(&avctx->coded_frame);
     av_freep(&avctx->stats_out);
     free_frame_list(ctx->coded_frame_list);
     return 0;
@@ -364,12 +363,6 @@ static av_cold int vpx_init(AVCodecContext *avctx,
     vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 
1,
                  (unsigned char*)1);
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n");
-        vp8_free(avctx);
-        return AVERROR(ENOMEM);
-    }
     return 0;
 }
 
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 841b824..7fef7f2 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -279,8 +279,6 @@ static av_cold int X264_close(AVCodecContext *avctx)
         x4->enc = NULL;
     }
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
@@ -531,10 +529,6 @@ static av_cold int X264_init(AVCodecContext *avctx)
     if (!x4->enc)
         return AVERROR_UNKNOWN;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
         x264_nal_t *nal;
         uint8_t *p;
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index f5687f6..145480f 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -66,8 +66,6 @@ static av_cold int libx265_encode_close(AVCodecContext *avctx)
 {
     libx265Context *ctx = avctx->priv_data;
 
-    av_frame_free(&avctx->coded_frame);
-
     ctx->api->param_free(ctx->params);
 
     if (ctx->encoder)
@@ -92,12 +90,6 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
         return AVERROR(ENOSYS);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
-        return AVERROR(ENOMEM);
-    }
-
     ctx->params = ctx->api->param_alloc();
     if (!ctx->params) {
         av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param 
structure.\n");
diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c
index 4fd90a9..4dd778e 100644
--- a/libavcodec/libxavs.c
+++ b/libavcodec/libxavs.c
@@ -208,8 +208,6 @@ static av_cold int XAVS_close(AVCodecContext *avctx)
     if (x4->enc)
         xavs_encoder_close(x4->enc);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
@@ -357,10 +355,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
     if (!(x4->pts_buffer = av_mallocz((avctx->max_b_frames+1) * 
sizeof(*x4->pts_buffer))))
         return AVERROR(ENOMEM);
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     /* TAG: Do we have GLOBAL HEADER in AVS */
     /* We Have PPS and SPS in AVS */
     if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index 46da773..b4cf0e0 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -645,9 +645,6 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx)
     }
 
     x->encoder_handle  = xvid_enc_create.handle;
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
 
     return 0;
 }
@@ -784,7 +781,6 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx)
         x->encoder_handle = NULL;
     }
 
-    av_frame_free(&avctx->coded_frame);
     av_freep(&avctx->extradata);
     if (x->twopassbuffer) {
         av_free(x->twopassbuffer);
diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c
index fc2ade6..c652653 100644
--- a/libavcodec/ljpegenc.c
+++ b/libavcodec/ljpegenc.c
@@ -255,7 +255,6 @@ static av_cold int ljpeg_encode_close(AVCodecContext *avctx)
 {
     LJpegEncContext *s = avctx->priv_data;
 
-    av_frame_free(&avctx->coded_frame);
     av_freep(&s->scratch);
 
     return 0;
@@ -277,10 +276,6 @@ static av_cold int ljpeg_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6397681..2e0dc72 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1460,8 +1460,7 @@ static void frame_end(MpegEncContext *s)
         }
     }
 
-    s->avctx->coded_frame = s->current_picture_ptr->f;
-
+    av_frame_copy_props(s->avctx->coded_frame, s->current_picture.f);
 }
 
 static void update_noise_reduction(MpegEncContext *s)
diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c
index 8535d3d..483089a 100644
--- a/libavcodec/pamenc.c
+++ b/libavcodec/pamenc.c
@@ -109,29 +109,18 @@ static int pam_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 
 static av_cold int pam_encode_init(AVCodecContext *avctx)
 {
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
     return 0;
 }
 
-static av_cold int pam_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_pam_encoder = {
     .name           = "pam",
     .long_name      = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PAM,
     .init           = pam_encode_init,
-    .close          = pam_encode_close,
     .encode2        = pam_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB32, AV_PIX_FMT_GRAY8, 
AV_PIX_FMT_MONOWHITE,
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index e06712e..0964d5b 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -48,16 +48,6 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
     avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
     avctx->block_align           = avctx->channels * 
avctx->bits_per_coded_sample / 8;
     avctx->bit_rate              = avctx->block_align * avctx->sample_rate * 8;
-    avctx->coded_frame           = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
-    return 0;
-}
-
-static av_cold int pcm_encode_close(AVCodecContext *avctx)
-{
-    av_freep(&avctx->coded_frame);
 
     return 0;
 }
@@ -457,7 +447,6 @@ AVCodec ff_ ## name_ ## _encoder = {                        
                \
     .id           = AV_CODEC_ID_ ## id_,                                    \
     .init         = pcm_encode_init,                                        \
     .encode2      = pcm_encode_frame,                                       \
-    .close        = pcm_encode_close,                                       \
     .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE,                          \
     .sample_fmts  = (const enum AVSampleFormat[]){ sample_fmt_,             \
                                                    AV_SAMPLE_FMT_NONE },    \
diff --git a/libavcodec/pcxenc.c b/libavcodec/pcxenc.c
index 8553fe1..24bca97 100644
--- a/libavcodec/pcxenc.c
+++ b/libavcodec/pcxenc.c
@@ -34,22 +34,12 @@ static const uint32_t monoblack_pal[16] = { 0x000000, 
0xFFFFFF };
 
 static av_cold int pcx_encode_init(AVCodecContext *avctx)
 {
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
     return 0;
 }
 
-static av_cold int pcx_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 /**
  * PCX run-length encoder
  * @param dst output buffer
@@ -206,7 +196,6 @@ AVCodec ff_pcx_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PCX,
     .init           = pcx_encode_init,
-    .close          = pcx_encode_close,
     .encode2        = pcx_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_RGB24,
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 3d11f37..bbeee01 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -455,10 +455,6 @@ static av_cold int png_enc_init(AVCodecContext *avctx)
 {
     PNGEncContext *s = avctx->priv_data;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
@@ -473,12 +469,6 @@ static av_cold int png_enc_init(AVCodecContext *avctx)
     return 0;
 }
 
-static av_cold int png_enc_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_png_encoder = {
     .name           = "png",
     .long_name      = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) 
image"),
@@ -486,7 +476,6 @@ AVCodec ff_png_encoder = {
     .id             = AV_CODEC_ID_PNG,
     .priv_data_size = sizeof(PNGEncContext),
     .init           = png_enc_init,
-    .close          = png_enc_close,
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB32, AV_PIX_FMT_PAL8, AV_PIX_FMT_GRAY8,
diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c
index 7513552..58fd4fe 100644
--- a/libavcodec/pnmenc.c
+++ b/libavcodec/pnmenc.c
@@ -120,22 +120,12 @@ static int pnm_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 
 static av_cold int pnm_encode_init(AVCodecContext *avctx)
 {
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
     return 0;
 }
 
-static av_cold int pnm_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 #if CONFIG_PGM_ENCODER
 AVCodec ff_pgm_encoder = {
     .name           = "pgm",
@@ -143,7 +133,6 @@ AVCodec ff_pgm_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PGM,
     .init           = pnm_encode_init,
-    .close          = pnm_encode_close,
     .encode2        = pnm_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_NONE
@@ -158,7 +147,6 @@ AVCodec ff_pgmyuv_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PGMYUV,
     .init           = pnm_encode_init,
-    .close          = pnm_encode_close,
     .encode2        = pnm_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_NONE
@@ -173,7 +161,6 @@ AVCodec ff_ppm_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PPM,
     .init           = pnm_encode_init,
-    .close          = pnm_encode_close,
     .encode2        = pnm_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48BE, AV_PIX_FMT_NONE
@@ -188,7 +175,6 @@ AVCodec ff_pbm_encoder = {
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_PBM,
     .init           = pnm_encode_init,
-    .close          = pnm_encode_close,
     .encode2        = pnm_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_MONOWHITE,
                                                   AV_PIX_FMT_NONE },
diff --git a/libavcodec/proresenc.c b/libavcodec/proresenc.c
index b71a7db..3e99d10 100644
--- a/libavcodec/proresenc.c
+++ b/libavcodec/proresenc.c
@@ -1097,8 +1097,6 @@ static av_cold int encode_close(AVCodecContext *avctx)
     ProresContext *ctx = avctx->priv_data;
     int i;
 
-    av_freep(&avctx->coded_frame);
-
     if (ctx->tdata) {
         for (i = 0; i < avctx->thread_count; i++)
             av_free(ctx->tdata[i].nodes);
@@ -1132,9 +1130,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     int interlaced = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
 
     avctx->bits_per_raw_sample = 10;
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
 
     ctx->fdct      = prores_fdct;
     ctx->scantable = interlaced ? ff_prores_interlaced_scan
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 2830b0d..8b0ecd1 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -226,10 +226,6 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext 
*q)
         return ret;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     q->avctx = avctx;
 
     return 0;
@@ -438,7 +434,5 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext 
*q)
         cur = q->work_frames;
     }
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
diff --git a/libavcodec/qtrleenc.c b/libavcodec/qtrleenc.c
index 91dbb8b..8417864 100644
--- a/libavcodec/qtrleenc.c
+++ b/libavcodec/qtrleenc.c
@@ -66,8 +66,6 @@ static av_cold int qtrle_encode_end(AVCodecContext *avctx)
 {
     QtrleEncContext *s = avctx->priv_data;
 
-    av_frame_free(&avctx->coded_frame);
-
     avpicture_free(&s->previous_frame);
     av_free(s->rlecode_table);
     av_free(s->length_table);
@@ -117,12 +115,6 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx)
                       + s->avctx->height*2                           /* skip 
code+rle end */
                       + s->avctx->width/MAX_RLE_BULK + 1             /* rle 
codes */;
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        qtrle_encode_end(avctx);
-        return AVERROR(ENOMEM);
-    }
-
     return 0;
 }
 
diff --git a/libavcodec/rawenc.c b/libavcodec/rawenc.c
index d6e8009..a360c34 100644
--- a/libavcodec/rawenc.c
+++ b/libavcodec/rawenc.c
@@ -35,10 +35,6 @@ static av_cold int raw_encode_init(AVCodecContext *avctx)
 {
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
 
-    avctx->coded_frame            = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
     avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
@@ -72,18 +68,11 @@ static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
     return 0;
 }
 
-static av_cold int raw_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_rawvideo_encoder = {
     .name           = "rawvideo",
     .long_name      = NULL_IF_CONFIG_SMALL("raw video"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_RAWVIDEO,
     .init           = raw_encode_init,
-    .close          = raw_encode_close,
     .encode2        = raw_encode,
 };
diff --git a/libavcodec/sgienc.c b/libavcodec/sgienc.c
index bfc0995..73e1a67 100644
--- a/libavcodec/sgienc.c
+++ b/libavcodec/sgienc.c
@@ -36,10 +36,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     return 0;
 }
 
@@ -205,12 +201,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
     return 0;
 }
 
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_sgi_encoder = {
     .name      = "sgi",
     .long_name = NULL_IF_CONFIG_SMALL("SGI image"),
@@ -218,7 +208,6 @@ AVCodec ff_sgi_encoder = {
     .id        = AV_CODEC_ID_SGI,
     .init      = encode_init,
     .encode2   = encode_frame,
-    .close     = encode_close,
     .pix_fmts  = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA,
         AV_PIX_FMT_RGB48LE, AV_PIX_FMT_RGB48BE,
diff --git a/libavcodec/sunrastenc.c b/libavcodec/sunrastenc.c
index 8e90a6c..0627c47 100644
--- a/libavcodec/sunrastenc.c
+++ b/libavcodec/sunrastenc.c
@@ -153,10 +153,6 @@ static av_cold int sunrast_encode_init(AVCodecContext 
*avctx)
         return AVERROR(EINVAL);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->key_frame = 1;
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     s->maptype                    = RMT_NONE;
@@ -210,12 +206,6 @@ static int sunrast_encode_frame(AVCodecContext *avctx,  
AVPacket *avpkt,
     return 0;
 }
 
-static av_cold int sunrast_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 static const AVCodecDefault sunrast_defaults[] = {
      { "coder", "rle" },
      { NULL },
@@ -228,7 +218,6 @@ AVCodec ff_sunrast_encoder = {
     .id             = AV_CODEC_ID_SUNRAST,
     .priv_data_size = sizeof(SUNRASTContext),
     .init           = sunrast_encode_init,
-    .close          = sunrast_encode_close,
     .encode2        = sunrast_encode_frame,
     .defaults       = sunrast_defaults,
     .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_BGR24,
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 78d6770..2244eaf 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -498,7 +498,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
 
     av_frame_free(&s->current_picture);
     av_frame_free(&s->last_picture);
-    av_frame_free(&avctx->coded_frame);
 
     return 0;
 }
@@ -512,10 +511,9 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
     ff_me_cmp_init(&s->mecc, avctx);
     ff_mpegvideoencdsp_init(&s->m.mpvencdsp, avctx);
 
-    avctx->coded_frame = av_frame_alloc();
     s->current_picture = av_frame_alloc();
     s->last_picture    = av_frame_alloc();
-    if (!avctx->coded_frame || !s->current_picture || !s->last_picture) {
+    if (!s->current_picture || !s->last_picture) {
         svq1_encode_end(avctx);
         return AVERROR(ENOMEM);
     }
diff --git a/libavcodec/targaenc.c b/libavcodec/targaenc.c
index 7679029..048183f 100644
--- a/libavcodec/targaenc.c
+++ b/libavcodec/targaenc.c
@@ -150,29 +150,18 @@ static int targa_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 
 static av_cold int targa_encode_init(AVCodecContext *avctx)
 {
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->key_frame = 1;
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
     return 0;
 }
 
-static av_cold int targa_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 AVCodec ff_targa_encoder = {
     .name           = "targa",
     .long_name      = NULL_IF_CONFIG_SMALL("Truevision Targa image"),
     .type           = AVMEDIA_TYPE_VIDEO,
     .id             = AV_CODEC_ID_TARGA,
     .init           = targa_encode_init,
-    .close          = targa_encode_close,
     .encode2        = targa_encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]){
         AV_PIX_FMT_BGR24, AV_PIX_FMT_BGRA, AV_PIX_FMT_RGB555LE, 
AV_PIX_FMT_GRAY8,
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index a020f5f..fbdb824 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -490,22 +490,12 @@ fail:
 
 static av_cold int encode_init(AVCodecContext *avctx)
 {
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
     avctx->coded_frame->key_frame = 1;
 
     return 0;
 }
 
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-    return 0;
-}
-
 #define OFFSET(x) offsetof(TiffEncoderContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -533,7 +523,6 @@ AVCodec ff_tiff_encoder = {
     .id             = AV_CODEC_ID_TIFF,
     .priv_data_size = sizeof(TiffEncoderContext),
     .init           = encode_init,
-    .close          = encode_close,
     .encode2        = encode_frame,
     .pix_fmts       = (const enum AVPixelFormat[]) {
         AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48LE, AV_PIX_FMT_PAL8,
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 48b7ac1..52d0bcc 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1186,6 +1186,11 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 
     if (av_codec_is_encoder(avctx->codec)) {
         int i;
+        avctx->coded_frame = av_frame_alloc();
+        if (!avctx->coded_frame) {
+            ret = AVERROR(ENOMEM);
+            goto free_and_end;
+        }
         if (avctx->codec->sample_fmts) {
             for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; 
i++) {
                 if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
@@ -1313,6 +1318,8 @@ free_and_end:
         av_opt_free(avctx->priv_data);
     av_opt_free(avctx);
 
+    av_frame_free(&avctx->coded_frame);
+
     av_dict_free(&tmp);
     av_freep(&avctx->priv_data);
     if (avctx->internal) {
@@ -1832,7 +1839,6 @@ av_cold int avcodec_close(AVCodecContext *avctx)
             ff_thread_free(avctx);
         if (avctx->codec && avctx->codec->close)
             avctx->codec->close(avctx);
-        avctx->coded_frame = NULL;
         av_frame_free(&avctx->internal->to_free);
         for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
             av_buffer_pool_uninit(&pool->pools[i]);
@@ -1849,8 +1855,10 @@ av_cold int avcodec_close(AVCodecContext *avctx)
         av_opt_free(avctx->priv_data);
     av_opt_free(avctx);
     av_freep(&avctx->priv_data);
-    if (av_codec_is_encoder(avctx->codec))
+    if (av_codec_is_encoder(avctx->codec)) {
         av_freep(&avctx->extradata);
+        av_frame_free(&avctx->coded_frame);
+    }
     avctx->codec = NULL;
     avctx->active_thread_type = 0;
 
diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
index 8dc208b..c22f488 100644
--- a/libavcodec/utvideoenc.c
+++ b/libavcodec/utvideoenc.c
@@ -48,7 +48,6 @@ static av_cold int utvideo_encode_close(AVCodecContext *avctx)
     UtvideoContext *c = avctx->priv_data;
     int i;
 
-    av_freep(&avctx->coded_frame);
     av_freep(&c->slice_bits);
     for (i = 0; i < 4; i++)
         av_freep(&c->slice_buffer[i]);
@@ -154,14 +153,6 @@ static av_cold int utvideo_encode_init(AVCodecContext 
*avctx)
         return AVERROR(EINVAL);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-
-    if (!avctx->coded_frame) {
-        av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
-        utvideo_encode_close(avctx);
-        return AVERROR(ENOMEM);
-    }
-
     /* extradata size is 4 * 32bit */
     avctx->extradata_size = 16;
 
diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index cb88788..375236c 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -91,10 +91,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
     s->pack_line_8  = v210_planar_pack_8_c;
@@ -213,13 +209,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
     return 0;
 }
 
-static av_cold int encode_close(AVCodecContext *avctx)
-{
-    av_freep(&avctx->coded_frame);
-
-    return 0;
-}
-
 AVCodec ff_v210_encoder = {
     .name           = "v210",
     .long_name      = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
@@ -228,6 +217,5 @@ AVCodec ff_v210_encoder = {
     .priv_data_size = sizeof(V210EncContext),
     .init           = encode_init,
     .encode2        = encode_frame,
-    .close          = encode_close,
     .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV422P10, 
AV_PIX_FMT_YUV422P, AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/v410enc.c b/libavcodec/v410enc.c
index 77b32d7..ffbdc7d 100644
--- a/libavcodec/v410enc.c
+++ b/libavcodec/v410enc.c
@@ -32,13 +32,6 @@ static av_cold int v410_encode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-
-    if (!avctx->coded_frame) {
-        av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
-        return AVERROR(ENOMEM);
-    }
-
     return 0;
 }
 
@@ -81,13 +74,6 @@ static int v410_encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
     return 0;
 }
 
-static av_cold int v410_encode_close(AVCodecContext *avctx)
-{
-    av_freep(&avctx->coded_frame);
-
-    return 0;
-}
-
 AVCodec ff_v410_encoder = {
     .name         = "v410",
     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
@@ -95,6 +81,5 @@ AVCodec ff_v410_encoder = {
     .id           = AV_CODEC_ID_V410,
     .init         = v410_encode_init,
     .encode2      = v410_encode_frame,
-    .close        = v410_encode_close,
     .pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV444P10, 
AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/xbmenc.c b/libavcodec/xbmenc.c
index 517e569..41456cb 100644
--- a/libavcodec/xbmenc.c
+++ b/libavcodec/xbmenc.c
@@ -26,9 +26,6 @@
 
 static av_cold int xbm_encode_init(AVCodecContext *avctx)
 {
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
     avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
 
     return 0;
@@ -67,13 +64,6 @@ static int xbm_encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
     return 0;
 }
 
-static av_cold int xbm_encode_close(AVCodecContext *avctx)
-{
-    av_frame_free(&avctx->coded_frame);
-
-    return 0;
-}
-
 AVCodec ff_xbm_encoder = {
     .name         = "xbm",
     .long_name    = NULL_IF_CONFIG_SMALL("XBM (X BitMap) image"),
@@ -81,7 +71,6 @@ AVCodec ff_xbm_encoder = {
     .id           = AV_CODEC_ID_XBM,
     .init         = xbm_encode_init,
     .encode2      = xbm_encode_frame,
-    .close        = xbm_encode_close,
     .pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_MONOWHITE,
                                                  AV_PIX_FMT_NONE },
 };
diff --git a/libavcodec/xwdenc.c b/libavcodec/xwdenc.c
index 54599a0..97a3eb8 100644
--- a/libavcodec/xwdenc.c
+++ b/libavcodec/xwdenc.c
@@ -30,15 +30,6 @@
 #define WINDOW_NAME         "lavcxwdenc"
 #define WINDOW_NAME_SIZE    11
 
-static av_cold int xwd_encode_init(AVCodecContext *avctx)
-{
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame)
-        return AVERROR(ENOMEM);
-
-    return 0;
-}
-
 static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                             const AVFrame *p, int *got_packet)
 {
@@ -213,21 +204,12 @@ static int xwd_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
     return 0;
 }
 
-static av_cold int xwd_encode_close(AVCodecContext *avctx)
-{
-    av_freep(&avctx->coded_frame);
-
-    return 0;
-}
-
 AVCodec ff_xwd_encoder = {
     .name         = "xwd",
     .long_name    = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"),
     .type         = AVMEDIA_TYPE_VIDEO,
     .id           = AV_CODEC_ID_XWD,
-    .init         = xwd_encode_init,
     .encode2      = xwd_encode_frame,
-    .close        = xwd_encode_close,
     .pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_BGRA,
                                                  AV_PIX_FMT_RGBA,
                                                  AV_PIX_FMT_ARGB,
diff --git a/libavcodec/zmbvenc.c b/libavcodec/zmbvenc.c
index d7b518d..ea63b94 100644
--- a/libavcodec/zmbvenc.c
+++ b/libavcodec/zmbvenc.c
@@ -261,8 +261,6 @@ static av_cold int encode_end(AVCodecContext *avctx)
     deflateEnd(&c->zstream);
     av_freep(&c->prev);
 
-    av_frame_free(&avctx->coded_frame);
-
     return 0;
 }
 
@@ -326,12 +324,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    avctx->coded_frame = av_frame_alloc();
-    if (!avctx->coded_frame) {
-        encode_end(avctx);
-        return AVERROR(ENOMEM);
-    }
-
     return 0;
 }
 
-- 
1.9.5 (Apple Git-50.3)


_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to