diff --git a/libavcodec/options.c b/libavcodec/options.c
index fdc8a71337a953e89db3edff06f3d5b3c8dc3db2..a08ed98cce977c5dd361e3299a6d0849d1951768 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -539,6 +539,7 @@ static const AVClass av_codec_context_class = {
 #if FF_API_ALLOC_CONTEXT
 void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){
     avcodec_get_context_defaults3(s, NULL);
+    s->codec_type = codec_type;
 }
 #endif