PR #25944 opened by sasha
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25944
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25944.patch

# Summary of changes

This PR adds remuxing of ac4 from `mpegts, mp4 and .ac4` to `mpegts, mp4 and 
.ac4`

```fate-samples
ac4/zAdN.ac4
ac4/zAdN.ts
ac4/zAdq.mp4
```
```




>From 732a317a1eb7730ffd61105c43a89970bee7dd0a Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:07:13 +0100
Subject: [PATCH 01/10] avformat/ac4: add shared TOC and syncframe helpers

Add helpers to parse the AC-4 TOC and to strip the AC-4 syncframe
header and optional CRC. These will be shared by the raw AC-4 and
MPEG-TS demuxers and the MP4, MPEG-TS and raw AC-4 muxers.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavformat/Makefile |  10 ++---
 libavformat/ac4.c    | 104 +++++++++++++++++++++++++++++++++++++++++++
 libavformat/ac4.h    |  56 +++++++++++++++++++++++
 3 files changed, 165 insertions(+), 5 deletions(-)
 create mode 100644 libavformat/ac4.c
 create mode 100644 libavformat/ac4.h

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 17da02eee7f..4c80469f7b6 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -92,8 +92,8 @@ OBJS-$(CONFIG_AAC_DEMUXER)               += aacdec.o apetag.o 
img2.o rawdec.o
 OBJS-$(CONFIG_AAX_DEMUXER)               += aaxdec.o
 OBJS-$(CONFIG_AC3_DEMUXER)               += ac3dec.o rawdec.o
 OBJS-$(CONFIG_AC3_MUXER)                 += rawenc.o
-OBJS-$(CONFIG_AC4_DEMUXER)               += ac4dec.o
-OBJS-$(CONFIG_AC4_MUXER)                 += ac4enc.o
+OBJS-$(CONFIG_AC4_DEMUXER)               += ac4.o ac4dec.o
+OBJS-$(CONFIG_AC4_MUXER)                 += ac4.o ac4enc.o
 OBJS-$(CONFIG_ACE_DEMUXER)               += acedec.o
 OBJS-$(CONFIG_ACM_DEMUXER)               += acm.o rawdec.o
 OBJS-$(CONFIG_ACT_DEMUXER)               += act.o
@@ -398,7 +398,7 @@ OBJS-$(CONFIG_MOFLEX_DEMUXER)            += moflex.o
 OBJS-$(CONFIG_MOV_DEMUXER)               += mov.o mov_chan.o mov_esds.o \
                                             qtpalette.o replaygain.o 
dovi_isom.o \
                                             dvdclut.o
-OBJS-$(CONFIG_MOV_MUXER)                 += movenc.o \
+OBJS-$(CONFIG_MOV_MUXER)                 += movenc.o ac4.o \
                                             movenchint.o mov_chan.o rtp.o \
                                             movenccenc.o movenc_ttml.o 
rawutils.o \
                                             apv.o dovi_isom.o evc.o
@@ -415,8 +415,8 @@ OBJS-$(CONFIG_MPEG2SVCD_MUXER)           += mpegenc.o
 OBJS-$(CONFIG_MPEG2VIDEO_MUXER)          += rawenc.o
 OBJS-$(CONFIG_MPEG2VOB_MUXER)            += mpegenc.o
 OBJS-$(CONFIG_MPEGPS_DEMUXER)            += mpeg.o
-OBJS-$(CONFIG_MPEGTS_DEMUXER)            += mpegts.o
-OBJS-$(CONFIG_MPEGTS_MUXER)              += mpegtsenc.o
+OBJS-$(CONFIG_MPEGTS_DEMUXER)            += ac4.o mpegts.o
+OBJS-$(CONFIG_MPEGTS_MUXER)              += ac4.o mpegtsenc.o
 OBJS-$(CONFIG_MPEGVIDEO_DEMUXER)         += mpegvideodec.o rawdec.o
 OBJS-$(CONFIG_MPJPEG_DEMUXER)            += mpjpegdec.o
 OBJS-$(CONFIG_MPJPEG_MUXER)              += mpjpeg.o
diff --git a/libavformat/ac4.c b/libavformat/ac4.c
new file mode 100644
index 00000000000..5d66291770d
--- /dev/null
+++ b/libavformat/ac4.c
@@ -0,0 +1,104 @@
+/*
+ * AC-4 helpers
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/get_bits.h"
+#include "libavutil/error.h"
+#include "libavutil/intreadwrite.h"
+
+#include "ac4.h"
+
+int ff_ac4_strip_syncframe(const uint8_t *data, int size,
+                           const uint8_t **payload, int *payload_size)
+{
+    int crc_size, hdr_size, len;
+
+    if (size < 4 || data[0] != 0xAC ||
+        (data[1] != 0x40 && data[1] != 0x41))
+        return AVERROR_INVALIDDATA;
+
+    len = AV_RB16(data + 2);
+    hdr_size = 4;
+    if (len == 0xFFFF) {
+        if (size < 7)
+            return AVERROR_INVALIDDATA;
+        len = AV_RB24(data + 4);
+        hdr_size = 7;
+    }
+
+    crc_size = data[1] == 0x41 ? 2 : 0;
+    if (len > size - hdr_size - crc_size)
+        return AVERROR_INVALIDDATA;
+    if (hdr_size + len + crc_size != size)
+        return AVERROR_INVALIDDATA;
+
+    *payload      = data + hdr_size;
+    *payload_size = len;
+
+    return 0;
+}
+
+int ff_ac4_parse_toc(const uint8_t *data, int size, FFAC4Toc *toc)
+{
+    GetBitContext gb;
+    int bitstream_version, more, wait_frames;
+
+    if (size < 4)
+        return AVERROR_INVALIDDATA;
+
+    if (init_get_bits8(&gb, data, size) < 0)
+        return AVERROR_INVALIDDATA;
+
+    bitstream_version = get_bits(&gb, 2);
+    if (bitstream_version == 3) {
+        do {
+            if (get_bits_left(&gb) < 3)
+                return AVERROR_INVALIDDATA;
+            skip_bits(&gb, 2);
+            more = get_bits1(&gb);
+        } while (more);
+    }
+
+    if (get_bits_left(&gb) < 10)
+        return AVERROR_INVALIDDATA;
+    skip_bits(&gb, 10); /* sequence_counter */
+
+    if (get_bits_left(&gb) < 1)
+        return AVERROR_INVALIDDATA;
+    if (get_bits1(&gb)) {
+        if (get_bits_left(&gb) < 3)
+            return AVERROR_INVALIDDATA;
+        wait_frames = get_bits(&gb, 3);
+        if (wait_frames) {
+            if (get_bits_left(&gb) < 2)
+                return AVERROR_INVALIDDATA;
+            skip_bits(&gb, 2); /* br_code */
+        }
+    }
+
+    if (get_bits_left(&gb) < 5)
+        return AVERROR_INVALIDDATA;
+
+    toc->bitstream_version = bitstream_version;
+    toc->fs_index          = get_bits1(&gb);
+    toc->frame_rate_index  = get_bits(&gb, 4);
+    toc->sample_rate       = toc->fs_index ? 48000 : 44100;
+
+    return 0;
+}
diff --git a/libavformat/ac4.h b/libavformat/ac4.h
new file mode 100644
index 00000000000..87a4f652ae9
--- /dev/null
+++ b/libavformat/ac4.h
@@ -0,0 +1,56 @@
+/*
+ * AC-4 helpers
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_AC4_H
+#define AVFORMAT_AC4_H
+
+#include <stdint.h>
+
+typedef struct FFAC4Toc {
+    int bitstream_version;  ///< AC-4 bitstream version
+    int fs_index;           ///< sample rate index
+    int frame_rate_index;   ///< frame rate index
+    int sample_rate;        ///< sample rate in Hz
+} FFAC4Toc;
+
+/**
+ * Parse the AC-4 TOC from a raw AC-4 frame.
+ *
+ * @param data raw AC-4 frame payload without a syncframe header
+ * @param size payload size
+ * @param toc parsed TOC fields
+ * @return 0 on success, a negative AVERROR on failure
+ */
+int ff_ac4_parse_toc(const uint8_t *data, int size, FFAC4Toc *toc);
+
+/**
+ * Strip the AC-4 syncframe header and optional CRC.
+ *
+ * @param data AC-4 syncframe
+ * @param size syncframe size
+ * @param payload output payload pointer
+ * @param payload_size output payload size
+ * @return 0 on success, a negative AVERROR if the input is not a single
+ *         complete AC-4 syncframe
+ */
+int ff_ac4_strip_syncframe(const uint8_t *data, int size,
+                           const uint8_t **payload, int *payload_size);
+
+#endif /* AVFORMAT_AC4_H */
-- 
2.54.0


>From 7fcc71792fc0769476ecdacbcd352ee873ef609d Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:07:18 +0100
Subject: [PATCH 02/10] avformat/ac4dec: set sample rate from the AC-4 TOC

Parse the TOC of the first raw AC-4 frame and export its sample rate
through the stream codec parameters. This is required for muxers that
need a sample rate before writing the output header.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavformat/ac4dec.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
index dc6638de3a4..19ff6ceb789 100644
--- a/libavformat/ac4dec.c
+++ b/libavformat/ac4dec.c
@@ -23,8 +23,11 @@
 #include "libavutil/crc.h"
 #include "avformat.h"
 #include "demux.h"
+#include "internal.h"
 #include "rawdec.h"
 
+#include "ac4.h"
+
 static int ac4_probe(const AVProbeData *p)
 {
     const uint8_t *buf = p->buf;
@@ -93,6 +96,15 @@ static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (sync == 0xAC41)
         avio_skip(pb, 2);
 
+    if (ret >= 0 && !s->streams[0]->codecpar->sample_rate) {
+        FFAC4Toc toc;
+
+        if (ff_ac4_parse_toc(pkt->data, pkt->size, &toc) >= 0) {
+            s->streams[0]->codecpar->sample_rate = toc.sample_rate;
+            ffstream(s->streams[0])->need_context_update = 1;
+        }
+    }
+
     return ret;
 }
 
-- 
2.54.0


>From ac36d70cac447b823156a8400d902292fbd75bb9 Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:07:23 +0100
Subject: [PATCH 03/10] avformat/mpegts: set AC-4 sample rate from the TOC

MPEG-TS carries AC-4 in syncframed form. Parse the TOC of the first
AC-4 PES and update the stream sample rate so that the stream can be
remuxed into containers that need it before writing the header.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavformat/mpegts.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index ae4d177083c..29484c7059c 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -39,6 +39,8 @@
 #include "avformat.h"
 #include "mpegts.h"
 #include "internal.h"
+
+#include "ac4.h"
 #include "avio_internal.h"
 #include "demux.h"
 #include "mpeg.h"
@@ -1102,6 +1104,23 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt)
 
     memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
+    if (pes->st->codecpar->codec_id == AV_CODEC_ID_AC4 &&
+        !pes->st->codecpar->sample_rate) {
+        const uint8_t *payload = pkt->data;
+        int payload_size = pkt->size;
+        FFAC4Toc toc;
+
+        if (ff_ac4_strip_syncframe(pkt->data, pkt->size,
+                                   &payload, &payload_size) < 0) {
+            payload      = pkt->data;
+            payload_size = pkt->size;
+        }
+        if (ff_ac4_parse_toc(payload, payload_size, &toc) >= 0) {
+            pes->st->codecpar->sample_rate = toc.sample_rate;
+            ffstream(pes->st)->need_context_update = 1;
+        }
+    }
+
     // Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID
     if (pes->sub_st && pes->stream_type == STREAM_TYPE_BLURAY_AUDIO_TRUEHD && 
pes->extended_stream_id == 0x76)
         pkt->stream_index = pes->sub_st->index;
-- 
2.54.0


>From 82199da73216a2b2bdb51019a61565712a2191cc Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:07:28 +0100
Subject: [PATCH 04/10] avformat/ac4enc: pass through syncframed AC-4 packets

When remuxing from a container that stores AC-4 with its syncframe
header, the raw AC-4 muxer used to add another syncframe. Detect a
complete input syncframe and write it unchanged instead.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavformat/ac4enc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libavformat/ac4enc.c b/libavformat/ac4enc.c
index 0505b051474..1a94db2d884 100644
--- a/libavformat/ac4enc.c
+++ b/libavformat/ac4enc.c
@@ -22,6 +22,8 @@
 #include "libavcodec/packet.h"
 #include "libavutil/crc.h"
 #include "libavutil/opt.h"
+
+#include "ac4.h"
 #include "avformat.h"
 #include "mux.h"
 
@@ -34,10 +36,17 @@ static int ac4_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 {
     AC4Context *ac4 = s->priv_data;
     AVIOContext *pb = s->pb;
+    const uint8_t *payload;
+    int payload_size;
 
     if (!pkt->size)
         return 0;
 
+    if (ff_ac4_strip_syncframe(pkt->data, pkt->size, &payload, &payload_size) 
>= 0) {
+        avio_write(pb, pkt->data, pkt->size);
+        return 0;
+    }
+
     if (ac4->write_crc)
         avio_wb16(pb, 0xAC41);
     else
-- 
2.54.0


>From 1134baa55b651e99bde76d929bd24c016e078ac2 Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:07:53 +0100
Subject: [PATCH 05/10] avformat/movenc: add AC-4 muxing support

Add the MP4 codec tag and write the dac4 box from the AC-4 TOC.
Strip the syncframe header and optional CRC from input packets before
writing them to the sample data.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavformat/movenc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
 libavformat/movenc.h |  5 ++++
 2 files changed, 60 insertions(+)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index ea71acde42a..f9ca4af9265 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -28,6 +28,7 @@
 #include <inttypes.h>
 
 #include "movenc.h"
+#include "ac4.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "dovi_isom.h"
@@ -1447,6 +1448,26 @@ static int mov_write_srat_tag(AVIOContext *pb, MOVTrack 
*track)
     return update_size(pb, pos);
 }
 
+static int mov_write_dac4_tag(AVIOContext *pb, MOVTrack *track)
+{
+    int64_t pos = avio_tell(pb);
+    int bitstream_version = track->ac4_dsi_valid ? 
track->ac4_bitstream_version : 2;
+    int fs_index = track->ac4_dsi_valid ? track->ac4_fs_index :
+                   track->par->sample_rate == 44100 ? 0 : 1;
+    int frame_rate_index = track->ac4_dsi_valid ? track->ac4_frame_rate_index 
: 0;
+    uint32_t val = (1 << 21) |
+                   ((bitstream_version & 0x7F) << 14) |
+                   ((fs_index & 1) << 13) |
+                   ((frame_rate_index & 0xF) << 9);
+
+    avio_wb32(pb, 0); /* size */
+    ffio_wfourcc(pb, "dac4");
+    avio_w8(pb, val >> 16);
+    avio_w8(pb, val >> 8);
+    avio_w8(pb, val);
+    return update_size(pb, pos);
+}
+
 static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, 
MOVMuxContext *mov, MOVTrack *track)
 {
     int64_t pos = avio_tell(pb);
@@ -1580,6 +1601,8 @@ static int mov_write_audio_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
         ret = mov_write_ac3_tag(s, pb, track);
     else if (track->par->codec_id == AV_CODEC_ID_EAC3)
         ret = mov_write_eac3_tag(s, pb, track);
+    else if (track->par->codec_id == AV_CODEC_ID_AC4)
+        ret = mov_write_dac4_tag(pb, track);
     else if (track->par->codec_id == AV_CODEC_ID_ALAC)
         ret = mov_write_extradata_tag(pb, track);
     else if (track->par->codec_id == AV_CODEC_ID_WMAPRO)
@@ -7127,6 +7150,19 @@ int ff_mov_set_fragment_end_hint(AVFormatContext *s, int 
stream_index,
     return 1;
 }
 
+static void mov_parse_ac4_toc(MOVTrack *track, const uint8_t *data, int size)
+{
+    FFAC4Toc toc;
+
+    if (track->ac4_dsi_valid || ff_ac4_parse_toc(data, size, &toc) < 0)
+        return;
+
+    track->ac4_bitstream_version = toc.bitstream_version;
+    track->ac4_fs_index = toc.fs_index;
+    track->ac4_frame_rate_index = toc.frame_rate_index;
+    track->ac4_dsi_valid = 1;
+}
+
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     MOVMuxContext *mov = s->priv_data;
@@ -7369,6 +7405,24 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket 
*pkt)
             }
         }
 
+    } else if (par->codec_id == AV_CODEC_ID_AC4) {
+        const uint8_t *payload = pkt->data;
+        int payload_size = pkt->size;
+
+        if (ff_ac4_strip_syncframe(pkt->data, pkt->size,
+                                   &payload, &payload_size) < 0) {
+            payload      = pkt->data;
+            payload_size = pkt->size;
+        }
+        mov_parse_ac4_toc(trk, payload, payload_size);
+        if (trk->cenc.aes_ctr) {
+            ret = ff_mov_cenc_write_packet(&trk->cenc, pb, payload, 
payload_size);
+            if (ret < 0)
+                goto err;
+        } else {
+            avio_write(pb, payload, payload_size);
+        }
+        size = payload_size;
     } else if (par->codec_id == AV_CODEC_ID_AC3 ||
                par->codec_id == AV_CODEC_ID_EAC3) {
         size = handle_eac3(mov, pkt, trk);
@@ -9500,6 +9554,7 @@ static const AVCodecTag codec_mp4_tags[] = {
     { AV_CODEC_ID_MP2,             MKTAG('m', 'p', '4', 'a') },
     { AV_CODEC_ID_AC3,             MKTAG('a', 'c', '-', '3') },
     { AV_CODEC_ID_EAC3,            MKTAG('e', 'c', '-', '3') },
+    { AV_CODEC_ID_AC4,             MKTAG('a', 'c', '-', '4') },
     { AV_CODEC_ID_DTS,             MKTAG('m', 'p', '4', 'a') },
     { AV_CODEC_ID_TRUEHD,          MKTAG('m', 'l', 'p', 'a') },
     { AV_CODEC_ID_FLAC,            MKTAG('f', 'L', 'a', 'C') },
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index c375659c93e..7146f1882d9 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -177,6 +177,11 @@ typedef struct MOVTrack {
 
     void       *eac3_priv;
 
+    int         ac4_dsi_valid;
+    int         ac4_bitstream_version;
+    int         ac4_fs_index;
+    int         ac4_frame_rate_index;
+
     MOVMuxCencContext cenc;
 
     uint32_t palette[AVPALETTE_COUNT];
-- 
2.54.0


>From 0f0a53e6de1d80c60542915e5fa8b993c4dd66fe Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:08:13 +0100
Subject: [PATCH 06/10] avformat/mpegtsenc: add AC-4 muxing support

Signal AC-4 with the registration descriptor and the DVB AC-4
descriptor, wrap raw packets in an AC-4 syncframe, and keep every
AC-4 frame in its own PES packet. Existing syncframed packets are
written unchanged.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavformat/mpegtsenc.c | 45 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 6682abfac4d..f5451fa6e0e 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -37,6 +37,8 @@
 #include "libavcodec/startcode.h"
 
 #include "avformat.h"
+
+#include "ac4.h"
 #include "avio_internal.h"
 #include "internal.h"
 #include "lcevc.h"
@@ -434,6 +436,7 @@ static int get_dvb_stream_type(AVFormatContext *s, AVStream 
*st)
     case AV_CODEC_ID_TRUEHD:
         stream_type = STREAM_TYPE_BLURAY_AUDIO_TRUEHD; // should be 
STREAM_TYPE_PRIVATE_DATA (ETSI TS 101 154), needs a DTS-HD_descriptor() (ETSI 
EN 300 468)
         break;
+    case AV_CODEC_ID_AC4:
     case AV_CODEC_ID_OPUS:
         stream_type = STREAM_TYPE_PRIVATE_DATA;
         break;
@@ -590,6 +593,13 @@ static int mpegts_write_pmt(AVFormatContext *s, 
MpegTSService *service)
                 put_registration_descriptor(&q, MKTAG('A', 'C', '-', '3'));
             if (codec_id == AV_CODEC_ID_EAC3)
                 put_registration_descriptor(&q, MKTAG('E', 'A', 'C', '3'));
+            if (codec_id == AV_CODEC_ID_AC4) {
+                put_registration_descriptor(&q, MKTAG('A', 'C', '-', '4'));
+                *q++ = DVB_EXTENSION_DESCRIPTOR;
+                *q++ = 2;
+                *q++ = AC4_DESCRIPTOR;
+                *q++ = 0; /* no config/TOC */
+            }
             if (ts->flags & MPEGTS_FLAG_SYSTEM_B) {
                 if (codec_id == AV_CODEC_ID_AC3) {
                     DVBAC3Descriptor *dvb_ac3_desc = ts_st->dvb_ac3_desc;
@@ -2273,6 +2283,36 @@ static int mpegts_write_packet_internal(AVFormatContext 
*s, AVPacket *pkt)
              * need to count the samples of that too! */
             av_log(s, AV_LOG_WARNING, "Got MPEG-TS formatted Opus data, 
unhandled");
         }
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_AC4) {
+        const uint8_t *payload;
+        int payload_size;
+
+        if (ff_ac4_strip_syncframe(pkt->data, pkt->size,
+                                   &payload, &payload_size) < 0) {
+            const int hdr_size = size >= 0xFFFF ? 7 : 4;
+            uint8_t *p;
+
+            if (size > 0xFFFFFF)
+                return AVERROR_INVALIDDATA;
+
+            data = av_malloc(size + hdr_size);
+            if (!data)
+                return AVERROR(ENOMEM);
+
+            p = data;
+            AV_WB16(p, 0xAC40);
+            if (hdr_size == 7) {
+                AV_WB16(p + 2, 0xFFFF);
+                p[4] = size >> 16;
+                p[5] = size >> 8;
+                p[6] = size;
+            } else {
+                AV_WB16(p + 2, size);
+            }
+            memcpy(p + hdr_size, buf, size);
+            buf  = data;
+            size += hdr_size;
+        }
     } else if (st->codecpar->codec_id == AV_CODEC_ID_AC3 && 
!ts_st->dvb_ac3_desc) {
         AC3HeaderInfo *hdr = NULL;
 
@@ -2347,9 +2387,10 @@ static int mpegts_write_packet_internal(AVFormatContext 
*s, AVPacket *pkt)
         ts_st->opus_queued_samples = 0;
     }
 
-    if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || size > 
ts->pes_payload_size) {
+    if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || size > 
ts->pes_payload_size ||
+        st->codecpar->codec_id == AV_CODEC_ID_AC4) {
         av_assert0(!ts_st->payload_size);
-        // for video and subtitle, write a single pes packet
+        // for video, subtitle and AC-4, write a single pes packet
         mpegts_write_pes(s, st, buf, size, pts, dts,
                          pkt->flags & AV_PKT_FLAG_KEY, stream_id);
         ts_st->opus_queued_samples = 0;
-- 
2.54.0


>From 39667f971dc59c4b8ef807b29483cfbe8224f18c Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 12:08:19 +0100
Subject: [PATCH 07/10] avcodec/codec_desc: mark AC-4 as intra-only

AC-4 frames are independently decodable. Mark the codec accordingly so
that muxers and demuxers can treat it as an intra-only codec.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 libavcodec/codec_desc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index dd63c2194df..320f625d011 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3567,7 +3567,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .type      = AVMEDIA_TYPE_AUDIO,
         .name      = "ac4",
         .long_name = NULL_IF_CONFIG_SMALL("AC-4"),
-        .props     = AV_CODEC_PROP_LOSSY,
+        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
     },
     {
         .id        = AV_CODEC_ID_OSQ,
-- 
2.54.0


>From 8bf4a0f7fe14a46815bd1dc481c0902f6d64a458 Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 14:55:49 +0100
Subject: [PATCH 08/10] tests/fate: add AC-4 muxing tests

Add tests for MP4 and MPEG-TS muxing and remuxing of AC-4.

Use zAdN.ac4, zAdN.ts and zAdq.mp4 from
https://streams.videolan.org/samples/A-codecs/AC4/.
zAdN.ac4 is trimmed to 25 frames, zAdN.ts is generated from it,
and zAdq.mp4 is trimmed to one second.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 tests/Makefile              |  1 +
 tests/fate/ac4.mak          | 35 +++++++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-mp4      | 31 +++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-mp4-copy | 37 +++++++++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-mp4-frag | 32 ++++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-mp4-ts   | 37 +++++++++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-ts       | 32 ++++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-ts-copy  | 32 ++++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-ts-mp4   | 31 +++++++++++++++++++++++++++++++
 tests/ref/fate/ac4-ts-raw   | 32 ++++++++++++++++++++++++++++++++
 10 files changed, 300 insertions(+)
 create mode 100644 tests/fate/ac4.mak
 create mode 100644 tests/ref/fate/ac4-mp4
 create mode 100644 tests/ref/fate/ac4-mp4-copy
 create mode 100644 tests/ref/fate/ac4-mp4-frag
 create mode 100644 tests/ref/fate/ac4-mp4-ts
 create mode 100644 tests/ref/fate/ac4-ts
 create mode 100644 tests/ref/fate/ac4-ts-copy
 create mode 100644 tests/ref/fate/ac4-ts-mp4
 create mode 100644 tests/ref/fate/ac4-ts-raw

diff --git a/tests/Makefile b/tests/Makefile
index 365c6e7c194..3268f8675ce 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -166,6 +166,7 @@ include $(SRC_PATH)/tests/fate/seek.mak
 
 include $(SRC_PATH)/tests/fate/aac.mak
 include $(SRC_PATH)/tests/fate/ac3.mak
+include $(SRC_PATH)/tests/fate/ac4.mak
 include $(SRC_PATH)/tests/fate/adpcm.mak
 include $(SRC_PATH)/tests/fate/alac.mak
 include $(SRC_PATH)/tests/fate/als.mak
diff --git a/tests/fate/ac4.mak b/tests/fate/ac4.mak
new file mode 100644
index 00000000000..246f8f134ad
--- /dev/null
+++ b/tests/fate/ac4.mak
@@ -0,0 +1,35 @@
+FATE_AC4_SAMPLES-$(call ALLYES, AC4_DEMUXER MP4_MUXER MOV_DEMUXER 
FILE_PROTOCOL PIPE_PROTOCOL) += fate-ac4-mp4
+fate-ac4-mp4: CMD = stream_remux ac4 $(TARGET_SAMPLES)/ac4/zAdN.ac4 "" mp4 \
+    "-map 0" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, AC4_DEMUXER MP4_MUXER MOV_DEMUXER 
FILE_PROTOCOL PIPE_PROTOCOL) += fate-ac4-mp4-frag
+fate-ac4-mp4-frag: CMD = stream_remux ac4 $(TARGET_SAMPLES)/ac4/zAdN.ac4 "" 
mp4 \
+    "-map 0 -movflags +frag_keyframe+empty_moov" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, MOV_DEMUXER MP4_MUXER FILE_PROTOCOL 
PIPE_PROTOCOL) += fate-ac4-mp4-copy
+fate-ac4-mp4-copy: CMD = stream_remux mp4 $(TARGET_SAMPLES)/ac4/zAdq.mp4 "" 
mp4 \
+    "-map 0" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, MOV_DEMUXER MPEGTS_MUXER MPEGTS_DEMUXER 
FILE_PROTOCOL PIPE_PROTOCOL) += fate-ac4-mp4-ts
+fate-ac4-mp4-ts: CMD = stream_remux mp4 $(TARGET_SAMPLES)/ac4/zAdq.mp4 "" 
mpegts \
+    "-map 0" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, AC4_DEMUXER MPEGTS_MUXER MPEGTS_DEMUXER 
FILE_PROTOCOL PIPE_PROTOCOL) += fate-ac4-ts
+fate-ac4-ts: CMD = stream_remux ac4 $(TARGET_SAMPLES)/ac4/zAdN.ac4 "" mpegts \
+    "-map 0" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, MPEGTS_DEMUXER MP4_MUXER MOV_DEMUXER 
FILE_PROTOCOL PIPE_PROTOCOL) += fate-ac4-ts-mp4
+fate-ac4-ts-mp4: CMD = stream_remux mpegts $(TARGET_SAMPLES)/ac4/zAdN.ts "" 
mp4 \
+    "-map 0" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, MPEGTS_DEMUXER MPEGTS_MUXER FILE_PROTOCOL 
PIPE_PROTOCOL) += fate-ac4-ts-copy
+fate-ac4-ts-copy: CMD = stream_remux mpegts $(TARGET_SAMPLES)/ac4/zAdN.ts "" 
mpegts \
+    "-map 0" "" "-c:a copy"
+
+FATE_AC4_SAMPLES-$(call ALLYES, MPEGTS_DEMUXER AC4_MUXER FILE_PROTOCOL 
PIPE_PROTOCOL) += fate-ac4-ts-raw
+fate-ac4-ts-raw: CMD = stream_remux mpegts $(TARGET_SAMPLES)/ac4/zAdN.ts "" 
ac4 \
+    "-map 0" "" "-c:a copy"
+
+FATE_SAMPLES_FFMPEG += $(FATE_AC4_SAMPLES-yes)
+
+fate-ac4: $(FATE_AC4_SAMPLES-yes)
diff --git a/tests/ref/fate/ac4-mp4 b/tests/ref/fate/ac4-mp4
new file mode 100644
index 00000000000..32629105189
--- /dev/null
+++ b/tests/ref/fate/ac4-mp4
@@ -0,0 +1,31 @@
+d0e187aa7f6b47c58c6e4d2ba3f856bb *tests/data/fate/ac4-mp4.mp4
+8395 tests/data/fate/ac4-mp4.mp4
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        1,      251, 0xb0b17ced
+0,          1,          1,        1,      262, 0x42cf80af
+0,          2,          2,        1,      278, 0x489885a0
+0,          3,          3,        1,      298, 0x75008149
+0,          4,          4,        1,      372, 0xe637bab0
+0,          5,          5,        1,      303, 0x75ef8feb
+0,          6,          6,        1,      310, 0x66f5914a
+0,          7,          7,        1,      312, 0xf6788930
+0,          8,          8,        1,      283, 0x261486a4
+0,          9,          9,        1,      363, 0xa9fda9d5
+0,         10,         10,        1,      317, 0xf7069a4f
+0,         11,         11,        1,      292, 0x06468cc7
+0,         12,         12,        1,      290, 0x84a48b49
+0,         13,         13,        1,      302, 0xf7ec8805
+0,         14,         14,        1,      300, 0x66a89591
+0,         15,         15,        1,      346, 0xf8009d1a
+0,         16,         16,        1,      291, 0xd0b98977
+0,         17,         17,        1,      354, 0xff67ae48
+0,         18,         18,        1,      283, 0xc9b58636
+0,         19,         19,        1,      309, 0x84658ce1
+0,         20,         20,        1,      356, 0x98dda801
+0,         21,         21,        1,      270, 0x595e8ae7
+0,         22,         22,        1,      275, 0x10598c0f
+0,         23,         23,        1,      295, 0xc8d38f8c
diff --git a/tests/ref/fate/ac4-mp4-copy b/tests/ref/fate/ac4-mp4-copy
new file mode 100644
index 00000000000..92878d73ebb
--- /dev/null
+++ b/tests/ref/fate/ac4-mp4-copy
@@ -0,0 +1,37 @@
+48139bfc7f87f872e85775bd96db382e *tests/data/fate/ac4-mp4-copy.mp4
+15294 tests/data/fate/ac4-mp4-copy.mp4
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,          0,          0,     1602,      464, 0x565e1ac9
+0,       1602,       1602,     1601,      456, 0xcd5c17d1
+0,       3203,       3203,     1602,      459, 0xdb5a15bf
+0,       4805,       4805,     1601,      458, 0xd41115b9
+0,       6406,       6406,     1602,      503, 0x468af683
+0,       8008,       8008,     1602,      592, 0x688f02bc
+0,       9610,       9610,     1601,      577, 0x8d031d52
+0,      11211,      11211,     1602,      573, 0xfb340c42
+0,      12813,      12813,     1601,      550, 0xe5ba018a
+0,      14414,      14414,     1602,      529, 0x9d27f913
+0,      16016,      16016,     1602,      511, 0xbd7ce52d
+0,      17618,      17618,     1601,      509, 0x94d4e9b0
+0,      19219,      19219,     1602,      493, 0x52efd55e
+0,      20821,      20821,     1601,      498, 0x17a1f10a
+0,      22422,      22422,     1602,      481, 0xbd2ee321
+0,      24024,      24024,     1602,      487, 0xba53d415
+0,      25626,      25626,     1601,      488, 0x9530e19a
+0,      27227,      27227,     1602,      482, 0xb74fe19e
+0,      28829,      28829,     1601,      464, 0x78a6ce40
+0,      30430,      30430,     1602,      471, 0xd202d4d1
+0,      32032,      32032,     1602,      448, 0xeed7d853
+0,      33634,      33634,     1601,      444, 0x20b4cf0a
+0,      35235,      35235,     1602,      448, 0x99bfd5ac
+0,      36837,      36837,     1601,      445, 0x05d3ca97
+0,      38438,      38438,     1602,      461, 0x5a25d686
+0,      40040,      40040,     1602,      485, 0xfbfacb63
+0,      41642,      41642,     1601,      385, 0xc5b5ad17
+0,      43243,      43243,     1602,      377, 0x2882b315
+0,      44845,      44845,     1601,      368, 0x7de4ab13
+0,      46446,      46446,     1602,      390, 0x63d5b521
diff --git a/tests/ref/fate/ac4-mp4-frag b/tests/ref/fate/ac4-mp4-frag
new file mode 100644
index 00000000000..3d84d91d4ca
--- /dev/null
+++ b/tests/ref/fate/ac4-mp4-frag
@@ -0,0 +1,32 @@
+2e0f261337a88e17597289da48bb6a8c *tests/data/fate/ac4-mp4-frag.mp4
+8518 tests/data/fate/ac4-mp4-frag.mp4
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        1,      251, 0xb0b17ced
+0,          1,          1,        1,      262, 0x42cf80af
+0,          2,          2,        1,      278, 0x489885a0
+0,          3,          3,        1,      298, 0x75008149
+0,          4,          4,        1,      372, 0xe637bab0
+0,          5,          5,        1,      303, 0x75ef8feb
+0,          6,          6,        1,      310, 0x66f5914a
+0,          7,          7,        1,      312, 0xf6788930
+0,          8,          8,        1,      283, 0x261486a4
+0,          9,          9,        1,      363, 0xa9fda9d5
+0,         10,         10,        1,      317, 0xf7069a4f
+0,         11,         11,        1,      292, 0x06468cc7
+0,         12,         12,        1,      290, 0x84a48b49
+0,         13,         13,        1,      302, 0xf7ec8805
+0,         14,         14,        1,      300, 0x66a89591
+0,         15,         15,        1,      346, 0xf8009d1a
+0,         16,         16,        1,      291, 0xd0b98977
+0,         17,         17,        1,      354, 0xff67ae48
+0,         18,         18,        1,      283, 0xc9b58636
+0,         19,         19,        1,      309, 0x84658ce1
+0,         20,         20,        1,      356, 0x98dda801
+0,         21,         21,        1,      270, 0x595e8ae7
+0,         22,         22,        1,      275, 0x10598c0f
+0,         23,         23,        1,      295, 0xc8d38f8c
+0,         24,         24,        1,      290, 0xe30b94a1
diff --git a/tests/ref/fate/ac4-mp4-ts b/tests/ref/fate/ac4-mp4-ts
new file mode 100644
index 00000000000..b0527c24da5
--- /dev/null
+++ b/tests/ref/fate/ac4-mp4-ts
@@ -0,0 +1,37 @@
+aa6c209a0b34292086b380fc38a1c440 *tests/data/fate/ac4-mp4-ts.mpegts
+21996 tests/data/fate/ac4-mp4-ts.mpegts
+#tb 0: 1/90000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        0,      468, 0x815d1c86, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       3004,       3004,        0,      460, 0xdc2b1986, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       6006,       6006,        0,      463, 0xf4ac1777, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,       9009,       9009,        0,      462, 0xe9e01770, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      12011,      12011,        0,      507, 0x022bf867, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      15015,      15015,        0,      596, 0x4be003fa, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      18019,      18019,        0,      581, 0x3bd41e81, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      21021,      21021,        0,      577, 0x9c510d6d, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      24024,      24024,        0,      554, 0x3a79029e, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      27026,      27026,        0,      533, 0xafb9fa12, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      30030,      30030,        0,      515, 0x983de719, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      33034,      33034,        0,      513, 0x67c1eb9a, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      36036,      36036,        0,      497, 0xe84dd738, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      39039,      39039,        0,      502, 0xc000f2e9, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      42041,      42041,        0,      485, 0x25cbe4ef, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      45045,      45045,        0,      491, 0x3934d5e9, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      48049,      48049,        0,      492, 0x17cee36f, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      51051,      51051,        0,      486, 0x239de36d, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      54054,      54054,        0,      468, 0xa3a5cffd, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      57056,      57056,        0,      475, 0x1623d695, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      60060,      60060,        0,      452, 0xe1f6da00, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      63064,      63064,        0,      448, 0x062bd0b3, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      66066,      66066,        0,      452, 0x8cded759, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      69069,      69069,        0,      449, 0xeea2cc41, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      72071,      72071,        0,      465, 0x7a83d840, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      75075,      75075,        0,      489, 0x7367cd35, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      78079,      78079,        0,      389, 0xf034ae85, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      81081,      81081,        0,      381, 0x3bc1b47b, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      84084,      84084,        0,      372, 0x7794ac70, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,      87086,      87086,        0,      394, 0x9d1db694, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
diff --git a/tests/ref/fate/ac4-ts b/tests/ref/fate/ac4-ts
new file mode 100644
index 00000000000..30cf00d4583
--- /dev/null
+++ b/tests/ref/fate/ac4-ts
@@ -0,0 +1,32 @@
+38e0cc8ec9977231ffc1914c0004dc5a *tests/data/fate/ac4-ts.mpegts
+10904 tests/data/fate/ac4-ts.mpegts
+#tb 0: 1/90000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        0,      255, 0x92b77ed4, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          1,          1,        0,      266, 0x3f0881a2, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          2,          2,        0,      282, 0x657186a3, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          3,          3,        0,      302, 0xbd718260, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          4,          4,        0,      376, 0xeb2fbc11, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          5,          5,        0,      307, 0xc9c39107, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          6,          6,        0,      314, 0xcb0e926d, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          7,          7,        0,      316, 0x5f588a55, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          8,          8,        0,      287, 0x4d8887ac, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          9,          9,        0,      367, 0x95c0ab2d, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         10,         10,        0,      321, 0x6bd59b79, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         11,         11,        0,      296, 0x414f8dd8, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         12,         12,        0,      294, 0xbb458c58, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         13,         13,        0,      306, 0x49848920, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         14,         14,        0,      304, 0xb3a196aa, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         15,         15,        0,      350, 0xb5e09e61, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         16,         16,        0,      295, 0x099c8a87, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         17,         17,        0,      358, 0xd297af97, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         18,         18,        0,      287, 0xf129873e, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         19,         19,        0,      313, 0xe6258e03, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         20,         20,        0,      360, 0x7175a952, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         21,         21,        0,      274, 0x65a78be2, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         22,         22,        0,      279, 0x26ed8d0f, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         23,         23,        0,      299, 0x0a9690a0, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         24,         24,        0,      294, 0x19bb95b0, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
diff --git a/tests/ref/fate/ac4-ts-copy b/tests/ref/fate/ac4-ts-copy
new file mode 100644
index 00000000000..b4afff8342f
--- /dev/null
+++ b/tests/ref/fate/ac4-ts-copy
@@ -0,0 +1,32 @@
+38e0cc8ec9977231ffc1914c0004dc5a *tests/data/fate/ac4-ts-copy.mpegts
+10904 tests/data/fate/ac4-ts-copy.mpegts
+#tb 0: 1/90000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        0,      255, 0x92b77ed4, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          1,          1,        0,      266, 0x3f0881a2, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          2,          2,        0,      282, 0x657186a3, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          3,          3,        0,      302, 0xbd718260, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          4,          4,        0,      376, 0xeb2fbc11, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          5,          5,        0,      307, 0xc9c39107, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          6,          6,        0,      314, 0xcb0e926d, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          7,          7,        0,      316, 0x5f588a55, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          8,          8,        0,      287, 0x4d8887ac, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,          9,          9,        0,      367, 0x95c0ab2d, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         10,         10,        0,      321, 0x6bd59b79, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         11,         11,        0,      296, 0x414f8dd8, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         12,         12,        0,      294, 0xbb458c58, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         13,         13,        0,      306, 0x49848920, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         14,         14,        0,      304, 0xb3a196aa, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         15,         15,        0,      350, 0xb5e09e61, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         16,         16,        0,      295, 0x099c8a87, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         17,         17,        0,      358, 0xd297af97, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         18,         18,        0,      287, 0xf129873e, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         19,         19,        0,      313, 0xe6258e03, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         20,         20,        0,      360, 0x7175a952, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         21,         21,        0,      274, 0x65a78be2, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         22,         22,        0,      279, 0x26ed8d0f, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         23,         23,        0,      299, 0x0a9690a0, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
+0,         24,         24,        0,      294, 0x19bb95b0, S=1, MPEGTS Stream 
ID,        1, 0x00bd00bd
diff --git a/tests/ref/fate/ac4-ts-mp4 b/tests/ref/fate/ac4-ts-mp4
new file mode 100644
index 00000000000..8bb4335f12b
--- /dev/null
+++ b/tests/ref/fate/ac4-ts-mp4
@@ -0,0 +1,31 @@
+d0e187aa7f6b47c58c6e4d2ba3f856bb *tests/data/fate/ac4-ts-mp4.mp4
+8395 tests/data/fate/ac4-ts-mp4.mp4
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        1,      251, 0xb0b17ced
+0,          1,          1,        1,      262, 0x42cf80af
+0,          2,          2,        1,      278, 0x489885a0
+0,          3,          3,        1,      298, 0x75008149
+0,          4,          4,        1,      372, 0xe637bab0
+0,          5,          5,        1,      303, 0x75ef8feb
+0,          6,          6,        1,      310, 0x66f5914a
+0,          7,          7,        1,      312, 0xf6788930
+0,          8,          8,        1,      283, 0x261486a4
+0,          9,          9,        1,      363, 0xa9fda9d5
+0,         10,         10,        1,      317, 0xf7069a4f
+0,         11,         11,        1,      292, 0x06468cc7
+0,         12,         12,        1,      290, 0x84a48b49
+0,         13,         13,        1,      302, 0xf7ec8805
+0,         14,         14,        1,      300, 0x66a89591
+0,         15,         15,        1,      346, 0xf8009d1a
+0,         16,         16,        1,      291, 0xd0b98977
+0,         17,         17,        1,      354, 0xff67ae48
+0,         18,         18,        1,      283, 0xc9b58636
+0,         19,         19,        1,      309, 0x84658ce1
+0,         20,         20,        1,      356, 0x98dda801
+0,         21,         21,        1,      270, 0x595e8ae7
+0,         22,         22,        1,      275, 0x10598c0f
+0,         23,         23,        1,      295, 0xc8d38f8c
diff --git a/tests/ref/fate/ac4-ts-raw b/tests/ref/fate/ac4-ts-raw
new file mode 100644
index 00000000000..b2cccd4ce5e
--- /dev/null
+++ b/tests/ref/fate/ac4-ts-raw
@@ -0,0 +1,32 @@
+0633a8572abdabaeb4dedf99527634da *tests/data/fate/ac4-ts-raw.ac4
+7702 tests/data/fate/ac4-ts-raw.ac4
+#tb 0: 1/90000
+#media_type 0: audio
+#codec_id 0: ac4
+#sample_rate 0: 48000
+#channel_layout_name 0: 0 channels
+0,          0,          0,        0,      251, 0xb0b17ced
+0,          0,          0,        0,      262, 0x42cf80af
+0,          0,          0,        0,      278, 0x489885a0
+0,          0,          0,        0,      298, 0x75008149
+0,          0,          0,        0,      372, 0xe637bab0
+0,          0,          0,        0,      303, 0x75ef8feb
+0,          0,          0,        0,      310, 0x66f5914a
+0,          0,          0,        0,      312, 0xf6788930
+0,          0,          0,        0,      283, 0x261486a4
+0,          0,          0,        0,      363, 0xa9fda9d5
+0,          0,          0,        0,      317, 0xf7069a4f
+0,          0,          0,        0,      292, 0x06468cc7
+0,          0,          0,        0,      290, 0x84a48b49
+0,          0,          0,        0,      302, 0xf7ec8805
+0,          0,          0,        0,      300, 0x66a89591
+0,          0,          0,        0,      346, 0xf8009d1a
+0,          0,          0,        0,      291, 0xd0b98977
+0,          0,          0,        0,      354, 0xff67ae48
+0,          0,          0,        0,      283, 0xc9b58636
+0,          0,          0,        0,      309, 0x84658ce1
+0,          0,          0,        0,      356, 0x98dda801
+0,          0,          0,        0,      270, 0x595e8ae7
+0,          0,          0,        0,      275, 0x10598c0f
+0,          0,          0,        0,      295, 0xc8d38f8c
+0,          0,          0,        0,      290, 0xe30b94a1
-- 
2.54.0


>From ae429e10bc8cb20759d4745b8e3badc716e426aa Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 14:55:49 +0100
Subject: [PATCH 09/10] doc/muxers: document AC-4 syncframe passthrough

Document that the raw AC-4 muxer writes packets containing a complete
syncframe unchanged.

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 doc/muxers.texi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a2489760fcd..c051ce7a6af 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -684,6 +684,7 @@ codec video stream.
 Raw AC-4 audio muxer.
 
 This muxer accepts a single @code{ac4} audio stream.
+Packets that already contain an AC-4 syncframe are written unchanged.
 
 @subsection Options
 @table @option
-- 
2.54.0


>From f69aa1c984d683b76fc9c2f50e1da983608ffaa5 Mon Sep 17 00:00:00 2001
From: Alexander Slobodeniuk <[email protected]>
Date: Wed, 11 Nov 2026 14:55:49 +0100
Subject: [PATCH 10/10] Changelog: add AC-4 muxing

Signed-off-by: Alexander Slobodeniuk <[email protected]>
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index bce79b181f7..c6e90555f20 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.
 
 version <next>:
+- AC-4 muxing in MP4 and MPEG-TS
 - DTS:X height channels in the DCA decoder
 - LCEVC raw demuxer and muxer
 - AVS+ (AVS1-P16, Broadcasting profile) support in the Chinese AVS decoder
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to