PR #26342 opened by Romain Beauxis (toots)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26342
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26342.patch

The two areas of a disc are separate mixes whose tracks can start up to half a 
minute apart, so the chapters, taken from the multichannel area, are wrong for 
the stereo program on many real discs. The new `area` option (`all`, 
`multichannel`, `stereo`) reads one area, whose own tracks become the chapters.

The demuxer also exports the text language, the specification version 
(`sacd_version`), the CD layer flag (`sacd_hybrid`) and the maximum bit rate 
(CPB side data), and requests a sample for an unexpected loudspeaker 
configuration. ffmpeg drops the `sacd_` tags from its output files.

Tests: new SACD FATE tests on two new samples, a DST stereo + DST 5.1 disc and 
a DSD stereo-only disc, covering demuxing, TOC, DST decoding, seeking, the 
`area` option and the copied tags. All SACD tests pass at every commit.

New FATE samples, attached to this PR:

```fate-samples
sacd/2ch-dst_6ch-dst.iso
sacd/2ch-dsd.iso
```


>From 100c57d2c5f3600262fdf220347f6cf43ed1630f Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 18:26:11 -0500
Subject: [PATCH 1/8] tests/fate: add Super Audio CD tests with DST stereo, 5.1
 and stereo-only discs

The samples are generated disc images that follow the layout of real
discs.

2ch-dst_6ch-dst.iso has a DST 2-channel area and a DST 5.1 area, whose
tracks are at other times, and a Master TOC and Area TOCs of version
1.01, which leave the second channel count unset.

2ch-dsd.iso has only a plain DSD 2-channel area.
---
 tests/fate/audio.mak          |   6 ++
 tests/fate/demux.mak          |  12 +++
 tests/fate/seek.mak           |   2 +
 tests/ref/fate/sacd-demux-2ch |  32 ++++++++
 tests/ref/fate/sacd-demux-6ch | 134 ++++++++++++++++++++++++++++++++++
 tests/ref/fate/sacd-dst-2ch   |  67 +++++++++++++++++
 tests/ref/fate/sacd-dst-6ch   |  67 +++++++++++++++++
 tests/ref/fate/sacd-toc-2ch   |  55 ++++++++++++++
 tests/ref/fate/sacd-toc-6ch   |  75 +++++++++++++++++++
 tests/ref/seek/sacd-6ch       |  53 ++++++++++++++
 10 files changed, 503 insertions(+)
 create mode 100644 tests/ref/fate/sacd-demux-2ch
 create mode 100644 tests/ref/fate/sacd-demux-6ch
 create mode 100644 tests/ref/fate/sacd-dst-2ch
 create mode 100644 tests/ref/fate/sacd-dst-6ch
 create mode 100644 tests/ref/fate/sacd-toc-2ch
 create mode 100644 tests/ref/fate/sacd-toc-6ch
 create mode 100644 tests/ref/seek/sacd-6ch

diff --git a/tests/fate/audio.mak b/tests/fate/audio.mak
index 76333e30236..2caae300f43 100644
--- a/tests/fate/audio.mak
+++ b/tests/fate/audio.mak
@@ -134,6 +134,12 @@ fate-rhetorex: CMD = framecrc -i 
$(TARGET_SAMPLES)/rhetorex/rhetorex-mono-4bit-8
 FATE_SAMPLES_AUDIO-$(call FRAMECRC, SACD, DST, DSD_MSBF_ENCODER) += 
fate-sacd-dst
 fate-sacd-dst: CMD = framecrc -request_sample_fmt dsd -i 
$(TARGET_SAMPLES)/sacd/2ch-dsd_5ch-dst.iso -map 0:p:1 -c:a dsd_msbf
 
+FATE_SAMPLES_AUDIO-$(call FRAMECRC, SACD, DST, DSD_MSBF_ENCODER) += 
fate-sacd-dst-6ch
+fate-sacd-dst-6ch: CMD = framecrc -request_sample_fmt dsd -i 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso -map 0:p:1 -c:a dsd_msbf
+
+FATE_SAMPLES_AUDIO-$(call FRAMECRC, SACD, DST, DSD_MSBF_ENCODER) += 
fate-sacd-dst-2ch
+fate-sacd-dst-2ch: CMD = framecrc -request_sample_fmt dsd -i 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso -map 0:p:2 -c:a dsd_msbf
+
 FATE_SAMPLES_AUDIO-$(call FRAMECRC, VMD, VMDAUDIO, ARESAMPLE_FILTER) += 
fate-sierra-vmd-audio
 fate-sierra-vmd-audio: CMD = framecrc -i $(TARGET_SAMPLES)/vmd/12.vmd -vn -af 
aresample
 
diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index d8e9e8b48e2..1884cf28128 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -133,10 +133,22 @@ fate-redspark-demux: CMD = crc -i 
$(TARGET_SAMPLES)/redspark/jingle04_partial.rs
 FATE_SAMPLES_DEMUX-$(call FRAMECRC, SACD) += fate-sacd-demux
 fate-sacd-demux: CMD = framecrc -i $(TARGET_SAMPLES)/sacd/2ch-dsd_5ch-dst.iso 
-map 0 -c:a copy
 
+FATE_SAMPLES_DEMUX-$(call FRAMECRC, SACD) += fate-sacd-demux-6ch
+fate-sacd-demux-6ch: CMD = framecrc -i 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso -map 0 -c:a copy
+
+FATE_SAMPLES_DEMUX-$(call FRAMECRC, SACD) += fate-sacd-demux-2ch
+fate-sacd-demux-2ch: CMD = framecrc -i $(TARGET_SAMPLES)/sacd/2ch-dsd.iso -map 
0 -c:a copy
+
 SACD_TOC_ENTRIES = 
format_tags:program=program_id,nb_streams:program_tags:chapter=id,time_base,start,end:chapter_tags:stream=index,codec_name,sample_rate,channel_layout,duration_ts
 FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc
 fate-sacd-toc: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dsd_5ch-dst.iso
 
+FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc-6ch
+fate-sacd-toc-6ch: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso
+
+FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc-2ch
+fate-sacd-toc-2ch: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dsd.iso
+
 FATE_SAMPLES_DEMUX-$(call FRAMECRC, STR) += fate-psx-str-demux
 fate-psx-str-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/psx-str/descent-partial.str -c copy
 
diff --git a/tests/fate/seek.mak b/tests/fate/seek.mak
index d27001c8266..2af2db5762d 100644
--- a/tests/fate/seek.mak
+++ b/tests/fate/seek.mak
@@ -191,6 +191,7 @@ FATE_SEEK_EXTRA-$(call ALLYES, MOV_DEMUXER) += 
fate-seek-test-iibbibb-mp4
 FATE_SEEK_EXTRA-$(call ALLYES, MOV_DEMUXER) += 
fate-seek-test-iibbibb-neg-ctts-mp4
 FATE_SEEK_EXTRA-$(CONFIG_WAV_DEMUXER)       += fate-seek-bad-avg-byterate
 FATE_SEEK_EXTRA-$(CONFIG_SACD_DEMUXER)      += fate-seek-sacd
+FATE_SEEK_EXTRA-$(CONFIG_SACD_DEMUXER)      += fate-seek-sacd-6ch
 FATE_SEEK_EXTRA-$(CONFIG_DSS_DEMUXER)       += fate-seek-dss-sp
 
 fate-seek-extra-mp3:  CMD = run libavformat/tests/seek$(EXESUF) 
$(TARGET_SAMPLES)/gapless/gapless.mp3 -fastseek 1
@@ -203,6 +204,7 @@ fate-seek-cache-pipe: CMD = cat 
$(SAMPLES)/gapless/gapless.mp3 | run libavformat
 fate-seek-mkv-codec-delay:   CMD = run libavformat/tests/seek$(EXESUF) 
$(TARGET_SAMPLES)/mkv/codec_delay_opus.mkv
 fate-seek-mkv-best-fit-ts:   CMD = run libavformat/tests/seek$(EXESUF) 
$(TARGET_SAMPLES)/mkv/test7_cut.mkv -duration 4 -frames 3 -best_fit_ts 1
 fate-seek-sacd: CMD = run libavformat/tests/seek$(EXESUF) 
$(TARGET_SAMPLES)/sacd/2ch-dsd_5ch-dst.iso -duration 2
+fate-seek-sacd-6ch: CMD = run libavformat/tests/seek$(EXESUF) 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso -duration 2
 fate-seek-dss-sp:     CMD = run libavformat/tests/seek$(EXESUF) 
$(TARGET_SAMPLES)/dss/sp.dss -duration 10
 
 # A master playlist with separate audio and video media playlists with 
different DTS.
diff --git a/tests/ref/fate/sacd-demux-2ch b/tests/ref/fate/sacd-demux-2ch
new file mode 100644
index 00000000000..43b9e99a8c7
--- /dev/null
+++ b/tests/ref/fate/sacd-demux-2ch
@@ -0,0 +1,32 @@
+#tb 0: 1/352800
+#media_type 0: audio
+#codec_id 0: dsd_msbf
+#sample_rate 0: 352800
+#channel_layout_name 0: stereo
+0,          0,          0,     4704,     9408, 0xbf559577
+0,       4704,       4704,     4704,     9408, 0x506053b1
+0,       9408,       9408,     4704,     9408, 0x505055e3
+0,      14112,      14112,     4704,     9408, 0x82e552aa
+0,      18816,      18816,     4704,     9408, 0xb98d5de5
+0,      23520,      23520,     4704,     9408, 0x52785d16
+0,      28224,      28224,     4704,     9408, 0x37ba493b
+0,      32928,      32928,     4704,     9408, 0xec1e5c6c
+0,      37632,      37632,     4704,     9408, 0x6cd93754
+0,      42336,      42336,     4704,     9408, 0xd77339e5
+0,      47040,      47040,     4704,     9408, 0x95744325
+0,      51744,      51744,     4704,     9408, 0x15b75f94
+0,      56448,      56448,     4704,     9408, 0xf95c4a8f
+0,      61152,      61152,     4704,     9408, 0xba9256d2
+0,      65856,      65856,     4704,     9408, 0x0090436c
+0,      70560,      70560,     4704,     9408, 0xcad8562e
+0,      75264,      75264,     4704,     9408, 0x715b5b3f
+0,      79968,      79968,     4704,     9408, 0xe8702f73
+0,      84672,      84672,     4704,     9408, 0xf73c6299
+0,      89376,      89376,     4704,     9408, 0xab340a0e
+0,      94080,      94080,     4704,     9408, 0x4a534478
+0,      98784,      98784,     4704,     9408, 0xa18c382e
+0,     103488,     103488,     4704,     9408, 0xd60b50cc
+0,     108192,     108192,     4704,     9408, 0xf50348fc
+0,     112896,     112896,     4704,     9408, 0xe0593463
+0,     117600,     117600,     4704,     9408, 0xc914f9fa
+0,     122304,     122304,     4704,     9408, 0x222925ef
diff --git a/tests/ref/fate/sacd-demux-6ch b/tests/ref/fate/sacd-demux-6ch
new file mode 100644
index 00000000000..824bd6df9bb
--- /dev/null
+++ b/tests/ref/fate/sacd-demux-6ch
@@ -0,0 +1,134 @@
+#tb 0: 1/352800
+#media_type 0: audio
+#codec_id 0: dst
+#sample_rate 0: 352800
+#channel_layout_name 0: 5.1(side)
+#tb 1: 1/352800
+#media_type 1: audio
+#codec_id 1: dst
+#sample_rate 1: 352800
+#channel_layout_name 1: stereo
+0,          0,          0,     4704,     7223, 0x18ad092b
+1,          0,          0,     4704,     3862, 0x8b367c06
+0,       4704,       4704,     4704,     7114, 0x2484c952
+1,       4704,       4704,     4704,     3802, 0x155c5868
+0,       9408,       9408,     4704,     7136, 0x2ee9f1da
+1,       9408,       9408,     4704,     3704, 0xd3be2780
+0,      14112,      14112,     4704,     7028, 0x35248c4a
+1,      14112,      14112,     4704,     3729, 0xb8d839aa
+0,      18816,      18816,     4704,     7070, 0x22e283e1
+1,      18816,      18816,     4704,     3736, 0xc09e4fd6
+0,      23520,      23520,     4704,     7108, 0x1105cdad
+1,      23520,      23520,     4704,     3676, 0xe6c72474
+0,      28224,      28224,     4704,     6950, 0x6323924e
+1,      28224,      28224,     4704,     3698, 0x88d42e03
+0,      32928,      32928,     4704,     7161, 0xdc6ee3a3
+1,      32928,      32928,     4704,     3665, 0x36ed144a
+0,      37632,      37632,     4704,     7087, 0xb7c6c6c1
+1,      37632,      37632,     4704,     3662, 0x93bb1856
+0,      42336,      42336,     4704,     6974, 0x753e87fd
+1,      42336,      42336,     4704,     3739, 0xb3ae4b45
+0,      47040,      47040,     4704,     6889, 0x88577bfc
+1,      47040,      47040,     4704,     3626, 0xe20bf3f0
+0,      51744,      51744,     4704,     6878, 0x2eca8793
+1,      51744,      51744,     4704,     3576, 0x272c1b58
+0,      56448,      56448,     4704,     7014, 0xc131a644
+1,      56448,      56448,     4704,     3525, 0x905ecca4
+0,      61152,      61152,     4704,     7308, 0xa71e4579
+1,      61152,      61152,     4704,     3453, 0xfe54af6c
+0,      65856,      65856,     4704,     7487, 0xb7269bf4
+1,      65856,      65856,     4704,     3662, 0x4e310fa2
+0,      70560,      70560,     4704,     7510, 0xb6679f38
+1,      70560,      70560,     4704,     3784, 0xf8f57335
+0,      75264,      75264,     4704,     7373, 0x5b093287
+1,      75264,      75264,     4704,     3870, 0xb76f9047
+0,      79968,      79968,     4704,     7409, 0x394c716d
+1,      79968,      79968,     4704,     3900, 0x82f794d7
+0,      84672,      84672,     4704,     7342, 0x1a17442d
+1,      84672,      84672,     4704,     3879, 0x64e58b27
+0,      89376,      89376,     4704,     7289, 0x81652590
+1,      89376,      89376,     4704,     3871, 0x2ffd941b
+0,      94080,      94080,     4704,     7273, 0x33c4243b
+1,      94080,      94080,     4704,     3950, 0x3e21a350
+0,      98784,      98784,     4704,     7194, 0x5772f040
+1,      98784,      98784,     4704,     3961, 0x9c6aac7c
+0,     103488,     103488,     4704,     7106, 0xd2c6e651
+1,     103488,     103488,     4704,     3933, 0x843e93cb
+0,     108192,     108192,     4704,     7102, 0xfd3bcad8
+1,     108192,     108192,     4704,     3927, 0xe32ca151
+0,     112896,     112896,     4704,     7035, 0xbce7af82
+1,     112896,     112896,     4704,     3926, 0xb1dea257
+0,     117600,     117600,     4704,     6975, 0x2c6c7977
+1,     117600,     117600,     4704,     3893, 0xf5b39b20
+0,     122304,     122304,     4704,     6976, 0x68a1a497
+1,     122304,     122304,     4704,     3845, 0x5bef825a
+0,     127008,     127008,     4704,     6949, 0x398788b4
+1,     127008,     127008,     4704,     3832, 0x09f370e5
+0,     131712,     131712,     4704,     6968, 0x84ef5ade
+1,     131712,     131712,     4704,     3830, 0x55d06230
+0,     136416,     136416,     4704,     6963, 0x597b8e96
+1,     136416,     136416,     4704,     3802, 0x696e487d
+0,     141120,     141120,     4704,     6914, 0x31417c80
+1,     141120,     141120,     4704,     3811, 0x7f9972c2
+0,     145824,     145824,     4704,     7431, 0xbad36e30
+1,     145824,     145824,     4704,     3814, 0x12f74c47
+0,     150528,     150528,     4704,     7546, 0xa6b5bb7c
+1,     150528,     150528,     4704,     3826, 0x978e5e58
+0,     155232,     155232,     4704,     7527, 0xdf62840a
+1,     155232,     155232,     4704,     3955, 0xe76a97c8
+0,     159936,     159936,     4704,     7396, 0x606960b5
+1,     159936,     159936,     4704,     3953, 0xce379b14
+0,     164640,     164640,     4704,     7299, 0x36293479
+1,     164640,     164640,     4704,     3914, 0xd1d3a26d
+0,     169344,     169344,     4704,     7238, 0x174f1dab
+1,     169344,     169344,     4704,     3882, 0xf2c09077
+0,     174048,     174048,     4704,     7153, 0x06211a42
+1,     174048,     174048,     4704,     3818, 0xf3c16bce
+0,     178752,     178752,     4704,     7081, 0xcc71923b
+1,     178752,     178752,     4704,     3861, 0xe2969302
+0,     183456,     183456,     4704,     6979, 0xe799881c
+1,     183456,     183456,     4704,     3826, 0xa42a662d
+0,     188160,     188160,     4704,     6983, 0x6be38568
+1,     188160,     188160,     4704,     3801, 0x41804140
+0,     192864,     192864,     4704,     6964, 0xd4e79536
+1,     192864,     192864,     4704,     3782, 0x50974d22
+0,     197568,     197568,     4704,     6925, 0xc7f1a3c4
+1,     197568,     197568,     4704,     3758, 0x2d7a4c9e
+0,     202272,     202272,     4704,     6856, 0xeb6a476e
+1,     202272,     202272,     4704,     3740, 0x890733a3
+0,     206976,     206976,     4704,     6874, 0x56165853
+1,     206976,     206976,     4704,     3771, 0x25fe63e5
+0,     211680,     211680,     4704,     7155, 0x905ecd9b
+1,     211680,     211680,     4704,     3703, 0x91b525f1
+0,     216384,     216384,     4704,     7143, 0xff3af98c
+1,     216384,     216384,     4704,     3715, 0x08db3b2c
+0,     221088,     221088,     4704,     6927, 0x4d798887
+1,     221088,     221088,     4704,     3766, 0x10504b78
+0,     225792,     225792,     4704,     6865, 0xe192581c
+1,     225792,     225792,     4704,     3728, 0x8aa43ed0
+0,     230496,     230496,     4704,     6738, 0x05c3223d
+1,     230496,     230496,     4704,     3600, 0x8156e874
+0,     235200,     235200,     4704,     6730, 0xc6b10a67
+1,     235200,     235200,     4704,     3497, 0x6bb4debd
+0,     239904,     239904,     4704,     7035, 0xded196d7
+1,     239904,     239904,     4704,     3445, 0xe811c455
+0,     244608,     244608,     4704,     7133, 0x147001f1
+1,     244608,     244608,     4704,     3522, 0x6423e9b2
+0,     249312,     249312,     4704,     7330, 0xf6ea2992
+1,     249312,     249312,     4704,     3559, 0xe779d730
+0,     254016,     254016,     4704,     7366, 0xe08f511f
+1,     254016,     254016,     4704,     3639, 0x389a15c1
+0,     258720,     258720,     4704,     7321, 0x2fdc3af4
+1,     258720,     258720,     4704,     3739, 0x310f296a
+0,     263424,     263424,     4704,     7279, 0x30634ec4
+1,     263424,     263424,     4704,     3768, 0x1d04517e
+0,     268128,     268128,     4704,     7271, 0x83f93011
+1,     268128,     268128,     4704,     3779, 0xec4460d5
+0,     272832,     272832,     4704,     7199, 0x98ccf485
+1,     272832,     272832,     4704,     3849, 0x6aa86a99
+0,     277536,     277536,     4704,     7226, 0xcd1429c8
+1,     277536,     277536,     4704,     3843, 0x652a8028
+0,     282240,     282240,     4704,     7269, 0x4af111da
+1,     282240,     282240,     4704,     3894, 0xf99b85ed
+0,     286944,     286944,     4704,     7066, 0xc8179bb6
+1,     286944,     286944,     4704,     3901, 0x8df07e40
diff --git a/tests/ref/fate/sacd-dst-2ch b/tests/ref/fate/sacd-dst-2ch
new file mode 100644
index 00000000000..72335c7b22c
--- /dev/null
+++ b/tests/ref/fate/sacd-dst-2ch
@@ -0,0 +1,67 @@
+#tb 0: 1/352800
+#media_type 0: audio
+#codec_id 0: dsd_msbf
+#sample_rate 0: 352800
+#channel_layout_name 0: stereo
+0,          0,          0,     4704,     9408, 0x903551e7
+0,       4704,       4704,     4704,     9408, 0x638e3c87
+0,       9408,       9408,     4704,     9408, 0xeec64a17
+0,      14112,      14112,     4704,     9408, 0x115e302f
+0,      18816,      18816,     4704,     9408, 0xa81552b4
+0,      23520,      23520,     4704,     9408, 0xc8696eee
+0,      28224,      28224,     4704,     9408, 0x6f59741a
+0,      32928,      32928,     4704,     9408, 0xee9546bf
+0,      37632,      37632,     4704,     9408, 0xf0006e45
+0,      42336,      42336,     4704,     9408, 0xbb03408d
+0,      47040,      47040,     4704,     9408, 0x1a358a21
+0,      51744,      51744,     4704,     9408, 0x90153f76
+0,      56448,      56448,     4704,     9408, 0x7a734de1
+0,      61152,      61152,     4704,     9408, 0x0aeb57dc
+0,      65856,      65856,     4704,     9408, 0x33d52210
+0,      70560,      70560,     4704,     9408, 0x23f37f5f
+0,      75264,      75264,     4704,     9408, 0x9fd21d23
+0,      79968,      79968,     4704,     9408, 0xf15a0e02
+0,      84672,      84672,     4704,     9408, 0x0e2a70a8
+0,      89376,      89376,     4704,     9408, 0x39165521
+0,      94080,      94080,     4704,     9408, 0xf4a04f39
+0,      98784,      98784,     4704,     9408, 0xb4264146
+0,     103488,     103488,     4704,     9408, 0x08de54a5
+0,     108192,     108192,     4704,     9408, 0xe34d4818
+0,     112896,     112896,     4704,     9408, 0xb5f05d65
+0,     117600,     117600,     4704,     9408, 0x6de17a23
+0,     122304,     122304,     4704,     9408, 0x39731d88
+0,     127008,     127008,     4704,     9408, 0x85555d30
+0,     131712,     131712,     4704,     9408, 0xf6f74449
+0,     136416,     136416,     4704,     9408, 0x9f6c2719
+0,     141120,     141120,     4704,     9408, 0x656d316d
+0,     145824,     145824,     4704,     9408, 0x46cf4476
+0,     150528,     150528,     4704,     9408, 0xb30d433c
+0,     155232,     155232,     4704,     9408, 0x9e20620e
+0,     159936,     159936,     4704,     9408, 0x7a2850a3
+0,     164640,     164640,     4704,     9408, 0x71b400ef
+0,     169344,     169344,     4704,     9408, 0xd19837c2
+0,     174048,     174048,     4704,     9408, 0xf3c1769f
+0,     178752,     178752,     4704,     9408, 0x8c473e25
+0,     183456,     183456,     4704,     9408, 0x794a45f6
+0,     188160,     188160,     4704,     9408, 0x79f55c89
+0,     192864,     192864,     4704,     9408, 0x8ec6621d
+0,     197568,     197568,     4704,     9408, 0x013524a0
+0,     202272,     202272,     4704,     9408, 0xb6496d51
+0,     206976,     206976,     4704,     9408, 0x56cd8b88
+0,     211680,     211680,     4704,     9408, 0xc3ad34fa
+0,     216384,     216384,     4704,     9408, 0xf19e2d0e
+0,     221088,     221088,     4704,     9408, 0x41e56d4a
+0,     225792,     225792,     4704,     9408, 0xdc763a77
+0,     230496,     230496,     4704,     9408, 0xbbc8413c
+0,     235200,     235200,     4704,     9408, 0xbf067e1e
+0,     239904,     239904,     4704,     9408, 0xb41950ea
+0,     244608,     244608,     4704,     9408, 0x95147c7c
+0,     249312,     249312,     4704,     9408, 0xb1041c8e
+0,     254016,     254016,     4704,     9408, 0xe3e68240
+0,     258720,     258720,     4704,     9408, 0x713062f0
+0,     263424,     263424,     4704,     9408, 0xc9e14a4c
+0,     268128,     268128,     4704,     9408, 0xa36a37d3
+0,     272832,     272832,     4704,     9408, 0xbeca4238
+0,     277536,     277536,     4704,     9408, 0x8e55442d
+0,     282240,     282240,     4704,     9408, 0xe84b445f
+0,     286944,     286944,     4704,     9408, 0xf36f448f
diff --git a/tests/ref/fate/sacd-dst-6ch b/tests/ref/fate/sacd-dst-6ch
new file mode 100644
index 00000000000..5af18b2ed08
--- /dev/null
+++ b/tests/ref/fate/sacd-dst-6ch
@@ -0,0 +1,67 @@
+#tb 0: 1/352800
+#media_type 0: audio
+#codec_id 0: dsd_msbf
+#sample_rate 0: 352800
+#channel_layout_name 0: 5.1(side)
+0,          0,          0,     4704,    28224, 0xf41a705a
+0,       4704,       4704,     4704,    28224, 0x5b759d41
+0,       9408,       9408,     4704,    28224, 0x3819af31
+0,      14112,      14112,     4704,    28224, 0xe05fc2bd
+0,      18816,      18816,     4704,    28224, 0xc225ccf2
+0,      23520,      23520,     4704,    28224, 0xbb883ca9
+0,      28224,      28224,     4704,    28224, 0x64362fe1
+0,      32928,      32928,     4704,    28224, 0x0cf2de8a
+0,      37632,      37632,     4704,    28224, 0x04e5bf30
+0,      42336,      42336,     4704,    28224, 0x7a5d4e89
+0,      47040,      47040,     4704,    28224, 0x6a7e9f81
+0,      51744,      51744,     4704,    28224, 0x7c103b1b
+0,      56448,      56448,     4704,    28224, 0x27d2a2cf
+0,      61152,      61152,     4704,    28224, 0x80b4fd0d
+0,      65856,      65856,     4704,    28224, 0x8816fc24
+0,      70560,      70560,     4704,    28224, 0xc54db1e3
+0,      75264,      75264,     4704,    28224, 0xe40085ef
+0,      79968,      79968,     4704,    28224, 0xb405bfd4
+0,      84672,      84672,     4704,    28224, 0xdf4b9017
+0,      89376,      89376,     4704,    28224, 0x1eb4addb
+0,      94080,      94080,     4704,    28224, 0x6b709b4d
+0,      98784,      98784,     4704,    28224, 0x89419d7c
+0,     103488,     103488,     4704,    28224, 0x0f0e467f
+0,     108192,     108192,     4704,    28224, 0x3984b957
+0,     112896,     112896,     4704,    28224, 0x26255202
+0,     117600,     117600,     4704,    28224, 0x7fbd9fe5
+0,     122304,     122304,     4704,    28224, 0x311376c2
+0,     127008,     127008,     4704,    28224, 0xe3cf9e39
+0,     131712,     131712,     4704,    28224, 0x181f6c26
+0,     136416,     136416,     4704,    28224, 0x09aea309
+0,     141120,     141120,     4704,    28224, 0x41d2ac8d
+0,     145824,     145824,     4704,    28224, 0xef219f51
+0,     150528,     150528,     4704,    28224, 0x057e7db9
+0,     155232,     155232,     4704,    28224, 0x6e0939d0
+0,     159936,     159936,     4704,    28224, 0xae9993d1
+0,     164640,     164640,     4704,    28224, 0xaafc9a10
+0,     169344,     169344,     4704,    28224, 0x6db38805
+0,     174048,     174048,     4704,    28224, 0x77cab99d
+0,     178752,     178752,     4704,    28224, 0x8e78ab48
+0,     183456,     183456,     4704,    28224, 0x90d2a572
+0,     188160,     188160,     4704,    28224, 0x16335195
+0,     192864,     192864,     4704,    28224, 0xf8554dad
+0,     197568,     197568,     4704,    28224, 0x51bdc116
+0,     202272,     202272,     4704,    28224, 0xb9fa4fdd
+0,     206976,     206976,     4704,    28224, 0x2adbb290
+0,     211680,     211680,     4704,    28224, 0x50688dea
+0,     216384,     216384,     4704,    28224, 0x2389656b
+0,     221088,     221088,     4704,    28224, 0xd31fd8c5
+0,     225792,     225792,     4704,    28224, 0x002577dd
+0,     230496,     230496,     4704,    28224, 0xe04a6dff
+0,     235200,     235200,     4704,    28224, 0xcfc0eeb8
+0,     239904,     239904,     4704,    28224, 0xee4ff9c4
+0,     244608,     244608,     4704,    28224, 0x2690e4da
+0,     249312,     249312,     4704,    28224, 0xc24a77be
+0,     254016,     254016,     4704,    28224, 0x48f55c17
+0,     258720,     258720,     4704,    28224, 0x82819b5b
+0,     263424,     263424,     4704,    28224, 0x0dc1bd6e
+0,     268128,     268128,     4704,    28224, 0x5ff3b760
+0,     272832,     272832,     4704,    28224, 0x3730c10e
+0,     277536,     277536,     4704,    28224, 0xe178d8a1
+0,     282240,     282240,     4704,    28224, 0x757f8878
+0,     286944,     286944,     4704,    28224, 0xd2e8a815
diff --git a/tests/ref/fate/sacd-toc-2ch b/tests/ref/fate/sacd-toc-2ch
new file mode 100644
index 00000000000..89aeb6ba01b
--- /dev/null
+++ b/tests/ref/fate/sacd-toc-2ch
@@ -0,0 +1,55 @@
+[PROGRAM]
+program_id=2
+nb_streams=1
+TAG:title=2-Channel Stereo
+TAG:description=2ch area
+TAG:copyright=(c) stereo
+[STREAM]
+index=0
+codec_name=dsd_msbf
+sample_rate=352800
+channel_layout=stereo
+duration_ts=127008
+[/STREAM]
+[/PROGRAM]
+[STREAM]
+index=0
+codec_name=dsd_msbf
+sample_rate=352800
+channel_layout=stereo
+duration_ts=127008
+[/STREAM]
+[CHAPTER]
+id=1
+time_base=1/75
+start=0
+end=12
+TAG:title=Track one
+TAG:artist=Track artist
+TAG:isrc=ZZ0000000001
+TAG:genre=Sound Effects
+[/CHAPTER]
+[CHAPTER]
+id=2
+time_base=1/75
+start=12
+end=27
+TAG:title=Track two
+TAG:artist=Track artist
+TAG:songwriter=Songwriter
+TAG:isrc=ZZ0000000002
+TAG:genre=Sound Effects
+[/CHAPTER]
+[FORMAT]
+TAG:disc=1/1
+TAG:album_catalog_number=TEST-ALBUM-0002
+TAG:catalog_number=TEST-0003
+TAG:genre=Sound Effects
+TAG:date=2026-11-24
+TAG:title=Test disc
+TAG:artist=Disc artist
+TAG:publisher=Disc publisher
+TAG:copyright=(c) Disc
+TAG:album=Test album
+TAG:album_artist=Album artist
+[/FORMAT]
diff --git a/tests/ref/fate/sacd-toc-6ch b/tests/ref/fate/sacd-toc-6ch
new file mode 100644
index 00000000000..6f23ddb1ad8
--- /dev/null
+++ b/tests/ref/fate/sacd-toc-6ch
@@ -0,0 +1,75 @@
+[PROGRAM]
+program_id=1
+nb_streams=1
+TAG:title=Multi Channel
+TAG:description=MC area
+[STREAM]
+index=0
+codec_name=dst
+sample_rate=352800
+channel_layout=5.1(side)
+duration_ts=291648
+[/STREAM]
+[/PROGRAM]
+[PROGRAM]
+program_id=2
+nb_streams=1
+TAG:title=2-Channel Stereo
+TAG:description=2ch area
+TAG:copyright=(c) stereo
+[STREAM]
+index=1
+codec_name=dst
+sample_rate=352800
+channel_layout=stereo
+duration_ts=291648
+[/STREAM]
+[/PROGRAM]
+[STREAM]
+index=0
+codec_name=dst
+sample_rate=352800
+channel_layout=5.1(side)
+duration_ts=291648
+[/STREAM]
+[STREAM]
+index=1
+codec_name=dst
+sample_rate=352800
+channel_layout=stereo
+duration_ts=291648
+[/STREAM]
+[CHAPTER]
+id=1
+time_base=1/75
+start=0
+end=30
+TAG:title=Track one
+TAG:artist=Track artist
+TAG:isrc=ZZ0000000001
+TAG:genre=Sound Effects
+[/CHAPTER]
+[CHAPTER]
+id=2
+time_base=1/75
+start=30
+end=62
+TAG:title=Track two
+TAG:artist=Track artist
+TAG:songwriter=Songwriter
+TAG:isrc=ZZ0000000002
+TAG:genre=Sound Effects
+[/CHAPTER]
+[FORMAT]
+TAG:disc=1/1
+TAG:album_catalog_number=TEST-ALBUM-0002
+TAG:catalog_number=TEST-0002
+TAG:genre=Sound Effects
+TAG:date=2026-11-24
+TAG:title=Test disc
+TAG:artist=Disc artist
+TAG:publisher=Disc publisher
+TAG:copyright=(c) Disc
+TAG:album=Test album
+TAG:album_artist=Album artist
+[/FORMAT]
diff --git a/tests/ref/seek/sacd-6ch b/tests/ref/seek/sacd-6ch
new file mode 100644
index 00000000000..3409098840f
--- /dev/null
+++ b/tests/ref/seek/sacd-6ch
@@ -0,0 +1,53 @@
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st:-1 flags:0  ts:-1.000000
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st:-1 flags:1  ts:-0.105833
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 0 flags:0  ts: 0.788333
+ret: 0         st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2023424 size:  
7269
+ret: 0         st: 0 flags:1  ts:-0.317500
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 1 flags:0  ts: 0.576667
+ret: 0         st: 0 flags:1 dts: 0.586667 pts: 0.586667 pos:1908736 size:  
6874
+ret: 0         st: 1 flags:1  ts:-0.529164
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st:-1 flags:0  ts: 0.365002
+ret: 0         st: 0 flags:1 dts: 0.373333 pts: 0.373333 pos:1794048 size:  
6968
+ret: 0         st:-1 flags:1  ts:-0.740831
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 0 flags:0  ts: 0.153336
+ret: 0         st: 0 flags:1 dts: 0.160000 pts: 0.160000 pos:1679360 size:  
7014
+ret: 0         st: 0 flags:1  ts:-0.952497
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 1 flags:0  ts:-0.058330
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 1 flags:1  ts: 0.835836
+ret: 0         st: 0 flags:1 dts: 0.813333 pts: 0.813333 pos:2031616 size:  
7066
+ret: 0         st:-1 flags:0  ts:-0.269996
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st:-1 flags:1  ts: 0.624171
+ret: 0         st: 0 flags:1 dts: 0.613333 pts: 0.613333 pos:1923072 size:  
7143
+ret: 0         st: 0 flags:0  ts:-0.481661
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 0 flags:1  ts: 0.412506
+ret: 0         st: 0 flags:1 dts: 0.400000 pts: 0.400000 pos:1808384 size:  
6914
+ret: 0         st: 1 flags:0  ts:-0.693328
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:1701888 size:  
7510
+ret: 0         st:-1 flags:0  ts:-0.904994
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st:-1 flags:1  ts:-0.010827
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 0 flags:0  ts: 0.883339
+ret:-EOF
+ret: 0         st: 0 flags:1  ts:-0.222494
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st: 1 flags:0  ts: 0.671675
+ret: 0         st: 0 flags:1 dts: 0.680000 pts: 0.680000 pos:1957888 size:  
7035
+ret: 0         st: 1 flags:1  ts:-0.434158
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.466667 pts: 0.466667 pos:1845248 size:  
7299
+ret: 0         st:-1 flags:1  ts:-0.645825
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:1595392 size:  
7223
-- 
2.54.1


>From 78acadda2210efc011499fa2966ddd4f8a17ab78 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 18:27:36 -0500
Subject: [PATCH 2/8] avformat/sacddec: add an option to select the audio area

The multi channel and the 2-channel stereo version of a disc can have
their tracks at other times, as they are mixes of their own, and the
chapters are the tracks of the first area. On real discs the tracks of
the stereo area start up to half a minute away from those chapters.

The area option reads only one of the areas, whose tracks are then the
chapters.
---
 doc/demuxers.texi                  | 23 +++++++++++++
 libavformat/sacddec.c              | 51 ++++++++++++++++++++++++---
 libavformat/version.h              |  2 +-
 tests/fate/demux.mak               |  3 ++
 tests/ref/fate/sacd-toc-6ch-stereo | 55 ++++++++++++++++++++++++++++++
 5 files changed, 129 insertions(+), 5 deletions(-)
 create mode 100644 tests/ref/fate/sacd-toc-6ch-stereo

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index e21b887849e..16c845a2d32 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -1191,6 +1191,29 @@ Images with 2048 bytes per sector are detected 
automatically. Images that
 hold the raw sectors of 2064 bytes need the format to be forced with
 @code{-f sacd}, or a @option{formatprobesize} of at least 2M.
 
+@subsection Options
+
+@table @option
+@item area
+Select the audio area to read. The two versions of a disc can have their
+tracks at other times, so the chapters only fit the area they come from.
+
+@table @samp
+@item all
+Read both areas. The chapters are the tracks of the multi channel area, or of
+the 2-channel stereo area on a disc that has only that one. This is the
+default.
+
+@item multichannel
+Read only the multi channel area.
+
+@item stereo
+Read only the 2-channel stereo area, with its own tracks as chapters.
+Mapping only the stereo stream with @samp{all} keeps the multi channel
+chapters.
+@end table
+@end table
+
 @section sbg
 
 SBaGen script demuxer.
diff --git a/libavformat/sacddec.c b/libavformat/sacddec.c
index da4c68aec53..efc3069f0e6 100644
--- a/libavformat/sacddec.c
+++ b/libavformat/sacddec.c
@@ -62,6 +62,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/mem.h"
+#include "libavutil/opt.h"
 
 #include "avformat.h"
 #include "avio_internal.h"
@@ -89,13 +90,19 @@
 #define MAX_TRACKS            255
 #define MAX_TRACK_TEXT_SECTORS 32
 
+enum {
+    AREA_ALL = -1,
+    AREA_MULTI_CHANNEL,
+    AREA_2_CHANNEL,
+};
+
 static const struct {
     int toc_address;            /* offset of the address in Master_TOC_0 */
     const char *signature;
     const char *name;
 } areas[] = {
-    { 0x48, "MULCHTOC", "Multi Channel"    },
-    { 0x40, "TWOCHTOC", "2-Channel Stereo" },
+    [AREA_MULTI_CHANNEL] = { 0x48, "MULCHTOC", "Multi Channel"    },
+    [AREA_2_CHANNEL]     = { 0x40, "TWOCHTOC", "2-Channel Stereo" },
 };
 
 enum {
@@ -127,6 +134,9 @@ typedef struct SACDArea {
 } SACDArea;
 
 typedef struct SACDContext {
+    const AVClass *class;
+    int area;                   /* the only area to read, or AREA_ALL */
+
     int sector_size;            /* bytes per sector in the image */
     int sector_offset;          /* offset of the data in a sector */
 
@@ -674,16 +684,26 @@ end:
 
 static int sacd_read_header(AVFormatContext *s)
 {
+    SACDContext *c = s->priv_data;
     uint32_t toc_lsn[FF_ARRAY_ELEMS(areas)];
     int ret;
 
     if ((ret = read_master_toc(s, toc_lsn)) < 0)
         return ret;
 
+    if (c->area != AREA_ALL && !toc_lsn[c->area]) {
+        av_log(s, AV_LOG_ERROR, "The disc has no %s area\n",
+               areas[c->area].name);
+        return AVERROR_STREAM_NOT_FOUND;
+    }
+
+    /* the chapters are the tracks of the first area read, and the other
+     * area only matters for the ISRCs, when both are read */
     for (int i = 0; i < FF_ARRAY_ELEMS(areas); i++) {
-        if (!toc_lsn[i])
+        if (!toc_lsn[i] || (c->area != AREA_ALL && i != c->area))
             continue;
-        ret = read_area_toc(s, i, toc_lsn[i], toc_lsn[!i]);
+        ret = read_area_toc(s, i, toc_lsn[i],
+                            c->area == AREA_ALL ? toc_lsn[!i] : 0);
         if (ret < 0)
             return ret;
     }
@@ -877,9 +897,32 @@ static int sacd_read_close(AVFormatContext *s)
     return 0;
 }
 
+#define OFFSET(x) offsetof(SACDContext, x)
+#define DEC AV_OPT_FLAG_DECODING_PARAM
+static const AVOption sacd_options[] = {
+    { "area", "audio area to read", OFFSET(area), AV_OPT_TYPE_INT,
+      { .i64 = AREA_ALL }, AREA_ALL, AREA_2_CHANNEL, DEC, .unit = "area" },
+        { "all",          "both areas, the chapters are the tracks of the 
multi channel one",
+          0, AV_OPT_TYPE_CONST, { .i64 = AREA_ALL },           0, 0, DEC, 
.unit = "area" },
+        { "multichannel", "the multi channel area",
+          0, AV_OPT_TYPE_CONST, { .i64 = AREA_MULTI_CHANNEL }, 0, 0, DEC, 
.unit = "area" },
+        { "stereo",       "the 2-channel stereo area",
+          0, AV_OPT_TYPE_CONST, { .i64 = AREA_2_CHANNEL },     0, 0, DEC, 
.unit = "area" },
+    { NULL },
+};
+
+static const AVClass sacd_demuxer_class = {
+    .class_name = "SACD demuxer",
+    .item_name  = av_default_item_name,
+    .option     = sacd_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+    .category   = AV_CLASS_CATEGORY_DEMUXER,
+};
+
 const FFInputFormat ff_sacd_demuxer = {
     .p.name         = "sacd",
     .p.long_name    = NULL_IF_CONFIG_SMALL("Super Audio CD (SACD)"),
+    .p.priv_class   = &sacd_demuxer_class,
     .p.flags        = AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
     .priv_data_size = sizeof(SACDContext),
     .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
diff --git a/libavformat/version.h b/libavformat/version.h
index 683184d5da1..2f54f57c024 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR  21
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index 1884cf28128..ef15f0881b3 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -146,6 +146,9 @@ fate-sacd-toc: CMD = probe -show_entries 
$(SACD_TOC_ENTRIES) $(TARGET_SAMPLES)/s
 FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc-6ch
 fate-sacd-toc-6ch: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso
 
+FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc-6ch-stereo
+fate-sacd-toc-6ch-stereo: CMD = probe -show_entries $(SACD_TOC_ENTRIES) -area 
stereo $(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.iso
+
 FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc-2ch
 fate-sacd-toc-2ch: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dsd.iso
 
diff --git a/tests/ref/fate/sacd-toc-6ch-stereo 
b/tests/ref/fate/sacd-toc-6ch-stereo
new file mode 100644
index 00000000000..683d8187b4e
--- /dev/null
+++ b/tests/ref/fate/sacd-toc-6ch-stereo
@@ -0,0 +1,55 @@
+[PROGRAM]
+program_id=2
+nb_streams=1
+TAG:title=2-Channel Stereo
+TAG:description=2ch area
+TAG:copyright=(c) stereo
+[STREAM]
+index=0
+codec_name=dst
+sample_rate=352800
+channel_layout=stereo
+duration_ts=291648
+[/STREAM]
+[/PROGRAM]
+[STREAM]
+index=0
+codec_name=dst
+sample_rate=352800
+channel_layout=stereo
+duration_ts=291648
+[/STREAM]
+[CHAPTER]
+id=1
+time_base=1/75
+start=0
+end=26
+TAG:title=Track one
+TAG:artist=Track artist
+TAG:isrc=ZZ0000000001
+TAG:genre=Sound Effects
+[/CHAPTER]
+[CHAPTER]
+id=2
+time_base=1/75
+start=26
+end=62
+TAG:title=Track two
+TAG:artist=Track artist
+TAG:songwriter=Songwriter
+TAG:isrc=ZZ0000000002
+TAG:genre=Sound Effects
+[/CHAPTER]
+[FORMAT]
+TAG:disc=1/1
+TAG:album_catalog_number=TEST-ALBUM-0002
+TAG:catalog_number=TEST-0002
+TAG:genre=Sound Effects
+TAG:date=2026-11-24
+TAG:title=Test disc
+TAG:artist=Disc artist
+TAG:publisher=Disc publisher
+TAG:copyright=(c) Disc
+TAG:album=Test album
+TAG:album_artist=Album artist
+[/FORMAT]
-- 
2.54.1


>From bba1d976bdb2b3a4348691d0720efb357374dd2a Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 18:28:15 -0500
Subject: [PATCH 3/8] avformat/sacddec: request a sample for an unknown
 loudspeaker configuration

Real discs have the loudspeaker configurations of DSDIFF that go with
their channel count: 0 with 2 channels, 3 with 5 and 4 with 6. The layout
still follows the channel count, for an area with any other
configuration.
---
 libavformat/sacddec.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavformat/sacddec.c b/libavformat/sacddec.c
index efc3069f0e6..f5c5b6602e1 100644
--- a/libavformat/sacddec.c
+++ b/libavformat/sacddec.c
@@ -522,9 +522,15 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
         [5] = AV_CHANNEL_LAYOUT_5POINT0,
         [6] = AV_CHANNEL_LAYOUT_5POINT1,
     };
+    /* the loudspeaker configurations of those layouts, as in DSDIFF */
+    static const uint8_t loudspeaker_configs[] = {
+        [2] = 0,
+        [5] = 3,
+        [6] = 4,
+    };
     uint8_t buf[2 * SECTOR_SIZE], tracks[SECTOR_SIZE];
     uint8_t *track_text = NULL;
-    int toc_size, nb_channels, nb_tracks, has_text;
+    int toc_size, nb_channels, loudspeaker_config, nb_tracks, has_text;
     int track_text_pos, track_text_size = 0, access_list_pos;
     AVProgram *program;
     AVStream *st;
@@ -555,6 +561,7 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
     toc_size        = AV_RB16(buf + 0x0a);
     a->frame_format = buf[0x15] & 0xf;
     nb_channels     = buf[0x20];
+    loudspeaker_config = buf[0x21] & 7;
     a->nb_frames    = time_code(buf + 0x40);
     /* the tracks of the first area are the chapters, those of the other one
      * are left out, as a file has only one list of chapters */
@@ -580,6 +587,11 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
         (nb_channels != 2 && a->frame_format != FRAME_FORMAT_DST) ||
         a->start > a->end)
         return AVERROR_INVALIDDATA;
+    /* the layout follows the channel count, other configurations are not
+     * known from real discs */
+    if (loudspeaker_config != loudspeaker_configs[nb_channels])
+        avpriv_request_sample(s, "Loudspeaker configuration %d with %d 
channels",
+                              loudspeaker_config, nb_channels);
 
     if (has_text) {
         set_text(s, &program->metadata, "description", buf, SECTOR_SIZE,
-- 
2.54.1


>From ad3c0cf4be6e1c77663b2c1f0c568b3cee6fa74f Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 20:40:25 -0600
Subject: [PATCH 4/8] avformat/sacddec: export the language of the texts

The Master TOC and each Area TOC give the language of their first Text
Channel as an ISO 639-1 code. It becomes the language of the disc and of
the programs, the levels the texts describe, rather than of the streams,
as the texts need not be in the language of the audio.
---
 libavformat/sacddec.c              | 13 +++++++++++++
 tests/ref/fate/sacd-toc            |  3 +++
 tests/ref/fate/sacd-toc-2ch        |  2 ++
 tests/ref/fate/sacd-toc-6ch        |  3 +++
 tests/ref/fate/sacd-toc-6ch-stereo |  2 ++
 5 files changed, 23 insertions(+)

diff --git a/libavformat/sacddec.c b/libavformat/sacddec.c
index f5c5b6602e1..4de9962ae5f 100644
--- a/libavformat/sacddec.c
+++ b/libavformat/sacddec.c
@@ -66,6 +66,7 @@
 
 #include "avformat.h"
 #include "avio_internal.h"
+#include "avlanguage.h"
 #include "demux.h"
 #include "internal.h"
 
@@ -338,6 +339,16 @@ static int text_supported(AVFormatContext *s, const 
uint8_t *text_channels)
     return 0;
 }
 
+/* the language of the texts of the first Text Channel, in ISO 639-1 */
+static void set_language(AVDictionary **m, const uint8_t *text_channels)
+{
+    const char code[3] = { text_channels[8], text_channels[8 + 1] };
+    const char *lang   = ff_convert_lang_to(code, AV_LANG_ISO639_2_BIBL);
+
+    if (lang)
+        av_dict_set(m, "language", lang, 0);
+}
+
 static int read_master_toc(AVFormatContext *s, uint32_t *toc_lsn)
 {
     /* the texts of the disc, then those of the album, which only fill in
@@ -393,6 +404,7 @@ static int read_master_toc(AVFormatContext *s, uint32_t 
*toc_lsn)
     /* only the first Text Channel is read, its texts are in the next sector */
     if (!text_supported(s, buf + 0x80))
         return 0;
+    set_language(&s->metadata, buf + 0x80);
     if ((ret = read_sectors(s, MASTER_TOC_LSN + 1, buf, 1)) < 0)
         return ret;
     if (memcmp(buf, "SACDText", 8))
@@ -594,6 +606,7 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
                               loudspeaker_config, nb_channels);
 
     if (has_text) {
+        set_language(&program->metadata, buf + 0x50);
         set_text(s, &program->metadata, "description", buf, SECTOR_SIZE,
                  AV_RB16(buf + 0x90), 0);
         set_text(s, &program->metadata, "copyright", buf, SECTOR_SIZE,
diff --git a/tests/ref/fate/sacd-toc b/tests/ref/fate/sacd-toc
index 3f2abcfe340..b1c7ddcaa58 100644
--- a/tests/ref/fate/sacd-toc
+++ b/tests/ref/fate/sacd-toc
@@ -2,6 +2,7 @@
 program_id=1
 nb_streams=1
 TAG:title=Multi Channel
+TAG:language=eng
 TAG:description=MC area
 [STREAM]
 index=0
@@ -15,6 +16,7 @@ duration_ts=324576
 program_id=2
 nb_streams=1
 TAG:title=2-Channel Stereo
+TAG:language=eng
 TAG:description=2ch area
 TAG:copyright=(c) stereo
 [STREAM]
@@ -59,6 +61,7 @@ TAG:album_catalog_number=0123456789012
 TAG:catalog_number=TEST-0001
 TAG:genre=Sound Effects
 TAG:date=2026-11-10
+TAG:language=eng
 TAG:title=Test disc
 TAG:artist=Disc artist
 TAG:album=Test album
diff --git a/tests/ref/fate/sacd-toc-2ch b/tests/ref/fate/sacd-toc-2ch
index 89aeb6ba01b..6b91aeb3876 100644
--- a/tests/ref/fate/sacd-toc-2ch
+++ b/tests/ref/fate/sacd-toc-2ch
@@ -2,6 +2,7 @@
 program_id=2
 nb_streams=1
 TAG:title=2-Channel Stereo
+TAG:language=eng
 TAG:description=2ch area
 TAG:copyright=(c) stereo
 [STREAM]
@@ -46,6 +47,7 @@ TAG:album_catalog_number=TEST-ALBUM-0002
 TAG:catalog_number=TEST-0003
 TAG:genre=Sound Effects
 TAG:date=2026-11-24
+TAG:language=eng
 TAG:title=Test disc
 TAG:artist=Disc artist
 TAG:publisher=Disc publisher
diff --git a/tests/ref/fate/sacd-toc-6ch b/tests/ref/fate/sacd-toc-6ch
index 6f23ddb1ad8..6c07dec0cad 100644
--- a/tests/ref/fate/sacd-toc-6ch
+++ b/tests/ref/fate/sacd-toc-6ch
@@ -2,6 +2,7 @@
 program_id=1
 nb_streams=1
 TAG:title=Multi Channel
+TAG:language=eng
 TAG:description=MC area
 [STREAM]
 index=0
@@ -15,6 +16,7 @@ duration_ts=291648
 program_id=2
 nb_streams=1
 TAG:title=2-Channel Stereo
+TAG:language=eng
 TAG:description=2ch area
 TAG:copyright=(c) stereo
 [STREAM]
@@ -66,6 +68,7 @@ TAG:album_catalog_number=TEST-ALBUM-0002
 TAG:catalog_number=TEST-0002
 TAG:genre=Sound Effects
 TAG:date=2026-11-24
+TAG:language=eng
 TAG:title=Test disc
 TAG:artist=Disc artist
 TAG:publisher=Disc publisher
diff --git a/tests/ref/fate/sacd-toc-6ch-stereo 
b/tests/ref/fate/sacd-toc-6ch-stereo
index 683d8187b4e..46070e6f3f0 100644
--- a/tests/ref/fate/sacd-toc-6ch-stereo
+++ b/tests/ref/fate/sacd-toc-6ch-stereo
@@ -2,6 +2,7 @@
 program_id=2
 nb_streams=1
 TAG:title=2-Channel Stereo
+TAG:language=eng
 TAG:description=2ch area
 TAG:copyright=(c) stereo
 [STREAM]
@@ -46,6 +47,7 @@ TAG:album_catalog_number=TEST-ALBUM-0002
 TAG:catalog_number=TEST-0002
 TAG:genre=Sound Effects
 TAG:date=2026-11-24
+TAG:language=eng
 TAG:title=Test disc
 TAG:artist=Disc artist
 TAG:publisher=Disc publisher
-- 
2.54.1


>From 9d7cfd7840b90d2b19a7ac1ed4ec1e50304ef709 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 20:40:42 -0600
Subject: [PATCH 5/8] avformat/sacddec: export the specification version and
 the hybrid flag

The version of the Super Audio CD specification the disc follows, and
whether it also has a CD layer, are informational fields of the Master
TOC. Their keys have a sacd_ prefix, as they describe the disc and
version is a tag of the track in Vorbis comments.
---
 libavformat/sacddec.c              | 6 ++++++
 tests/ref/fate/sacd-toc            | 2 ++
 tests/ref/fate/sacd-toc-2ch        | 2 ++
 tests/ref/fate/sacd-toc-6ch        | 2 ++
 tests/ref/fate/sacd-toc-6ch-stereo | 2 ++
 5 files changed, 14 insertions(+)

diff --git a/libavformat/sacddec.c b/libavformat/sacddec.c
index 4de9962ae5f..853fb356d42 100644
--- a/libavformat/sacddec.c
+++ b/libavformat/sacddec.c
@@ -386,6 +386,12 @@ static int read_master_toc(AVFormatContext *s, uint32_t 
*toc_lsn)
     for (int i = 0; i < FF_ARRAY_ELEMS(areas); i++)
         toc_lsn[i] = AV_RB32(buf + areas[i].toc_address);
 
+    snprintf(str, sizeof(str), "%d.%02d", buf[0x08], buf[0x09]);
+    av_dict_set(&s->metadata, "sacd_version", str, 0);
+    /* the disc has a CD layer */
+    if (buf[0x50] & 0x80)
+        av_dict_set(&s->metadata, "sacd_hybrid", "1", 0);
+
     if (AV_RB16(buf + 0x10) && AV_RB16(buf + 0x12)) {
         snprintf(str, sizeof(str), "%d/%d", AV_RB16(buf + 0x12),
                  AV_RB16(buf + 0x10));
diff --git a/tests/ref/fate/sacd-toc b/tests/ref/fate/sacd-toc
index b1c7ddcaa58..2e0ac03fa0f 100644
--- a/tests/ref/fate/sacd-toc
+++ b/tests/ref/fate/sacd-toc
@@ -56,6 +56,8 @@ end=69
 TAG:title=Surround two
 [/CHAPTER]
 [FORMAT]
+TAG:sacd_version=1.20
+TAG:sacd_hybrid=1
 TAG:disc=1/2
 TAG:album_catalog_number=0123456789012
 TAG:catalog_number=TEST-0001
diff --git a/tests/ref/fate/sacd-toc-2ch b/tests/ref/fate/sacd-toc-2ch
index 6b91aeb3876..13597a75bff 100644
--- a/tests/ref/fate/sacd-toc-2ch
+++ b/tests/ref/fate/sacd-toc-2ch
@@ -42,6 +42,8 @@ TAG:isrc=ZZ0000000002
 TAG:genre=Sound Effects
 [/CHAPTER]
 [FORMAT]
+TAG:sacd_version=1.20
+TAG:sacd_hybrid=1
 TAG:disc=1/1
 TAG:album_catalog_number=TEST-ALBUM-0002
 TAG:catalog_number=TEST-0003
diff --git a/tests/ref/fate/sacd-toc-6ch b/tests/ref/fate/sacd-toc-6ch
index 6c07dec0cad..ee3f9d03992 100644
--- a/tests/ref/fate/sacd-toc-6ch
+++ b/tests/ref/fate/sacd-toc-6ch
@@ -63,6 +63,8 @@ TAG:isrc=ZZ0000000002
 TAG:genre=Sound Effects
 [/CHAPTER]
 [FORMAT]
+TAG:sacd_version=1.01
+TAG:sacd_hybrid=1
 TAG:disc=1/1
 TAG:album_catalog_number=TEST-ALBUM-0002
 TAG:catalog_number=TEST-0002
diff --git a/tests/ref/fate/sacd-toc-6ch-stereo 
b/tests/ref/fate/sacd-toc-6ch-stereo
index 46070e6f3f0..eefa091c0d7 100644
--- a/tests/ref/fate/sacd-toc-6ch-stereo
+++ b/tests/ref/fate/sacd-toc-6ch-stereo
@@ -42,6 +42,8 @@ TAG:isrc=ZZ0000000002
 TAG:genre=Sound Effects
 [/CHAPTER]
 [FORMAT]
+TAG:sacd_version=1.01
+TAG:sacd_hybrid=1
 TAG:disc=1/1
 TAG:album_catalog_number=TEST-ALBUM-0002
 TAG:catalog_number=TEST-0002
-- 
2.54.1


>From c1e075ff365bb28d537e28d4af832b01d756413a Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 20:40:54 -0600
Subject: [PATCH 6/8] avformat/sacddec: export the maximum bit rate of the
 areas

Each Area TOC gives the maximum byte rate of its Track Area. It becomes
the maximum bit rate of the CPB properties of the stream, which muxers
already read. The TOC tests now list the side data of the streams.
---
 libavformat/sacddec.c              | 23 +++++++++++++++++++++
 tests/fate/demux.mak               |  2 +-
 tests/ref/fate/sacd-toc            | 32 ++++++++++++++++++++++++++++++
 tests/ref/fate/sacd-toc-2ch        | 16 +++++++++++++++
 tests/ref/fate/sacd-toc-6ch        | 32 ++++++++++++++++++++++++++++++
 tests/ref/fate/sacd-toc-6ch-stereo | 16 +++++++++++++++
 6 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/libavformat/sacddec.c b/libavformat/sacddec.c
index 853fb356d42..637bc07d435 100644
--- a/libavformat/sacddec.c
+++ b/libavformat/sacddec.c
@@ -531,6 +531,24 @@ static void seek_frame(AVFormatContext *s, AVStream *st, 
int64_t pos)
     a->nb_packets = a->packet = 0;
 }
 
+static int set_max_bitrate(AVStream *st, int64_t max_bitrate)
+{
+    AVCodecParameters *par = st->codecpar;
+    AVCPBProperties *props;
+    size_t size;
+
+    props = av_cpb_properties_alloc(&size);
+    if (!props)
+        return AVERROR(ENOMEM);
+    props->max_bitrate = max_bitrate;
+    if (!av_packet_side_data_add(&par->coded_side_data, 
&par->nb_coded_side_data,
+                                 AV_PKT_DATA_CPB_PROPERTIES, props, size, 0)) {
+        av_free(props);
+        return AVERROR(ENOMEM);
+    }
+    return 0;
+}
+
 static int read_area_toc(AVFormatContext *s, int area, int64_t toc_lsn,
                          int64_t other_toc_lsn)
 {
@@ -550,6 +568,7 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
     uint8_t *track_text = NULL;
     int toc_size, nb_channels, loudspeaker_config, nb_tracks, has_text;
     int track_text_pos, track_text_size = 0, access_list_pos;
+    uint32_t max_byte_rate;
     AVProgram *program;
     AVStream *st;
     SACDArea *a;
@@ -577,6 +596,7 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
     av_dict_set(&program->metadata, "title", areas[area].name, 0);
 
     toc_size        = AV_RB16(buf + 0x0a);
+    max_byte_rate   = AV_RB32(buf + 0x10);
     a->frame_format = buf[0x15] & 0xf;
     nb_channels     = buf[0x20];
     loudspeaker_config = buf[0x21] & 7;
@@ -701,6 +721,9 @@ static int read_area_toc(AVFormatContext *s, int area, 
int64_t toc_lsn,
         st->codecpar->block_align = nb_channels;
         st->codecpar->bit_rate    = nb_channels * BITS_PER_SAMPLE * 
SAMPLE_RATE;
     }
+    if (max_byte_rate &&
+        (ret = set_max_bitrate(st, max_byte_rate * 8LL)) < 0)
+        goto end;
     avpriv_set_pts_info(st, 64, 1, SAMPLE_RATE);
     st->start_time = 0;
     st->duration   = (a->nb_frames - a->first_frame) * (int64_t)FRAME_SAMPLES;
diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index ef15f0881b3..c14b61c4a65 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -139,7 +139,7 @@ fate-sacd-demux-6ch: CMD = framecrc -i 
$(TARGET_SAMPLES)/sacd/2ch-dst_6ch-dst.is
 FATE_SAMPLES_DEMUX-$(call FRAMECRC, SACD) += fate-sacd-demux-2ch
 fate-sacd-demux-2ch: CMD = framecrc -i $(TARGET_SAMPLES)/sacd/2ch-dsd.iso -map 
0 -c:a copy
 
-SACD_TOC_ENTRIES = 
format_tags:program=program_id,nb_streams:program_tags:chapter=id,time_base,start,end:chapter_tags:stream=index,codec_name,sample_rate,channel_layout,duration_ts
+SACD_TOC_ENTRIES = 
format_tags:program=program_id,nb_streams:program_tags:chapter=id,time_base,start,end:chapter_tags:stream=index,codec_name,sample_rate,channel_layout,duration_ts:stream_side_data_list:program_stream_side_data_list
 FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc
 fate-sacd-toc: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dsd_5ch-dst.iso
 
diff --git a/tests/ref/fate/sacd-toc b/tests/ref/fate/sacd-toc
index 2e0ac03fa0f..9c97e6dbdb6 100644
--- a/tests/ref/fate/sacd-toc
+++ b/tests/ref/fate/sacd-toc
@@ -10,6 +10,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=5.0(side)
 duration_ts=324576
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=1327104
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [/PROGRAM]
 [PROGRAM]
@@ -25,6 +33,14 @@ codec_name=dsd_msbf
 sample_rate=352800
 channel_layout=stereo
 duration_ts=188160
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=5743304
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [/PROGRAM]
 [STREAM]
@@ -33,6 +49,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=5.0(side)
 duration_ts=324576
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=1327104
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [STREAM]
 index=1
@@ -40,6 +64,14 @@ codec_name=dsd_msbf
 sample_rate=352800
 channel_layout=stereo
 duration_ts=188160
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=5743304
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [CHAPTER]
 id=1
diff --git a/tests/ref/fate/sacd-toc-2ch b/tests/ref/fate/sacd-toc-2ch
index 13597a75bff..616b8ec359a 100644
--- a/tests/ref/fate/sacd-toc-2ch
+++ b/tests/ref/fate/sacd-toc-2ch
@@ -11,6 +11,14 @@ codec_name=dsd_msbf
 sample_rate=352800
 channel_layout=stereo
 duration_ts=127008
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=5734400
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [/PROGRAM]
 [STREAM]
@@ -19,6 +27,14 @@ codec_name=dsd_msbf
 sample_rate=352800
 channel_layout=stereo
 duration_ts=127008
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=5734400
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [CHAPTER]
 id=1
diff --git a/tests/ref/fate/sacd-toc-6ch b/tests/ref/fate/sacd-toc-6ch
index ee3f9d03992..54f64beeb90 100644
--- a/tests/ref/fate/sacd-toc-6ch
+++ b/tests/ref/fate/sacd-toc-6ch
@@ -10,6 +10,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=5.1(side)
 duration_ts=291648
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=5079040
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [/PROGRAM]
 [PROGRAM]
@@ -25,6 +33,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=stereo
 duration_ts=291648
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=2539520
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [/PROGRAM]
 [STREAM]
@@ -33,6 +49,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=5.1(side)
 duration_ts=291648
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=5079040
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [STREAM]
 index=1
@@ -40,6 +64,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=stereo
 duration_ts=291648
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=2539520
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [CHAPTER]
 id=1
diff --git a/tests/ref/fate/sacd-toc-6ch-stereo 
b/tests/ref/fate/sacd-toc-6ch-stereo
index eefa091c0d7..8cb02eb83f9 100644
--- a/tests/ref/fate/sacd-toc-6ch-stereo
+++ b/tests/ref/fate/sacd-toc-6ch-stereo
@@ -11,6 +11,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=stereo
 duration_ts=291648
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=2539520
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [/PROGRAM]
 [STREAM]
@@ -19,6 +27,14 @@ codec_name=dst
 sample_rate=352800
 channel_layout=stereo
 duration_ts=291648
+[SIDE_DATA]
+side_data_type=CPB properties
+max_bitrate=2539520
+min_bitrate=0
+avg_bitrate=0
+buffer_size=0
+vbv_delay=-1
+[/SIDE_DATA]
 [/STREAM]
 [CHAPTER]
 id=1
-- 
2.54.1


>From cc89cabc5c0903722d505f94b267d0a1e7e49e64 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 20:45:32 -0600
Subject: [PATCH 7/8] tests/fate/demux: test the SACD tags copied by ffmpeg

The tags of the disc as ffmpeg copies them to an ffmetadata file. They
still include the specification version and the hybrid flag, which
describe the source disc.
---
 tests/fate/demux.mak           |  4 ++++
 tests/ref/fate/sacd-ffmetadata | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 tests/ref/fate/sacd-ffmetadata

diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index c14b61c4a65..0c90e6cf741 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -152,6 +152,10 @@ fate-sacd-toc-6ch-stereo: CMD = probe -show_entries 
$(SACD_TOC_ENTRIES) -area st
 FATE_FFPROBE_DEMUX-$(CONFIG_SACD_DEMUXER) += fate-sacd-toc-2ch
 fate-sacd-toc-2ch: CMD = probe -show_entries $(SACD_TOC_ENTRIES) 
$(TARGET_SAMPLES)/sacd/2ch-dsd.iso
 
+# the tags that describe the disc are not copied
+FATE_SAMPLES_DEMUX-$(call DEMMUX, SACD, FFMETADATA, PIPE_PROTOCOL) += 
fate-sacd-ffmetadata
+fate-sacd-ffmetadata: CMD = fmtstdout ffmetadata -i 
$(TARGET_SAMPLES)/sacd/2ch-dsd.iso
+
 FATE_SAMPLES_DEMUX-$(call FRAMECRC, STR) += fate-psx-str-demux
 fate-psx-str-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/psx-str/descent-partial.str -c copy
 
diff --git a/tests/ref/fate/sacd-ffmetadata b/tests/ref/fate/sacd-ffmetadata
new file mode 100644
index 00000000000..e5eae604d04
--- /dev/null
+++ b/tests/ref/fate/sacd-ffmetadata
@@ -0,0 +1,32 @@
+;FFMETADATA1
+sacd_version=1.20
+sacd_hybrid=1
+disc=1/1
+album_catalog_number=TEST-ALBUM-0002
+catalog_number=TEST-0003
+genre=Sound Effects
+date=2026-11-24
+language=eng
+title=Test disc
+artist=Disc artist
+publisher=Disc publisher
+copyright=(c) Disc
+album=Test album
+album_artist=Album artist
+[CHAPTER]
+TIMEBASE=1/75
+START=0
+END=12
+title=Track one
+artist=Track artist
+isrc=ZZ0000000001
+genre=Sound Effects
+[CHAPTER]
+TIMEBASE=1/75
+START=12
+END=27
+title=Track two
+artist=Track artist
+songwriter=Songwriter
+isrc=ZZ0000000002
+genre=Sound Effects
-- 
2.54.1


>From 83019a8cbce177bd7ce656347869066aaefef3d4 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Tue, 24 Nov 2026 20:45:32 -0600
Subject: [PATCH 8/8] fftools/ffmpeg_mux_init: do not copy the SACD disc tags

sacd_version and sacd_hybrid describe the source disc, the specification
it follows and whether it has a CD layer, so they are wrong for any output
file.
---
 fftools/ffmpeg_mux_init.c      | 1 +
 tests/ref/fate/sacd-ffmetadata | 6 ++----
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 00d33bb03bf..33e7b9d115b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -3178,6 +3178,7 @@ static const struct {
     { "major_brand",                  0,                     0 },
     { "minor_version",                0,                     0 },
     { "compatible_brands",            0,                     0 },
+    { "sacd_",                        AV_DICT_IGNORE_SUFFIX, 0 },
     { NULL }
 };
 
diff --git a/tests/ref/fate/sacd-ffmetadata b/tests/ref/fate/sacd-ffmetadata
index e5eae604d04..ecaf580cd33 100644
--- a/tests/ref/fate/sacd-ffmetadata
+++ b/tests/ref/fate/sacd-ffmetadata
@@ -1,6 +1,6 @@
 ;FFMETADATA1
-sacd_version=1.20
-sacd_hybrid=1
+album_artist=Album artist
+album=Test album
 disc=1/1
 album_catalog_number=TEST-ALBUM-0002
 catalog_number=TEST-0003
@@ -11,8 +11,6 @@ title=Test disc
 artist=Disc artist
 publisher=Disc publisher
 copyright=(c) Disc
-album=Test album
-album_artist=Album artist
 [CHAPTER]
 TIMEBASE=1/75
 START=0
-- 
2.54.1

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

Reply via email to