From fc0e4d6bf09b6f32e718399800c0e90adc6f6118 Mon Sep 17 00:00:00 2001
From: Luiz Felipe Stangarlin <luizfelipestang@gmail.com>
Date: Tue, 10 Feb 2026 08:26:35 -0600
Subject: [PATCH 2/2] fix: also allow demuxing iamf to iamf/mp4 without
specifying groups
---
libavformat/iamfdec.c | 21 +++++++++++++++++++++
libavformat/iamfenc.c | 1 +
2 files changed, 22 insertions(+)
diff --git a/libavformat/iamfdec.c b/libavformat/iamfdec.c
index 02f01abc6c..e7ddc27b9b 100644
|
a
|
b
|
static int iamf_read_header(AVFormatContext *s)
|
| 75 | 75 | IAMFContext *const iamf = &c->iamf; |
| 76 | 76 | int ret; |
| 77 | 77 | |
| | 78 | int64_t old_offset = avio_tell(s->pb); |
| | 79 | |
| 78 | 80 | ret = ff_iamfdec_read_descriptors(iamf, s->pb, INT_MAX, s); |
| 79 | 81 | if (ret < 0) |
| 80 | 82 | return ret; |
| 81 | 83 | |
| | 84 | int64_t cur_offset = avio_tell(s->pb); |
| | 85 | size_t descriptors_size = cur_offset - old_offset; |
| | 86 | |
| 82 | 87 | for (int i = 0; i < iamf->nb_audio_elements; i++) { |
| 83 | 88 | IAMFAudioElement *audio_element = iamf->audio_elements[i]; |
| 84 | 89 | AVStreamGroup *stg = avformat_stream_group_create(s, AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT, NULL); |
| … |
… |
static int iamf_read_header(AVFormatContext *s)
|
| 113 | 118 | st->disposition |= AV_DISPOSITION_DEPENDENT; |
| 114 | 119 | st->id = substream->audio_substream_id; |
| 115 | 120 | avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); |
| | 121 | |
| | 122 | // save a copy of the descriptors on the side data for later use when encoding raw IAMF |
| | 123 | if (i == 0 && j == 0) { |
| | 124 | //we only look at the first stream later |
| | 125 | if (!av_packet_side_data_new(&st->codecpar->coded_side_data, |
| | 126 | &st->codecpar->nb_coded_side_data, |
| | 127 | AV_PKT_DATA_IAMF_DESCRIPTORS, |
| | 128 | descriptors_size, 0)) { |
| | 129 | return AVERROR(ENOMEM); |
| | 130 | } |
| | 131 | avio_seek(s->pb, old_offset, SEEK_SET); |
| | 132 | ret = avio_read(s->pb, st->codecpar->coded_side_data->data, descriptors_size); |
| | 133 | if (ret != descriptors_size) |
| | 134 | return ret < 0 ? ret : AVERROR_INVALIDDATA; |
| | 135 | avio_seek(s->pb, cur_offset, SEEK_SET); |
| | 136 | } |
| 116 | 137 | } |
| 117 | 138 | } |
| 118 | 139 | |
diff --git a/libavformat/iamfenc.c b/libavformat/iamfenc.c
index bc21988907..5030c33996 100644
|
a
|
b
|
static int iamf_init(AVFormatContext *s)
|
| 128 | 128 | ret = ff_iamf_fill_codec_config(iamf, stg, cc); |
| 129 | 129 | if (ret < 0) |
| 130 | 130 | return ret; |
| | 131 | audio_element->codec_config_id = ret; |
| 131 | 132 | } |
| 132 | 133 | |
| 133 | 134 | return 0; |