[FFmpeg-devel] [PATCH] avcodec/utils: Allocate dummy codec_frame for video encoders which do not allocate one

Michael Niedermayer michaelni at gmx.at
Mon Feb 23 17:19:16 CET 2015


This should allow simplifying many encoders

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavcodec/utils.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c5e6300..c6d588a 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1695,6 +1695,16 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
     }
 
+    if (av_codec_is_encoder(avctx->codec) &&
+        avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
+        !avctx->coded_frame) {
+        avctx->coded_frame = av_frame_alloc();
+        if (avctx->coded_frame) {
+            av_assert0(avctx->coded_frame->key_frame);
+            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
+        }
+    }
+
 end:
     ff_unlock_avcodec();
     if (options) {
@@ -2852,6 +2862,8 @@ av_cold int avcodec_close(AVCodecContext *avctx)
         av_freep(&avctx->internal->hwaccel_priv_data);
 
         av_freep(&avctx->internal);
+        if (av_codec_is_encoder(avctx->codec))
+            av_frame_free(&avctx->coded_frame);
     }
 
     if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list