diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index ecbf57c293..3125656027 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -665,3 +665,17 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
 
     return 0;
 }
+
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+                              CodedBitstreamUnit *unit)
+{
+    if (unit->content && (!unit->content_ref ||
+                          !av_buffer_is_writable(unit->content_ref))) {
+        if (!ctx->codec->make_writable)
+            return AVERROR_PATCHWELCOME;
+
+        return ctx->codec->make_writable(ctx, unit);
+    }
+
+    return 0;
+}
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 53ac360bb1..faef6124f1 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -352,5 +352,11 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
                        CodedBitstreamFragment *frag,
                        int position);
 
+/**
+ * Make the content of a unit writable.
+ */
+int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
+                              CodedBitstreamUnit *unit);
+
 
 #endif /* AVCODEC_CBS_H */
diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index e02bc7027a..ce8ee3faaa 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -1305,6 +1305,7 @@ const CodedBitstreamType ff_cbs_type_av1 = {
 
     .split_fragment    = &cbs_av1_split_fragment,
     .read_unit         = &cbs_av1_read_unit,
+    .make_writable     = NULL,
     .write_unit        = &cbs_av1_write_unit,
     .assemble_fragment = &cbs_av1_assemble_fragment,
 
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 666970ed03..7296c4cf29 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1545,6 +1545,7 @@ const CodedBitstreamType ff_cbs_type_h264 = {
 
     .split_fragment    = &cbs_h2645_split_fragment,
     .read_unit         = &cbs_h264_read_nal_unit,
+    .make_writable     = NULL,
     .write_unit        = &cbs_h2645_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
@@ -1558,6 +1559,7 @@ const CodedBitstreamType ff_cbs_type_h265 = {
 
     .split_fragment    = &cbs_h2645_split_fragment,
     .read_unit         = &cbs_h265_read_nal_unit,
+    .make_writable     = NULL,
     .write_unit        = &cbs_h2645_write_nal_unit,
     .assemble_fragment = &cbs_h2645_assemble_fragment,
 
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 53f2e5d187..62a836af90 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -44,6 +44,10 @@ typedef struct CodedBitstreamType {
     int (*read_unit)(CodedBitstreamContext *ctx,
                      CodedBitstreamUnit *unit);
 
+    // Make a unit's content writable.
+    int (*make_writable)(CodedBitstreamContext *ctx,
+                         CodedBitstreamUnit *unit);
+
     // Write the unit->data bitstream from unit->content.
     int (*write_unit)(CodedBitstreamContext *ctx,
                       CodedBitstreamUnit *unit);
diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
index 5a72f0e2e7..f3706e7575 100644
--- a/libavcodec/cbs_jpeg.c
+++ b/libavcodec/cbs_jpeg.c
@@ -513,6 +513,7 @@ const CodedBitstreamType ff_cbs_type_jpeg = {
 
     .split_fragment    = &cbs_jpeg_split_fragment,
     .read_unit         = &cbs_jpeg_read_unit,
+    .make_writable     = NULL,
     .write_unit        = &cbs_jpeg_write_unit,
     .assemble_fragment = &cbs_jpeg_assemble_fragment,
 
diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 8b8b266563..3e6a109550 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -414,6 +414,7 @@ const CodedBitstreamType ff_cbs_type_mpeg2 = {
 
     .split_fragment    = &cbs_mpeg2_split_fragment,
     .read_unit         = &cbs_mpeg2_read_unit,
+    .make_writable     = NULL,
     .write_unit        = &cbs_mpeg2_write_unit,
     .assemble_fragment = &cbs_mpeg2_assemble_fragment,
 
diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
index c03ce986c0..e939ec10ba 100644
--- a/libavcodec/cbs_vp9.c
+++ b/libavcodec/cbs_vp9.c
@@ -685,6 +685,7 @@ const CodedBitstreamType ff_cbs_type_vp9 = {
 
     .split_fragment    = &cbs_vp9_split_fragment,
     .read_unit         = &cbs_vp9_read_unit,
+    .make_writable     = NULL,
     .write_unit        = &cbs_vp9_write_unit,
     .assemble_fragment = &cbs_vp9_assemble_fragment,
 
