Ticket #11627: 0002-fix-also-allow-demuxing-iamf-to-iamf-mp4-without-spe.patch

File 0002-fix-also-allow-demuxing-iamf-to-iamf-mp4-without-spe.patch, 2.6 KB (added by Luiz Stangarlin, 7 months ago)

patch to allow copying the stream groups from iamf to iamf/mp4

  • libavformat/iamfdec.c

    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)  
    7575    IAMFContext *const iamf = &c->iamf;
    7676    int ret;
    7777
     78    int64_t old_offset = avio_tell(s->pb);
     79
    7880    ret = ff_iamfdec_read_descriptors(iamf, s->pb, INT_MAX, s);
    7981    if (ret < 0)
    8082        return ret;
    8183
     84    int64_t cur_offset = avio_tell(s->pb);
     85    size_t descriptors_size = cur_offset - old_offset;
     86
    8287    for (int i = 0; i < iamf->nb_audio_elements; i++) {
    8388        IAMFAudioElement *audio_element = iamf->audio_elements[i];
    8489        AVStreamGroup *stg = avformat_stream_group_create(s, AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT, NULL);
    static int iamf_read_header(AVFormatContext *s)  
    113118                st->disposition |= AV_DISPOSITION_DEPENDENT;
    114119            st->id = substream->audio_substream_id;
    115120            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            }
    116137        }
    117138    }
    118139
  • libavformat/iamfenc.c

    diff --git a/libavformat/iamfenc.c b/libavformat/iamfenc.c
    index bc21988907..5030c33996 100644
    a b static int iamf_init(AVFormatContext *s)  
    128128            ret = ff_iamf_fill_codec_config(iamf, stg, cc);
    129129            if (ret < 0)
    130130                return ret;
     131            audio_element->codec_config_id = ret;
    131132        }
    132133
    133134        return 0;