diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 2da63c87ea..464b4078fc 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -451,6 +451,16 @@ typedef struct AVCodecContext {
      int log_level_offset;

      enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
+    /**
+     * Generic codec name of the encoded data.
+     *
+     * Null-terminated string, can be NULL.
+     * Contents may vary depending on the source of the data stream.
+     * This is typically the string that's interpreted to determine 
'codec_id'.
+     * Must be allocated with av_malloc() or av_strdup() and will be 
freed by
+     * avcodec_free_context().
+     */
+    char *codec_name;
      const struct AVCodec  *codec;
      enum AVCodecID     codec_id; /* see AV_CODEC_ID_xxx */

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index 790ea01d10..27d9880b53 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -31,6 +31,7 @@

  static void codec_parameters_reset(AVCodecParameters *par)
  {
+    av_freep(&par->codec_name);
      av_freep(&par->extradata);
      av_channel_layout_uninit(&par->ch_layout);
      av_packet_side_data_free(&par->coded_side_data, 
&par->nb_coded_side_data);
@@ -110,6 +111,13 @@ int avcodec_parameters_copy(AVCodecParameters *dst, 
const AVCodecParameters *src
      codec_parameters_reset(dst);
      memcpy(dst, src, sizeof(*dst));

+    dst->codec_name = NULL;
+    if (src->codec_name) {
+        dst->codec_name = av_strdup(src->codec_name);
+        if (!dst->codec_name)
+            return AVERROR(ENOMEM);
+    }
+
      dst->ch_layout      = (AVChannelLayout){0};
      dst->extradata      = NULL;
      dst->extradata_size = 0;
@@ -142,6 +150,11 @@ int 
avcodec_parameters_from_context(AVCodecParameters *par,
      codec_parameters_reset(par);

      par->codec_type = codec->codec_type;
+    if (codec->codec_name) {
+        par->codec_name = av_strdup(codec->codec_name);
+        if (!par->codec_name)
+            return AVERROR(ENOMEM);
+    }
      par->codec_id   = codec->codec_id;
      par->codec_tag  = codec->codec_tag;

@@ -206,6 +219,12 @@ int avcodec_parameters_to_context(AVCodecContext 
*codec,
      int ret;

      codec->codec_type = par->codec_type;
+    av_freep(&codec->codec_name);
+    if (par->codec_name) {
+        codec->codec_name = av_strdup(par->codec_name);
+        if (!codec->codec_name)
+            return AVERROR(ENOMEM);
+    }
      codec->codec_id   = par->codec_id;
      codec->codec_tag  = par->codec_tag;

diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index f4b9bb5c06..196ef1fc66 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -49,6 +49,16 @@ typedef struct AVCodecParameters {
       * General type of the encoded data.
       */
      enum AVMediaType codec_type;
+    /**
+     * Generic codec name of the encoded data.
+     *
+     * Null-terminated string, can be NULL.
+     * Contents may vary depending on the source of the data stream.
+     * This is typically the string that's interpreted to determine 
'codec_id'.
+     * Must be allocated with av_malloc() or av_strdup() and will be 
freed by
+     * avcodec_parameters_free().
+     */
+    char *codec_name;
      /**
       * Specific type of the encoded data (the codec used).
       */
diff --git a/libavcodec/options.c b/libavcodec/options.c
index f60c41bdc3..c107f4efbd 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -170,6 +170,7 @@ void avcodec_free_context(AVCodecContext **pavctx)

      ff_codec_close(avctx);

+    av_freep(&avctx->codec_name);
      av_freep(&avctx->extradata);
      av_freep(&avctx->subtitle_header);
      av_freep(&avctx->intra_matrix);
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index db78735c7a..56363caeda 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -317,6 +317,11 @@ static int sdp_parse_rtpmap(AVFormatContext *s,
              par->codec_id = ff_rtp_codec_id(buf, par->codec_type);
      }

+    /* Copy the codec name, regardless of whether we can handle it.
+     * Applications might handle unknown codecs on their own. */
+    av_freep(&par->codec_name);
+    par->codec_name = av_strdup(buf);
+
      desc = avcodec_descriptor_get(par->codec_id);
      if (desc && desc->name)
          c_name = desc->name;
