diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index c63c20370f..c036d37403 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -537,6 +537,17 @@ Decompress non-standard compressed MP3 audio headers.
 Modify metadata embedded in an MPEG-2 stream.
 
 @table @option
+@item a53_cc
+Insert or remove user data containing A/53 closed captions.
+
+@table @samp
+@item pass
+@item insert
+@item remove
+@end table
+
+Default is pass.
+
 @item display_aspect_ratio
 Set the display aspect ratio in the stream.
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 1fb963f820..2a36a31ff2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1227,7 +1227,7 @@ OBJS-$(CONFIG_MPEG4_UNPACK_BFRAMES_BSF)   += mpeg4_unpack_bframes_bsf.o
 OBJS-$(CONFIG_MOV2TEXTSUB_BSF)            += movsub_bsf.o
 OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF)  += mp3_header_decompress_bsf.o \
                                              mpegaudiotabs.o
-OBJS-$(CONFIG_MPEG2_METADATA_BSF)         += mpeg2_metadata_bsf.o
+OBJS-$(CONFIG_MPEG2_METADATA_BSF)         += mpeg2_metadata_bsf.o cbs_misc.o
 OBJS-$(CONFIG_NOISE_BSF)                  += noise_bsf.o
 OBJS-$(CONFIG_NULL_BSF)                   += null_bsf.o
 OBJS-$(CONFIG_OPUS_METADATA_BSF)          += opus_metadata_bsf.o
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index 1aa6e02791..888bace6b2 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -23,6 +23,7 @@
 #include "bsf_internal.h"
 #include "cbs.h"
 #include "cbs_bsf.h"
+#include "cbs_misc.h"
 #include "cbs_mpeg2.h"
 #include "mpeg12.h"
 
@@ -39,10 +40,79 @@ typedef struct MPEG2MetadataContext {
     int colour_primaries;
     int transfer_characteristics;
     int matrix_coefficients;
+    int a53_cc;
 
     int mpeg1_warned;
 } MPEG2MetadataContext;
 
+static int mpeg2_metadata_handle_a53_cc(AVBSFContext *bsf,
+                                          AVPacket *pkt,
+                                          CodedBitstreamFragment *frag)
+{
+    MPEG2MetadataContext *ctx = bsf->priv_data;
+    int err, i;
+    uint8_t *a53_side_data = NULL;
+    size_t a53_side_data_size = 0;
+
+    if (ctx->a53_cc == BSF_ELEMENT_REMOVE || ctx->a53_cc == BSF_ELEMENT_EXTRACT) {
+        for (i = 0; i < frag->nb_units; i++) {
+            MPEG2RawUserData *ud;
+            A53UserData a53_ud;
+
+            if (frag->units[i].type != MPEG2_START_USER_DATA)
+                continue;
+            ud = frag->units[i].content;
+
+            err = ff_cbs_read_a53_user_data(ctx->common.output, &a53_ud, ud->user_data,
+                                            ud->user_data_length);
+            if (err < 0) {
+                // Invalid or something completely different.
+                continue;
+            }
+            if (a53_ud.user_identifier != A53_USER_IDENTIFIER_ATSC ||
+                a53_ud.atsc.user_data_type_code !=
+                    A53_USER_DATA_TYPE_CODE_CC_DATA) {
+                // Valid but something else (e.g. AFD).
+                continue;
+            }
+
+            if (ctx->a53_cc == BSF_ELEMENT_REMOVE) {
+                ff_cbs_delete_unit(frag, i);
+                --i;
+                break;
+            } else if(ctx->a53_cc == BSF_ELEMENT_EXTRACT) {
+                err = ff_cbs_write_a53_cc_side_data(ctx->common.output,
+                                                    &a53_side_data,
+                                                    &a53_side_data_size,
+                                                    &a53_ud);
+                if (err < 0) {
+                    av_log(bsf, AV_LOG_ERROR, "Failed to write "
+                           "A/53 user data for packet side data.\n");
+                    goto fail;
+                }
+
+                if (a53_side_data) {
+                    err = av_packet_add_side_data(pkt, AV_PKT_DATA_A53_CC,
+                                                  a53_side_data, a53_side_data_size);
+                    if (err) {
+                        av_log(bsf, AV_LOG_ERROR, "Failed to attach extracted A/53 "
+                               "side data to packet.\n");
+                        goto fail;
+                    }
+                    a53_side_data = NULL;
+                }
+            }
+        }
+    }
+
+    err = 0;
+
+fail:
+    av_freep(&a53_side_data);
+
+    return err;
+}
+
 
 static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
                                           AVPacket *pkt,
@@ -54,6 +124,13 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
     MPEG2RawSequenceDisplayExtension *sde = NULL;
     int i, se_pos;
 
+    if (pkt && ctx->a53_cc != BSF_ELEMENT_PASS) {
+        int err;
+        err = mpeg2_metadata_handle_a53_cc(bsf, pkt, frag);
+        if (err < 0)
+            return err;
+    }
+
     for (i = 0; i < frag->nb_units; i++) {
         if (frag->units[i].type == MPEG2_START_SEQUENCE_HEADER) {
             sh = frag->units[i].content;
@@ -218,6 +295,9 @@ static const AVOption mpeg2_metadata_options[] = {
         OFFSET(matrix_coefficients), AV_OPT_TYPE_INT,
         { .i64 = -1 }, -1, 255, FLAGS },
 
+    BSF_ELEMENT_OPTIONS_PIRE("a53_cc",
+                             "A/53 Closed Captions in user data",
+                             a53_cc, FLAGS),
     { NULL }
 };
 
