diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index af69064e9b..211d4cee34 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1833,8 +1833,8 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl,
     return 0;
 }
 
-static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
-                                   const H2645NAL *nal)
+int ff_h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
+                                   const H2645NAL *nal, int err_recognition, void *logctx)
 {
     const SPS *sps;
     const PPS *pps;
@@ -1851,7 +1851,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
 
     slice_type = get_ue_golomb_31(&sl->gb);
     if (slice_type > 9) {
-        av_log(h->avctx, AV_LOG_ERROR,
+        av_log(logctx, AV_LOG_ERROR,
                "slice type %d too large at %d\n",
                slice_type, sl->first_mb_addr);
         return AVERROR_INVALIDDATA;
@@ -1868,17 +1868,17 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
 
     if (nal->type  == H264_NAL_IDR_SLICE &&
         sl->slice_type_nos != AV_PICTURE_TYPE_I) {
-        av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
+        av_log(logctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
         return AVERROR_INVALIDDATA;
     }
 
     sl->pps_id = get_ue_golomb(&sl->gb);
     if (sl->pps_id >= MAX_PPS_COUNT) {
-        av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id);
+        av_log(logctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id);
         return AVERROR_INVALIDDATA;
     }
     if (!h->ps.pps_list[sl->pps_id]) {
-        av_log(h->avctx, AV_LOG_ERROR,
+        av_log(logctx, AV_LOG_ERROR,
                "non-existing PPS %u referenced\n",
                sl->pps_id);
         return AVERROR_INVALIDDATA;
@@ -1889,7 +1889,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
     sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);
     if (!first_slice) {
         if (h->poc.frame_num != sl->frame_num) {
-            av_log(h->avctx, AV_LOG_ERROR, "Frame num change from %d to %d\n",
+            av_log(logctx, AV_LOG_ERROR, "Frame num change from %d to %d\n",
                    h->poc.frame_num, sl->frame_num);
             return AVERROR_INVALIDDATA;
         }
@@ -1901,7 +1901,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
         picture_structure = PICT_FRAME;
     } else {
         if (!sps->direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) {
-            av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
+            av_log(logctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
             return -1;
         }
         field_pic_flag = get_bits1(&sl->gb);
@@ -1928,7 +1928,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
         if (idr_pic_id < 65536) {
             sl->idr_pic_id = idr_pic_id;
         } else
-            av_log(h->avctx, AV_LOG_WARNING, "idr_pic_id is invalid\n");
+            av_log(logctx, AV_LOG_WARNING, "idr_pic_id is invalid\n");
     }
 
     sl->poc_lsb = 0;
@@ -1957,12 +1957,12 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
 
     ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,
                                   &sl->gb, pps, sl->slice_type_nos,
-                                  picture_structure, h->avctx);
+                                  picture_structure, logctx);
     if (ret < 0)
         return ret;
 
     if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
-       ret = ff_h264_decode_ref_pic_list_reordering(sl, h->avctx);
+       ret = ff_h264_decode_ref_pic_list_reordering(sl, logctx);
        if (ret < 0) {
            sl->ref_count[1] = sl->ref_count[0] = 0;
            return ret;
@@ -1979,22 +1979,22 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
          sl->slice_type_nos == AV_PICTURE_TYPE_B)) {
         ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
                                   sl->slice_type_nos, &sl->pwt,
-                                  picture_structure, h->avctx);
+                                  picture_structure, logctx);
         if (ret < 0)
             return ret;
     }
 
     sl->explicit_ref_marking = 0;
     if (nal->ref_idc) {
-        ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, h->avctx);
-        if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
+        ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, logctx);
+        if (ret < 0 && (err_recognition & AV_EF_EXPLODE))
             return AVERROR_INVALIDDATA;
     }
 
     if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {
         tmp = get_ue_golomb_31(&sl->gb);
         if (tmp > 2) {
-            av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
+            av_log(logctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
             return AVERROR_INVALIDDATA;
         }
         sl->cabac_init_idc = tmp;
@@ -2003,7 +2003,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
     sl->last_qscale_diff = 0;
     tmp = pps->init_qp + (unsigned)get_se_golomb(&sl->gb);
     if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {
-        av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
+        av_log(logctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
         return AVERROR_INVALIDDATA;
     }
     sl->qscale       = tmp;
@@ -2022,7 +2022,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
     if (pps->deblocking_filter_parameters_present) {
         tmp = get_ue_golomb_31(&sl->gb);
         if (tmp > 2) {
-            av_log(h->avctx, AV_LOG_ERROR,
+            av_log(logctx, AV_LOG_ERROR,
                    "deblocking_filter_idc %u out of range\n", tmp);
             return AVERROR_INVALIDDATA;
         }
@@ -2037,7 +2037,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
                 slice_alpha_c0_offset_div2 < -6 ||
                 slice_beta_offset_div2 >  6     ||
                 slice_beta_offset_div2 < -6) {
-                av_log(h->avctx, AV_LOG_ERROR,
+                av_log(logctx, AV_LOG_ERROR,
                        "deblocking filter parameters %d %d out of range\n",
                        slice_alpha_c0_offset_div2, slice_beta_offset_div2);
                 return AVERROR_INVALIDDATA;
@@ -2090,7 +2090,8 @@ static int h264_slice_init(H264Context *h, H264SliceContext *sl,
 
     if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)
         ff_h264_direct_dist_scale_factor(h, sl);
-    ff_h264_direct_ref_list_init(h, sl);
+    if (!h->setup_finished)
+        ff_h264_direct_ref_list_init(h, sl);
 
     if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||
         (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&
@@ -2123,7 +2124,7 @@ static int h264_slice_init(H264Context *h, H264SliceContext *sl,
     if (h->current_slice >= 0xFFFE) {
         av_log(h->avctx, AV_LOG_ERROR, "Too many slices (%d)\n", h->current_slice + 1);
         return AVERROR_PATCHWELCOME;
-    }
+    }                   
 
     sl->slice_num       = ++h->current_slice;
 
@@ -2201,7 +2202,7 @@ int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal)
 
     sl->gb = nal->gb;
 
-    ret = h264_slice_header_parse(h, sl, nal);
+    ret = ff_h264_slice_header_parse(h, sl, nal, h->avctx->err_recognition, h->avctx);
     if (ret < 0)
         return ret;
 
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index 9a1ec1bace..4dee2595ce 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -561,6 +561,9 @@ extern const uint16_t ff_h264_mb_sizes[4];
  */
 int ff_h264_get_slice_type(const H264SliceContext *sl);
 
+int ff_h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
+                                   const H2645NAL *nal, int err_recognition, void *logctx);
+
 /**
  * Allocate tables.
  * needs width/height
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index cdaa920c17..f9946a2cc1 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -108,9 +108,10 @@ static const AVOption options[] = {
     { "fragment_index", "Fragment number of the next fragment", offsetof(MOVMuxContext, fragments), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
     { "mov_gamma", "gamma value for gama atom", offsetof(MOVMuxContext, gamma), AV_OPT_TYPE_FLOAT, {.dbl = 0.0 }, 0.0, 10, AV_OPT_FLAG_ENCODING_PARAM},
     { "frag_interleave", "Interleave samples within fragments (max number of consecutive samples, lower is tighter interleaving, but with more overhead)", offsetof(MOVMuxContext, frag_interleave), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
-    { "encryption_scheme",    "Configures the encryption scheme, allowed values are none, cenc-aes-ctr", offsetof(MOVMuxContext, encryption_scheme_str),   AV_OPT_TYPE_STRING, {.str = NULL}, .flags = AV_OPT_FLAG_ENCODING_PARAM },
+    { "encryption_scheme",    "Configures the encryption scheme, allowed values are none, cenc-aes-ctr or cenc-aes-cbc", offsetof(MOVMuxContext, encryption_scheme_str),   AV_OPT_TYPE_STRING, {.str = "none"}, .flags = AV_OPT_FLAG_ENCODING_PARAM },
     { "encryption_key", "The media encryption key (hex)", offsetof(MOVMuxContext, encryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
     { "encryption_kid", "The media encryption key identifier (hex)", offsetof(MOVMuxContext, encryption_kid), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
+    { "encryption_iv", "The media encryption iv (hex)", offsetof(MOVMuxContext, encryption_iv), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
     { "use_stream_ids_as_track_ids", "use stream ids as track ids", offsetof(MOVMuxContext, use_stream_ids_as_track_ids), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
     { "write_btrt", "force or disable writing btrt", offsetof(MOVMuxContext, write_btrt), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
     { "write_tmcd", "force or disable writing tmcd", offsetof(MOVMuxContext, write_tmcd), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
@@ -119,6 +120,7 @@ static const AVOption options[] = {
     { "pts", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = MOV_PRFT_SRC_PTS}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM, "prft"},
     { "empty_hdlr_name", "write zero-length name string in hdlr atoms within mdia and minf atoms", offsetof(MOVMuxContext, empty_hdlr_name), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
     { "movie_timescale", "set movie timescale", offsetof(MOVMuxContext, movie_timescale), AV_OPT_TYPE_INT, {.i64 = MOV_TIMESCALE}, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+    { "earliest_presentation_time_offsets", "set offsets for earliest_presentation_time in sidx", offsetof(MOVMuxContext, epts_offsets), AV_OPT_TYPE_DICT, {.str = NULL},  0, 0, AV_OPT_FLAG_ENCODING_PARAM},
     { NULL },
 };
 
@@ -2721,7 +2723,7 @@ static int mov_write_stbl_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext
     mov_write_stsc_tag(pb, track);
     mov_write_stsz_tag(pb, track);
     mov_write_stco_tag(pb, track);
-    if (track->cenc.aes_ctr) {
+    if ((track->cenc.aes_ctr || track->cenc.aes_cbc) && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
         ff_mov_cenc_write_stbl_atoms(&track->cenc, pb);
     }
     if (track->par->codec_id == AV_CODEC_ID_OPUS || track->par->codec_id == AV_CODEC_ID_AAC) {
@@ -4928,15 +4930,25 @@ static void mov_prune_frag_info(MOVMuxContext *mov, int tracks, int max)
     }
 }
 
-static int mov_write_tfdt_tag(AVIOContext *pb, MOVTrack *track)
+static int mov_write_tfdt_tag(AVIOContext *pb, MOVTrack *track, MOVMuxContext *ctx)
 {
     int64_t pos = avio_tell(pb);
+    int64_t time = track->cluster[0].dts - track->start_dts;
 
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "tfdt");
     avio_w8(pb, 1); /* version */
     avio_wb24(pb, 0);
-    avio_wb64(pb, track->cluster[0].dts - track->start_dts);
+
+    AVDictionaryEntry *en = NULL;
+    while ((en = av_dict_get(ctx->epts_offsets, "", en, AV_DICT_IGNORE_SUFFIX))) {
+        if (track->track_id == atoi(en->key)) {
+            time = strtol(en->value, NULL, 10);
+            break;
+        }
+    }
+
+    avio_wb64(pb, time);
     return update_size(pb, pos);
 }
 
@@ -4951,7 +4963,7 @@ static int mov_write_traf_tag(AVIOContext *pb, MOVMuxContext *mov,
 
     mov_write_tfhd_tag(pb, mov, track, moof_offset);
     if (mov->mode != MODE_ISM)
-        mov_write_tfdt_tag(pb, track);
+        mov_write_tfdt_tag(pb, track, mov);
     for (i = 1; i < track->entry; i++) {
         if (track->cluster[i].pos != track->cluster[i - 1].pos + track->cluster[i - 1].size) {
             mov_write_trun_tag(pb, mov, track, moof_size, start, i);
@@ -4976,6 +4988,10 @@ static int mov_write_traf_tag(AVIOContext *pb, MOVMuxContext *mov,
         }
     }
 
+    if ((track->cenc.aes_ctr || track->cenc.aes_cbc) && mov->flags & FF_MOV_FLAG_FRAGMENT) {
+        ff_mov_cenc_write_stbl_atoms(&track->cenc, pb);
+    }
+
     return update_size(pb, pos);
 }
 
@@ -5002,13 +5018,14 @@ static int mov_write_moof_tag_internal(AVIOContext *pb, MOVMuxContext *mov,
     return update_size(pb, pos);
 }
 
-static int mov_write_sidx_tag(AVIOContext *pb,
+static int mov_write_sidx_tag(MOVMuxContext *ctx, AVIOContext *pb,
                               MOVTrack *track, int ref_size, int total_sidx_size)
 {
     int64_t pos = avio_tell(pb), offset_pos, end_pos;
     int64_t presentation_time, duration, offset;
     unsigned starts_with_SAP;
     int i, entries;
+    AVDictionaryEntry *offsets = NULL;
 
     if (track->entry) {
         entries = 1;
@@ -5033,6 +5050,14 @@ static int mov_write_sidx_tag(AVIOContext *pb,
             presentation_time -= track->start_dts + track->start_cts;
     }
 
+    
+    while ((offsets = av_dict_get(ctx->epts_offsets, "", offsets, AV_DICT_IGNORE_SUFFIX))) {
+        if (track->track_id == atoi(offsets->key)) {
+            presentation_time += strtol(offsets->value, NULL, 10);
+            break;
+        }
+    }
+
     avio_wb32(pb, 0); /* size */
     ffio_wfourcc(pb, "sidx");
     avio_w8(pb, 1); /* version */
@@ -5093,7 +5118,7 @@ static int mov_write_sidx_tags(AVIOContext *pb, MOVMuxContext *mov,
             // since we read it from frag_info instead.
             if (!track->entry && ref_size > 0)
                 continue;
-            total_size -= mov_write_sidx_tag(avio_buf, track, ref_size,
+            total_size -= mov_write_sidx_tag(mov, avio_buf, track, ref_size,
                                              total_size);
         }
         if (round == 0)
@@ -6069,8 +6094,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
                 return ret;
             avio_write(pb, reformatted_data, size);
         } else {
-            if (trk->cenc.aes_ctr) {
-                size = ff_mov_cenc_avc_parse_nal_units(&trk->cenc, pb, pkt->data, size);
+            if (trk->cenc.aes_ctr || trk->cenc.aes_cbc) {
+                size = ff_mov_cenc_avc_parse_nal_units(s, &trk->cenc, pb, pkt->data, size);
                 if (size < 0) {
                     ret = size;
                     goto err;
@@ -6089,8 +6114,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
                 return ret;
             avio_write(pb, reformatted_data, size);
         } else {
-            if (trk->cenc.aes_ctr) {
-                size = ff_mov_cenc_avc_parse_nal_units(&trk->cenc, pb, pkt->data, size);
+            if (trk->cenc.aes_ctr || trk->cenc.aes_cbc) {
+                size = ff_mov_cenc_avc_parse_nal_units(s, &trk->cenc, pb, pkt->data, size);
                 if (size < 0) {
                     ret = size;
                     goto err;
@@ -6138,7 +6163,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             }
         }
     } else {
-        if (trk->cenc.aes_ctr) {
+        if (trk->cenc.aes_ctr || trk->cenc.aes_cbc) {
             if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 4) {
                 int nal_size_length = (par->extradata[4] & 0x3) + 1;
                 ret = ff_mov_cenc_avc_write_nal_units(s, &trk->cenc, nal_size_length, pb, pkt->data, size);
@@ -7022,12 +7047,32 @@ static int mov_init(AVFormatContext *s)
         if (strcmp(mov->encryption_scheme_str, "cenc-aes-ctr") == 0) {
             mov->encryption_scheme = MOV_ENC_CENC_AES_CTR;
 
+            if (mov->encryption_key_len != AES_CTR_KEY_SIZE) {
+                av_log(s, AV_LOG_ERROR, "Invalid encryption key len %d expected %d\n",
+                       mov->encryption_key_len, AES_CTR_KEY_SIZE);
+                return AVERROR(EINVAL);
+            }
+
+            if (mov->encryption_kid_len != CENC_KID_SIZE) {
+                av_log(s, AV_LOG_ERROR, "Invalid encryption kid len %d expected %d\n",
+                       mov->encryption_kid_len, CENC_KID_SIZE);
+                return AVERROR(EINVAL);
+            }
+        } else if (strcmp(mov->encryption_scheme_str, "cenc-aes-cbc") == 0) {
+            mov->encryption_scheme = MOV_ENC_CENC_AES_CBC;
+
             if (mov->encryption_key_len != AES_CTR_KEY_SIZE) {
                 av_log(s, AV_LOG_ERROR, "Invalid encryption key len %d expected %d\n",
                     mov->encryption_key_len, AES_CTR_KEY_SIZE);
                 return AVERROR(EINVAL);
             }
 
+            if (mov->encryption_iv_len != 0 && mov->encryption_iv_len != CBCS_IV_SIZE) {
+                av_log(s, AV_LOG_ERROR, "Invalid iv len %d expected %d\n",
+                    mov->encryption_iv_len, CBCS_IV_SIZE);
+                return AVERROR(EINVAL);
+            }
+
             if (mov->encryption_kid_len != CENC_KID_SIZE) {
                 av_log(s, AV_LOG_ERROR, "Invalid encryption kid len %d expected %d\n",
                     mov->encryption_kid_len, CENC_KID_SIZE);
@@ -7226,11 +7271,17 @@ static int mov_init(AVFormatContext *s)
         avpriv_set_pts_info(st, 64, 1, track->timescale);
 
         if (mov->encryption_scheme == MOV_ENC_CENC_AES_CTR) {
-            ret = ff_mov_cenc_init(&track->cenc, mov->encryption_key,
+            ret = ff_mov_cenc_init(s, &track->cenc, mov->encryption_scheme_str, mov->encryption_key, NULL,
                 (track->par->codec_id == AV_CODEC_ID_H264 || track->par->codec_id == AV_CODEC_ID_HEVC),
                 s->flags & AVFMT_FLAG_BITEXACT);
             if (ret)
                 return ret;
+        } else if (mov->encryption_scheme == MOV_ENC_CENC_AES_CBC) {
+            ret = ff_mov_cenc_init(s, &track->cenc, mov->encryption_scheme_str, mov->encryption_key, mov->encryption_iv,
+                1, s->flags & AVFMT_FLAG_BITEXACT);
+            ret = ff_mov_cbcs_set_extradata(s, &track->cenc, track->par->codec_type, track->par->codec_id, track->par->extradata, track->par->extradata_size);
+            if (ret)
+                return ret;
         }
     }
 
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index c6b3313deb..13f4e4e8c5 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -175,6 +175,7 @@ typedef struct MOVTrack {
 typedef enum {
     MOV_ENC_NONE = 0,
     MOV_ENC_CENC_AES_CTR,
+    MOV_ENC_CENC_AES_CBC,
 } MOVEncryptionScheme;
 
 typedef enum {
@@ -235,6 +236,8 @@ typedef struct MOVMuxContext {
     int encryption_key_len;
     uint8_t *encryption_kid;
     int encryption_kid_len;
+    uint8_t *encryption_iv;
+    int encryption_iv_len;
 
     int need_rewrite_extradata;
 
@@ -249,6 +252,8 @@ typedef struct MOVMuxContext {
     int64_t avif_extent_pos[2];  // index 0 is YUV and 1 is Alpha.
     int avif_extent_length[2];   // index 0 is YUV and 1 is Alpha.
     int is_animated_avif;
+
+    AVDictionary *epts_offsets;
 } MOVMuxContext;
 
 #define FF_MOV_FLAG_RTP_HINT              (1 <<  0)
diff --git a/libavformat/movenccenc.c b/libavformat/movenccenc.c
index 74f3c4ccfb..a7b0705cf3 100644
--- a/libavformat/movenccenc.c
+++ b/libavformat/movenccenc.c
@@ -1,7 +1,7 @@
 /*
  * MOV CENC (Common Encryption) writer
  * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com>
- *
+ * Copyright (c) 2026 Olivier Ayache <olivier dot ayache at gmail dot com>
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -20,6 +20,12 @@
  */
 #include "movenccenc.h"
 #include "libavutil/intreadwrite.h"
+#include "libavcodec/get_bits.h"
+#include "libavcodec/golomb.h"
+#include "libavcodec/h264data.h"
+#include "libavcodec/h2645_parse.h"
+#include "libavcodec/hevcdec.h"
+#include "libavutil/random_seed.h"
 #include "avio_internal.h"
 #include "movenc.h"
 #include "avc.h"
@@ -60,7 +66,7 @@ static int auxiliary_info_add_subsample(MOVMuxCencContext* ctx,
 {
     uint8_t* p;
     int ret;
-
+            
     if (!ctx->use_subsamples) {
         return 0;
     }
@@ -103,6 +109,40 @@ static void mov_cenc_write_encrypted(MOVMuxCencContext* ctx, AVIOContext *pb,
     }
 }
 
+/**
+ * Encrypt the input buffer and write using avio_write
+ */
+static void mov_cbcs_write_encrypted(MOVMuxCencContext* ctx, AVIOContext *pb,
+                                     const uint8_t *buf_in, int size)
+{
+    int encrypted_bytes = ctx->codec_type == AVMEDIA_TYPE_VIDEO ? CBCS_VIDEO_ENCRYPTED : CBCS_AUDIO_ENCRYPTED;
+    int clear_bytes = ctx->codec_type == AVMEDIA_TYPE_VIDEO ? CBCS_VIDEO_SKIP : CBCS_AUDIO_SKIP;
+    const uint8_t* cur_pos = buf_in;
+    uint8_t iv[16];
+    int size_left = size;
+    
+    memcpy(iv, ctx->iv, 16);
+    
+    while (size_left > 0) {
+        if (size_left < encrypted_bytes) {
+            avio_write(pb, cur_pos, size_left);
+            break;
+        }
+        av_aes_crypt(ctx->aes_cbc, cur_pos, cur_pos, 1, iv, 0);
+        avio_write(pb, cur_pos, encrypted_bytes);
+        cur_pos += encrypted_bytes;
+        size_left -= encrypted_bytes;
+        if (clear_bytes > 0) {
+            avio_write(pb, cur_pos, FFMIN(clear_bytes, size_left));
+            cur_pos += FFMIN(clear_bytes, size_left);
+            size_left -= FFMIN(clear_bytes, size_left);
+        }
+    }
+
+}
+
+
+
 /**
  * Start writing a packet
  */
@@ -111,9 +151,11 @@ static int mov_cenc_start_packet(MOVMuxCencContext* ctx)
     int ret;
 
     /* write the iv */
-    ret = auxiliary_info_write(ctx, av_aes_ctr_get_iv(ctx->aes_ctr), AES_CTR_IV_SIZE);
-    if (ret) {
-        return ret;
+    if (!ctx->constant_iv){
+        ret = auxiliary_info_write(ctx, ctx->iv, ctx->iv_size);
+        if (ret) {
+            return ret;
+        }
     }
 
     if (!ctx->use_subsamples) {
@@ -131,6 +173,23 @@ static int mov_cenc_start_packet(MOVMuxCencContext* ctx)
     return 0;
 }
 
+static void mov_cenc_increment_iv(MOVMuxCencContext* ctx)
+{
+    if (ctx->aes_ctr) {
+        av_aes_ctr_increment_iv(ctx->aes_ctr);
+        ctx->iv = av_aes_ctr_get_iv(ctx->aes_ctr);
+    } else {
+        uint8_t* cur_pos;
+        uint8_t* counter = ctx->iv;
+        for (cur_pos = counter + 7; cur_pos >= counter; cur_pos--) {
+            (*cur_pos)++;
+            if (*cur_pos != 0) {
+                break;
+            }
+        }
+    }
+}
+
 /**
  * Finalize a packet
  */
@@ -138,7 +197,8 @@ static int mov_cenc_end_packet(MOVMuxCencContext* ctx)
 {
     size_t new_alloc_size;
 
-    av_aes_ctr_increment_iv(ctx->aes_ctr);
+    if (!ctx->constant_iv)
+        mov_cenc_increment_iv(ctx);
 
     if (!ctx->use_subsamples) {
         ctx->auxiliary_info_entries++;
@@ -155,7 +215,7 @@ static int mov_cenc_end_packet(MOVMuxCencContext* ctx)
         ctx->auxiliary_info_sizes_alloc_size = new_alloc_size;
     }
     ctx->auxiliary_info_sizes[ctx->auxiliary_info_entries] =
-        AES_CTR_IV_SIZE + ctx->auxiliary_info_size - ctx->auxiliary_info_subsample_start;
+        (ctx->constant_iv ? 0 : ctx->iv_size) + ctx->auxiliary_info_size - ctx->auxiliary_info_subsample_start;
     ctx->auxiliary_info_entries++;
 
     /* update the subsample count*/
@@ -179,7 +239,11 @@ int ff_mov_cenc_write_packet(MOVMuxCencContext* ctx, AVIOContext *pb,
         return ret;
     }
 
-    mov_cenc_write_encrypted(ctx, pb, buf_in, size);
+    if (ctx->aes_ctr) {
+        mov_cenc_write_encrypted(ctx, pb, buf_in, size);
+    } else if (ctx->aes_cbc) {
+        mov_cbcs_write_encrypted(ctx, pb, buf_in, size);
+    }
 
     ret = mov_cenc_end_packet(ctx);
     if (ret) {
@@ -189,7 +253,142 @@ int ff_mov_cenc_write_packet(MOVMuxCencContext* ctx, AVIOContext *pb,
     return 0;
 }
 
-int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
+int ff_mov_cbcs_set_extradata(AVFormatContext* s, MOVMuxCencContext* ctx, enum AVMediaType codec_type, enum AVCodecID codec_id,
+                                      const uint8_t *extradata, int size)
+{
+    ctx->codec_type = codec_type;
+    ctx->codec_id = codec_id;
+    if (codec_type == AVMEDIA_TYPE_VIDEO) {
+        switch (codec_id) {
+            case AV_CODEC_ID_H264:
+                ff_h264_decode_extradata(extradata, size, &ctx->h264_ps, &ctx->is_nalff, &ctx->nal_length_size, 0, s);
+                break;
+            case AV_CODEC_ID_HEVC:
+                ff_hevc_decode_extradata(extradata, size, &ctx->hevc_ps, &ctx->hevc_sei, &ctx->is_nalff, &ctx->nal_length_size, 0, 1, s);
+                break;
+            default:
+                return AVERROR(EINVAL);
+        }
+    }
+    return 0;
+}
+
+static int hevc_parse_nal_header(H2645NAL *nal, void *logctx)
+{     
+    GetBitContext *gb = &nal->gb;
+
+    if (get_bits1(gb) != 0)
+        return AVERROR_INVALIDDATA;
+
+    nal->type = get_bits(gb, 6);
+
+    nal->nuh_layer_id = get_bits(gb, 6);
+    nal->temporal_id = get_bits(gb, 3) - 1;
+    if (nal->temporal_id < 0)
+        return AVERROR_INVALIDDATA;
+
+    return 1;
+}
+
+static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
+{
+    GetBitContext *gb = &nal->gb;
+
+    if (get_bits1(gb) != 0)
+        return AVERROR_INVALIDDATA;
+
+    nal->ref_idc = get_bits(gb, 2);
+    nal->type    = get_bits(gb, 5);
+
+    return 1;
+}
+
+static int mov_cbcs_h2645_write_nal_units(AVFormatContext *s, MOVMuxCencContext* ctx, AVIOContext *pb,
+                                      const uint8_t *buf_in, int size, int offset)
+{
+    int ret = 0;
+    const uint8_t* cur_pos = buf_in;
+    int slice_header_size, start, end, written = 0;
+
+    int nal_header_size;
+    int nal_size;
+    H2645Packet pkt = {0};
+    H2645NAL nal;
+
+    H264SliceContext sl;
+    H264Context h;
+
+    ret = ff_h2645_packet_split(&pkt, buf_in, size, s, ctx->is_nalff, ctx->nal_length_size, ctx->codec_id, 0, 0);
+
+    if (ret < 0) {
+        goto end;
+    }
+        
+    for (size_t i = 0; i < pkt.nb_nals; i++) {
+        if (ctx->codec_id == AV_CODEC_ID_H264) {
+            nal_header_size = 1;
+        } else if (ctx->codec_id == AV_CODEC_ID_HEVC) {
+            nal_header_size = 2;
+        }
+            
+        nal = pkt.nals[i];
+        nal_size = nal.raw_size;
+            
+        cur_pos = nal.raw_data - ctx->nal_length_size;
+
+        if (ctx->nal_length_size == 0) {
+            avio_wb32(pb, nal_size);
+            avio_write(pb, cur_pos, nal_header_size);
+            offset = 4 + nal_header_size;
+            cur_pos += nal_header_size;
+        } else {
+            avio_write(pb, cur_pos, ctx->nal_length_size + nal_header_size);
+            offset = ctx->nal_length_size + nal_header_size;
+            cur_pos += offset;
+        }
+
+        if (nal.type != H264_NAL_SLICE && nal.type != H264_NAL_IDR_SLICE) {
+            avio_write(pb, cur_pos, nal_size - nal_header_size);
+            ret = auxiliary_info_add_subsample(ctx, nal_size - nal_header_size + offset, 0);
+            if (ret < 0) {
+                goto end;
+            }
+            cur_pos += nal_size - nal_header_size;
+        } else {     
+            sl.gb = nal.gb;
+            h.setup_finished = 0;
+            h.current_slice = 0;
+            h.slice_ctx = &sl;
+            h.ps = ctx->h264_ps;
+
+            start = get_bits_count(&sl.gb);    
+            ret = ff_h264_slice_header_parse(&h, &sl, &nal, 1, s);
+            if (ret < 0) {
+                goto end;
+            }
+            
+            end = get_bits_count(&sl.gb);
+            slice_header_size = (end - start + 7) >> 3;
+    
+            avio_write(pb, cur_pos, slice_header_size);
+            cur_pos += slice_header_size;
+    
+            mov_cbcs_write_encrypted(ctx, pb, cur_pos, nal_size - slice_header_size - nal_header_size);
+            ret = auxiliary_info_add_subsample(ctx, slice_header_size + offset, nal_size - slice_header_size - nal_header_size);
+            if (ret < 0) {
+                goto end;
+            }
+            
+            written += offset + slice_header_size + nal_size - slice_header_size - nal_header_size;
+        }
+    }
+
+    end:
+        ff_h2645_packet_uninit(&pkt);
+        return ret;
+}
+
+int ff_mov_cenc_avc_parse_nal_units(AVFormatContext* s, MOVMuxCencContext* ctx, AVIOContext *pb,
                                  const uint8_t *buf_in, int size)
 {
     const uint8_t *p = buf_in;
@@ -202,23 +401,29 @@ int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb,
         return ret;
     }
 
-    size = 0;
-    nal_start = ff_avc_find_startcode(p, end);
-    for (;;) {
-        while (nal_start < end && !*(nal_start++));
-        if (nal_start == end)
-            break;
+    if (ctx->aes_cbc) {
+        size = mov_cbcs_h2645_write_nal_units(s, ctx, pb, buf_in, size, 0);
+    } else {
+        size = 0;
+        nal_start = ff_avc_find_startcode(p, end);
+        for (;;) {
+            while (nal_start < end && !*(nal_start++));
+            if (nal_start == end)
+                break;
 
-        nal_end = ff_avc_find_startcode(nal_start, end);
+            nal_end = ff_avc_find_startcode(nal_start, end);
 
-        avio_wb32(pb, nal_end - nal_start);
-        avio_w8(pb, *nal_start);
-        mov_cenc_write_encrypted(ctx, pb, nal_start + 1, nal_end - nal_start - 1);
+            avio_wb32(pb, nal_end - nal_start);
+            avio_w8(pb, *nal_start);
 
-        auxiliary_info_add_subsample(ctx, 5, nal_end - nal_start - 1);
+            if (ctx->aes_ctr) {
+                mov_cenc_write_encrypted(ctx, pb, nal_start + 1, nal_end - nal_start - 1);
+                auxiliary_info_add_subsample(ctx, 5, nal_end - nal_start - 1);
+            }
 
-        size += 4 + nal_end - nal_start;
-        nal_start = nal_end;
+            size += 4 + nal_end - nal_start;
+            nal_start = nal_end;
+        }
     }
 
     ret = mov_cenc_end_packet(ctx);
@@ -241,35 +446,39 @@ int ff_mov_cenc_avc_write_nal_units(AVFormatContext *s, MOVMuxCencContext* ctx,
         return ret;
     }
 
-    while (size > 0) {
-        /* parse the nal size */
-        if (size < nal_length_size + 1) {
-            av_log(s, AV_LOG_ERROR, "CENC-AVC: remaining size %d smaller than nal length+type %d\n",
-                size, nal_length_size + 1);
-            return -1;
-        }
-
-        avio_write(pb, buf_in, nal_length_size + 1);
-
-        nalsize = 0;
-        for (j = 0; j < nal_length_size; j++) {
-            nalsize = (nalsize << 8) | *buf_in++;
-        }
-        size -= nal_length_size;
-
-        /* encrypt the nal body */
-        if (nalsize <= 0 || nalsize > size) {
-            av_log(s, AV_LOG_ERROR, "CENC-AVC: nal size %d remaining %d\n", nalsize, size);
-            return -1;
+    if (ctx->aes_cbc) {
+       ret = mov_cbcs_h2645_write_nal_units(s, ctx, pb, buf_in, size, 0);
+    } else {
+        while (size > 0) {
+            /* parse the nal size */
+            if (size < nal_length_size + 1) {
+                av_log(s, AV_LOG_ERROR, "CENC-AVC: remaining size %d smaller than nal length+type %d\n",
+                    size, nal_length_size + 1);
+                return -1;
+            }
+
+            avio_write(pb, buf_in, nal_length_size + 1);
+
+            nalsize = 0;
+            for (j = 0; j < nal_length_size; j++) {
+                nalsize = (nalsize << 8) | *buf_in++;
+            }
+            size -= nal_length_size;
+
+            /* encrypt the nal body */
+            if (nalsize <= 0 || nalsize > size) {
+                av_log(s, AV_LOG_ERROR, "CENC-AVC: nal size %d remaining %d\n", nalsize, size);
+                return -1;
+            }
+
+            if (ctx->aes_ctr) {
+                mov_cenc_write_encrypted(ctx, pb, buf_in + 1, nalsize - 1);
+                auxiliary_info_add_subsample(ctx, nal_length_size + 1, nalsize - 1);
+            }
+            buf_in += nalsize;
+            size -= nalsize;
         }
-
-        mov_cenc_write_encrypted(ctx, pb, buf_in + 1, nalsize - 1);
-        buf_in += nalsize;
-        size -= nalsize;
-
-        auxiliary_info_add_subsample(ctx, nal_length_size + 1, nalsize - 1);
     }
-
     ret = mov_cenc_end_packet(ctx);
     if (ret) {
         return ret;
@@ -345,19 +554,43 @@ void ff_mov_cenc_write_stbl_atoms(MOVMuxCencContext* ctx, AVIOContext *pb)
     mov_cenc_write_saiz_tag(ctx, pb);
 }
 
-static int mov_cenc_write_schi_tag(AVIOContext *pb, uint8_t* kid)
+static int mov_cenc_write_schi_tag(MOVTrack* track, AVIOContext *pb, uint8_t* kid, char iv_size)
 {
     int64_t pos = avio_tell(pb);
     avio_wb32(pb, 0);     /* size */
     ffio_wfourcc(pb, "schi");
 
-    avio_wb32(pb, 32);    /* size */
+    if (track->cenc.constant_iv) {
+        avio_wb32(pb, 49);    /* size */
+    } else {
+        avio_wb32(pb, 32);    /* size */
+    }
     ffio_wfourcc(pb, "tenc");
-    avio_wb32(pb, 0);     /* version & flags */
-    avio_wb24(pb, 1);     /* is encrypted */
-    avio_w8(pb, AES_CTR_IV_SIZE); /* iv size */
+    if (track->cenc.aes_ctr) {
+        avio_wb32(pb, 0);     /* version & flags */
+        avio_wb24(pb, 1);     /* is encrypted */
+        avio_w8(pb, AES_CTR_IV_SIZE); /* iv size */
+    } else if (track->cenc.aes_cbc) {
+        avio_wl32(pb, 1);     /* version & flags */
+        if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
+            avio_wb24(pb, 0x001901);     /* 1:9 crypt/clear pattern & is encrypted */
+        } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) {
+            avio_wb24(pb, 0x001001);     /* 1:0 crypt/clear pattern & is encrypted */
+        }
+        if (track->cenc.constant_iv) {
+            avio_w8(pb, 0);
+        } else {
+            avio_w8(pb, CBCS_IV_SIZE); /* iv size */    
+        }
+            
+    }
     avio_write(pb, kid, CENC_KID_SIZE);
 
+    if (track->cenc.constant_iv) {
+        avio_w8(pb, CBCS_IV_SIZE); /* constant iv size */  
+        avio_write(pb, track->cenc.iv, CBCS_IV_SIZE);
+    }
+
     return update_size(pb, pos);
 }
 
@@ -376,42 +609,90 @@ int ff_mov_cenc_write_sinf_tag(MOVTrack* track, AVIOContext *pb, uint8_t* kid)
     avio_wb32(pb, 20);    /* size */
     ffio_wfourcc(pb, "schm");
     avio_wb32(pb, 0); /* version & flags */
-    ffio_wfourcc(pb, "cenc");    /* scheme type*/
-    avio_wb32(pb, 0x10000); /* scheme version */
-
-    /* schi */
-    mov_cenc_write_schi_tag(pb, kid);
+    if (track->cenc.aes_ctr) {
+        ffio_wfourcc(pb, "cenc");    /* scheme type*/
+        avio_wb32(pb, 0x10000); /* scheme version */
+        /* schi */
+        mov_cenc_write_schi_tag(track, pb, kid, AES_CTR_IV_SIZE);
+    } else if (track->cenc.aes_cbc) {
+        ffio_wfourcc(pb, "cbcs");    /* scheme type*/
+        avio_wb32(pb, 0x10000); /* scheme version */
+        /* schi */
+        mov_cenc_write_schi_tag(track, pb, kid, CBCS_IV_SIZE);
+    }
 
     return update_size(pb, pos);
 }
 
-int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key,
-                     int use_subsamples, int bitexact)
+int ff_mov_cenc_init(AVFormatContext *s, MOVMuxCencContext* ctx, char* encryption_scheme, uint8_t* encryption_key,
+                     uint8_t* encryption_iv, int use_subsamples, int bitexact)
 {
     int ret;
 
-    ctx->aes_ctr = av_aes_ctr_alloc();
-    if (!ctx->aes_ctr) {
-        return AVERROR(ENOMEM);
-    }
+    if (strcmp(encryption_scheme, "cenc-aes-ctr") == 0) {
+        ctx->aes_ctr = av_aes_ctr_alloc();
+        if (!ctx->aes_ctr) {
+            return AVERROR(ENOMEM);
+        }
 
-    ret = av_aes_ctr_init(ctx->aes_ctr, encryption_key);
-    if (ret != 0) {
-        return ret;
-    }
+        ret = av_aes_ctr_init(ctx->aes_ctr, encryption_key);
+        if (ret != 0) {
+            return ret;
+        }
 
-    if (!bitexact) {
-        av_aes_ctr_set_random_iv(ctx->aes_ctr);
-    }
+        if (!bitexact) {
+            av_aes_ctr_set_random_iv(ctx->aes_ctr);
+        }
+        ctx->iv = av_aes_ctr_get_iv(ctx->aes_ctr);
+        ctx->iv_size = AES_CTR_IV_SIZE;
+        ctx->use_subsamples = use_subsamples;
+
+    } else if (strcmp(encryption_scheme, "cenc-aes-cbc") == 0) {
+
+        ctx->aes_cbc = av_aes_alloc();
+        if (!ctx->aes_cbc) {
+            return AVERROR(ENOMEM);
+        }
+
+        ret = av_aes_init(ctx->aes_cbc, encryption_key, 128, 0);
+        if (ret != 0) {
+            return ret;
+        }
 
-    ctx->use_subsamples = use_subsamples;
+        ctx->iv_size = CBCS_IV_SIZE;
+        ctx->use_subsamples = 1;
+
+        if (encryption_iv) {
+            ctx->iv = av_malloc(ctx->iv_size);
+            ctx->constant_iv = 1;
+            memcpy(ctx->iv, encryption_iv, ctx->iv_size);
+        } else if (!bitexact) {
+            ctx->iv = av_malloc(ctx->iv_size);
+            uint32_t iv[2];
+            iv[0] = av_get_random_seed();
+            iv[1] = av_get_random_seed();
+            memcpy(ctx->iv, iv, ctx->iv_size);
+        } else {
+            ctx->iv = av_mallocz(ctx->iv_size);
+        }
+    }
 
     return 0;
 }
 
 void ff_mov_cenc_free(MOVMuxCencContext* ctx)
 {
-    av_aes_ctr_free(ctx->aes_ctr);
+    if (ctx->aes_ctr) {
+        av_aes_ctr_free(ctx->aes_ctr);
+    }
     av_freep(&ctx->auxiliary_info);
     av_freep(&ctx->auxiliary_info_sizes);
+    if (ctx->aes_cbc) {
+        av_freep(&ctx->aes_cbc);
+        av_freep(&ctx->iv);
+    }
+    ff_h264_ps_uninit(&ctx->h264_ps);
+    ff_hevc_ps_uninit(&ctx->hevc_ps);
+    ff_hevc_reset_sei(&ctx->hevc_sei);
+
 }
diff --git a/libavformat/movenccenc.h b/libavformat/movenccenc.h
index 6f9e70e905..568554925f 100644
--- a/libavformat/movenccenc.h
+++ b/libavformat/movenccenc.h
@@ -1,7 +1,7 @@
 /*
- * MOV CENC (Common Encryption) writer
+ * MOV CENC/CBCS (Common Encryption) writer
  * Copyright (c) 2015 Eran Kornblau <erankor at gmail dot com>
- *
+ * Copyright (c) 2026 Olivier Ayache <olivier dot ayache at gmail dot com>
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -22,16 +22,31 @@
 #ifndef AVFORMAT_MOVENCCENC_H
 #define AVFORMAT_MOVENCCENC_H
 
+#include "libavcodec/h264dec.h"
+#include "libavcodec/h2645_parse.h"
+#include "libavcodec/h264_parse.h"
+#include "libavcodec/hevc_parse.h"
+#include "libavutil/aes.h"
 #include "libavutil/aes_ctr.h"
 #include "avformat.h"
 #include "avio.h"
 
 #define CENC_KID_SIZE (16)
 
+#define CBCS_IV_SIZE (16)
+#define CBCS_AUDIO_SKIP (0)
+#define CBCS_AUDIO_ENCRYPTED (16)
+#define CBCS_VIDEO_SKIP (144)
+#define CBCS_VIDEO_ENCRYPTED (16)
+
 struct MOVTrack;
 
 typedef struct {
     struct AVAESCTR* aes_ctr;
+    struct AVAES* aes_cbc;
+    const uint8_t* iv;
+    int iv_size;
+    int constant_iv;
     uint8_t* auxiliary_info;
     size_t auxiliary_info_size;
     size_t auxiliary_info_alloc_size;
@@ -43,14 +58,28 @@ typedef struct {
     size_t auxiliary_info_subsample_start;
     uint8_t* auxiliary_info_sizes;
     size_t  auxiliary_info_sizes_alloc_size;
+
+    enum AVMediaType codec_type;
+    enum AVCodecID codec_id;
+
+    int is_nalff;
+    int nal_length_size;
+
+    H264ParamSets h264_ps;
+
+    HEVCParamSets hevc_ps;
+    HEVCSEI hevc_sei;
 } MOVMuxCencContext;
 
 /**
  * Initialize a CENC context
+ * @param encryption_scheme encryption scheme (can be cenc-aes-ctr or cenc-aes-cbc)
  * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
  * @param use_subsamples when enabled parts of a packet can be encrypted, otherwise the whole packet is encrypted
  */
-int ff_mov_cenc_init(MOVMuxCencContext* ctx, uint8_t* encryption_key, int use_subsamples, int bitexact);
+int ff_mov_cenc_init(AVFormatContext* s, MOVMuxCencContext* ctx, char* encryption_scheme, uint8_t* encryption_key, uint8_t* encryption_iv, int use_subsamples, int bitexact);
+
+int ff_mov_cbcs_set_extradata(AVFormatContext* s, MOVMuxCencContext* ctx, enum AVMediaType codec_type, enum AVCodecID codec_id, const uint8_t *extradata, int size);
 
 /**
  * Free a CENC context
@@ -65,7 +94,7 @@ int ff_mov_cenc_write_packet(MOVMuxCencContext* ctx, AVIOContext *pb, const uint
 /**
  * Parse AVC NAL units from annex B format, the nal size and type are written in the clear while the body is encrypted
  */
-int ff_mov_cenc_avc_parse_nal_units(MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size);
+int ff_mov_cenc_avc_parse_nal_units(AVFormatContext* s, MOVMuxCencContext* ctx, AVIOContext *pb, const uint8_t *buf_in, int size);
 
 /**
  * Write AVC NAL units that are in MP4 format, the nal size and type are written in the clear while the body is encrypted 
