diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index 907e2d7b88..fe8150d559 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -128,7 +128,7 @@ int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
     rects[sub->num_rects]       = av_mallocz(sizeof(*rects[0]));
     if (!rects[sub->num_rects])
         return AVERROR(ENOMEM);
-    rects[sub->num_rects]->type = SUBTITLE_ASS;
+    rects[sub->num_rects]->type = AV_SUBTITLE_FMT_ASS;
     ass_str = ff_ass_get_dialog(readorder, layer, style, speaker, dialog);
     if (!ass_str)
         return AVERROR(ENOMEM);
diff --git a/libavcodec/ass.h b/libavcodec/ass.h
index 2c260e4e78..e9d49628cc 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -48,7 +48,7 @@ typedef struct FFASSDecoderContext {
 } FFASSDecoderContext;
 
 /**
- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
+ * Generate a suitable AVCodecContext.subtitle_header for AV_SUBTITLE_FMT_ASS.
  * Can specify all fields explicitly
  *
  * @param avctx pointer to the AVCodecContext
@@ -76,7 +76,7 @@ int ff_ass_subtitle_header_full(AVCodecContext *avctx,
                                 int bold, int italic, int underline,
                                 int border_style, int alignment);
 /**
- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
+ * Generate a suitable AVCodecContext.subtitle_header for AV_SUBTITLE_FMT_ASS.
  *
  * @param avctx pointer to the AVCodecContext
  * @param font name of the default font face to use
@@ -97,7 +97,7 @@ int ff_ass_subtitle_header(AVCodecContext *avctx,
                            int border_style, int alignment);
 
 /**
- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS
+ * Generate a suitable AVCodecContext.subtitle_header for AV_SUBTITLE_FMT_ASS
  * with default style.
  *
  * @param avctx pointer to the AVCodecContext
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 319279490c..fd80436eb2 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -54,7 +54,7 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
     if (!sub->rects[0])
         return AVERROR(ENOMEM);
     sub->num_rects = 1;
-    sub->rects[0]->type = SUBTITLE_ASS;
+    sub->rects[0]->type = AV_SUBTITLE_FMT_ASS;
     sub->rects[0]->ass  = av_strdup(avpkt->data);
     if (!sub->rects[0]->ass)
         return AVERROR(ENOMEM);
diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index a6d107ded2..0e78414adb 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -48,8 +48,8 @@ static int ass_encode_frame(AVCodecContext *avctx,
     for (i=0; i<sub->num_rects; i++) {
         const char *ass = sub->rects[i]->ass;
 
-        if (sub->rects[i]->type != SUBTITLE_ASS) {
-            av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+        if (sub->rects[i]->type != AV_SUBTITLE_FMT_ASS) {
+            av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type supported.\n");
             return AVERROR(EINVAL);
         }
 
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 2dd7dd84e0..963f52c4bd 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -426,25 +426,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
         av_bsf_flush(avci->bsf);
 }
 
-void avsubtitle_free(AVSubtitle *sub)
-{
-    int i;
-
-    for (i = 0; i < sub->num_rects; i++) {
-        av_freep(&sub->rects[i]->data[0]);
-        av_freep(&sub->rects[i]->data[1]);
-        av_freep(&sub->rects[i]->data[2]);
-        av_freep(&sub->rects[i]->data[3]);
-        av_freep(&sub->rects[i]->text);
-        av_freep(&sub->rects[i]->ass);
-        av_freep(&sub->rects[i]);
-    }
-
-    av_freep(&sub->rects);
-
-    memset(sub, 0, sizeof(*sub));
-}
-
 av_cold int avcodec_close(AVCodecContext *avctx)
 {
     int i;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ffd58c333f..b459c23ac7 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -35,6 +35,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "codec.h"
@@ -1670,7 +1671,7 @@ typedef struct AVCodecContext {
 
     /**
      * Header containing style information for text subtitles.
-     * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+     * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
      * [Script Info] and [V4+ Styles] section, plus the [Events] line and
      * the Format line following. It shouldn't include any Dialogue line.
      * - encoding: Set/allocated/freed by user (before avcodec_open2())
@@ -2233,63 +2234,8 @@ typedef struct AVHWAccel {
  * @}
  */
 
-enum AVSubtitleType {
-    SUBTITLE_NONE,
-
-    SUBTITLE_BITMAP,                ///< A bitmap, pict will be set
-
-    /**
-     * Plain text, the text field must be set by the decoder and is
-     * authoritative. ass and pict fields may contain approximations.
-     */
-    SUBTITLE_TEXT,
-
-    /**
-     * Formatted text, the ass field must be set by the decoder and is
-     * authoritative. pict and text fields may contain approximations.
-     */
-    SUBTITLE_ASS,
-};
-
 #define AV_SUBTITLE_FLAG_FORCED 0x00000001
 
-typedef struct AVSubtitleRect {
-    int x;         ///< top left corner  of pict, undefined when pict is not set
-    int y;         ///< top left corner  of pict, undefined when pict is not set
-    int w;         ///< width            of pict, undefined when pict is not set
-    int h;         ///< height           of pict, undefined when pict is not set
-    int nb_colors; ///< number of colors in pict, undefined when pict is not set
-
-    /**
-     * data+linesize for the bitmap of this subtitle.
-     * Can be set for text/ass as well once they are rendered.
-     */
-    uint8_t *data[4];
-    int linesize[4];
-
-    enum AVSubtitleType type;
-
-    char *text;                     ///< 0 terminated plain UTF-8 text
-
-    /**
-     * 0 terminated ASS/SSA compatible event line.
-     * The presentation of this is unaffected by the other values in this
-     * struct.
-     */
-    char *ass;
-
-    int flags;
-} AVSubtitleRect;
-
-typedef struct AVSubtitle {
-    uint16_t format; /* 0 = graphics */
-    uint32_t start_display_time; /* relative to packet pts, in ms */
-    uint32_t end_display_time; /* relative to packet pts, in ms */
-    unsigned num_rects;
-    AVSubtitleRect **rects;
-    int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
-} AVSubtitle;
-
 /**
  * Return the LIBAVCODEC_VERSION_INT constant.
  */
@@ -2425,13 +2371,6 @@ int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **op
  */
 int avcodec_close(AVCodecContext *avctx);
 
-/**
- * Free all allocated data in the given subtitle struct.
- *
- * @param sub AVSubtitle to free.
- */
-void avsubtitle_free(AVSubtitle *sub);
-
 /**
  * @}
  */
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index e45c14e878..1e13d784bb 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -795,7 +795,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou
             rect->w = region->width;
             rect->h = region->height;
             rect->nb_colors = (1 << region->depth);
-            rect->type      = SUBTITLE_BITMAP;
+            rect->type      = AV_SUBTITLE_FMT_BITMAP;
             rect->linesize[0] = region->width;
 
             clut = get_clut(ctx, region->clut);
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 52259f0730..b39b3d1838 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -406,7 +406,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
                 sub_header->rects[0]->y = y1;
                 sub_header->rects[0]->w = w;
                 sub_header->rects[0]->h = h;
-                sub_header->rects[0]->type = SUBTITLE_BITMAP;
+                sub_header->rects[0]->type = AV_SUBTITLE_FMT_BITMAP;
                 sub_header->rects[0]->linesize[0] = w;
                 sub_header->rects[0]->flags = is_menu ? AV_SUBTITLE_FLAG_FORCED : 0;
             }
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index ff4fbed39d..943a7466d9 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -268,7 +268,7 @@ static int encode_dvd_subtitles(AVCodecContext *avctx,
     if (rects == 0 || !h->rects)
         return AVERROR(EINVAL);
     for (i = 0; i < rects; i++)
-        if (h->rects[i]->type != SUBTITLE_BITMAP) {
+        if (h->rects[i]->type != AV_SUBTITLE_FMT_BITMAP) {
             av_log(avctx, AV_LOG_ERROR, "Bitmap subtitle required\n");
             return AVERROR(EINVAL);
         }
diff --git a/libavcodec/libzvbi-teletextdec.c b/libavcodec/libzvbi-teletextdec.c
index 1073d6a0bd..995648c9ec 100644
--- a/libavcodec/libzvbi-teletextdec.c
+++ b/libavcodec/libzvbi-teletextdec.c
@@ -215,7 +215,7 @@ static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page
     }
 
     if (buf.len) {
-        sub_rect->type = SUBTITLE_ASS;
+        sub_rect->type = AV_SUBTITLE_FMT_ASS;
         sub_rect->ass = create_ass_text(ctx, buf.str);
 
         if (!sub_rect->ass) {
@@ -224,7 +224,7 @@ static int gen_sub_text(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page
         }
         av_log(ctx, AV_LOG_DEBUG, "subtext:%s:txetbus\n", sub_rect->ass);
     } else {
-        sub_rect->type = SUBTITLE_NONE;
+        sub_rect->type = AV_SUBTITLE_FMT_NONE;
     }
     av_bprint_finalize(&buf, NULL);
     return 0;
@@ -393,7 +393,7 @@ static int gen_sub_ass(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page
     }
 
     if (buf.len) {
-        sub_rect->type = SUBTITLE_ASS;
+        sub_rect->type = AV_SUBTITLE_FMT_ASS;
         sub_rect->ass = ff_ass_get_dialog(ctx->readorder++, 0, is_subtitle_page ? "Subtitle" : "Teletext", NULL, buf.str);
 
         if (!sub_rect->ass) {
@@ -402,7 +402,7 @@ static int gen_sub_ass(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_page
         }
         av_log(ctx, AV_LOG_DEBUG, "subtext:%s:txetbus\n", sub_rect->ass);
     } else {
-        sub_rect->type = SUBTITLE_NONE;
+        sub_rect->type = AV_SUBTITLE_FMT_NONE;
     }
     av_bprint_finalize(&buf, NULL);
     return 0;
@@ -462,7 +462,7 @@ static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_pa
 
     if (vc >= vcend) {
         av_log(ctx, AV_LOG_DEBUG, "dropping empty page %3x\n", page->pgno);
-        sub_rect->type = SUBTITLE_NONE;
+        sub_rect->type = AV_SUBTITLE_FMT_NONE;
         return 0;
     }
 
@@ -500,7 +500,7 @@ static int gen_sub_bitmap(TeletextContext *ctx, AVSubtitleRect *sub_rect, vbi_pa
     }
     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK] = RGBA(0, 0, 0, 0);
     ((uint32_t *)sub_rect->data[1])[VBI_TRANSPARENT_BLACK + VBI_NB_COLORS] = RGBA(0, 0, 0, 0);
-    sub_rect->type = SUBTITLE_BITMAP;
+    sub_rect->type = AV_SUBTITLE_FMT_BITMAP;
     return 0;
 }
 
@@ -695,7 +695,7 @@ static int teletext_decode_frame(AVCodecContext *avctx, void *data, int *got_sub
         sub->num_rects = 0;
         sub->pts = ctx->pages->pts;
 
-        if (ctx->pages->sub_rect->type != SUBTITLE_NONE) {
+        if (ctx->pages->sub_rect->type != AV_SUBTITLE_FMT_NONE) {
             sub->rects = av_malloc(sizeof(*sub->rects));
             if (sub->rects) {
                 sub->num_rects = 1;
diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
index 2ae5a9bf0b..a4a963a9f2 100644
--- a/libavcodec/movtextenc.c
+++ b/libavcodec/movtextenc.c
@@ -649,8 +649,8 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
     for (i = 0; i < sub->num_rects; i++) {
         const char *ass = sub->rects[i]->ass;
 
-        if (sub->rects[i]->type != SUBTITLE_ASS) {
-            av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+        if (sub->rects[i]->type != AV_SUBTITLE_FMT_ASS) {
+            av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type supported.\n");
             return AVERROR(EINVAL);
         }
 
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 55eda4c2a9..ef4778cd1b 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -513,7 +513,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
     // is defined by the start of the next sub which may contain no
     // objects (i.e. clears the previous sub)
     sub->end_display_time   = UINT32_MAX;
-    sub->format             = 0;
+    sub->format             = AV_SUBTITLE_FMT_BITMAP;
 
     // Blank if last object_count was 0.
     if (!ctx->presentation.object_count)
@@ -539,7 +539,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
             return AVERROR(ENOMEM);
         }
         sub->num_rects++;
-        sub->rects[i]->type = SUBTITLE_BITMAP;
+        sub->rects[i]->type = AV_SUBTITLE_FMT_BITMAP;
 
         /* Process bitmap */
         object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c
index 2e3ac55770..9a550b9e23 100644
--- a/libavcodec/srtenc.c
+++ b/libavcodec/srtenc.c
@@ -240,8 +240,8 @@ static int encode_frame(AVCodecContext *avctx,
     for (i=0; i<sub->num_rects; i++) {
         const char *ass = sub->rects[i]->ass;
 
-        if (sub->rects[i]->type != SUBTITLE_ASS) {
-            av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+        if (sub->rects[i]->type != AV_SUBTITLE_FMT_ASS) {
+            av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type supported.\n");
             return AVERROR(EINVAL);
         }
 
diff --git a/libavcodec/ttmlenc.c b/libavcodec/ttmlenc.c
index ad2eddfdd5..891b4f496f 100644
--- a/libavcodec/ttmlenc.c
+++ b/libavcodec/ttmlenc.c
@@ -90,8 +90,8 @@ static int ttml_encode_frame(AVCodecContext *avctx, uint8_t *buf,
         const char *ass = sub->rects[i]->ass;
         int ret;
 
-        if (sub->rects[i]->type != SUBTITLE_ASS) {
-            av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+        if (sub->rects[i]->type != AV_SUBTITLE_FMT_ASS) {
+            av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type supported.\n");
             return AVERROR(EINVAL);
         }
 
diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index 89b49e42bf..23ad6c32d3 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -167,8 +167,8 @@ static int webvtt_encode_frame(AVCodecContext *avctx,
     for (i=0; i<sub->num_rects; i++) {
         const char *ass = sub->rects[i]->ass;
 
-        if (sub->rects[i]->type != SUBTITLE_ASS) {
-            av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
+        if (sub->rects[i]->type != AV_SUBTITLE_FMT_ASS) {
+            av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type supported.\n");
             return AVERROR(EINVAL);
         }
 
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 979399bae6..5c9e65f737 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -107,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
     }
     sub->rects[0]->x = x; sub->rects[0]->y = y;
     sub->rects[0]->w = w; sub->rects[0]->h = h;
-    sub->rects[0]->type = SUBTITLE_BITMAP;
+    sub->rects[0]->type = AV_SUBTITLE_FMT_BITMAP;
     sub->rects[0]->linesize[0] = w;
     sub->rects[0]->data[0] = av_malloc(w * h);
     sub->rects[0]->nb_colors = 4;
