avformat/iamf_writer: add support for Projection mode ambisonic Audio elements

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2025-12-27 17:11:30 -03:00
parent a0fc454871
commit 8cd4d4cb0b
3 changed files with 13 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ version <next>:
- JPEG-XS parser
- JPEG-XS decoder and encoder through libsvtjpegxs
- JPEG-XS raw bitstream muxer and demuxer
- IAMF Projection mode Ambisonic Audio Elements muxing and demuxing
version 8.0:

View File

@@ -235,7 +235,7 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout for SCENE_BASED audio element\n");
return AVERROR(EINVAL);
}
if (layer->ambisonics_mode >= AV_IAMF_AMBISONICS_MODE_PROJECTION) {
if (layer->ambisonics_mode > AV_IAMF_AMBISONICS_MODE_PROJECTION) {
av_log(log_ctx, AV_LOG_ERROR, "Unsupported ambisonics mode %d\n", layer->ambisonics_mode);
return AVERROR_PATCHWELCOME;
}
@@ -665,16 +665,25 @@ static int ambisonics_config(const IAMFAudioElement *audio_element,
if (audio_element->nb_substreams != ilayer->substream_count)
return AVERROR(EINVAL);
ffio_write_leb(dyn_bc, 0); // ambisonics_mode
ffio_write_leb(dyn_bc, layer->ambisonics_mode);
avio_w8(dyn_bc, layer->ch_layout.nb_channels); // output_channel_count
avio_w8(dyn_bc, audio_element->nb_substreams); // substream_count
if (layer->ambisonics_mode == AV_IAMF_AMBISONICS_MODE_MONO) {
if (layer->ch_layout.order == AV_CHANNEL_ORDER_AMBISONIC)
for (int i = 0; i < layer->ch_layout.nb_channels; i++)
avio_w8(dyn_bc, i);
else
for (int i = 0; i < layer->ch_layout.nb_channels; i++)
avio_w8(dyn_bc, layer->ch_layout.u.map[i].id);
} else {
int nb_demixing_matrix = (ilayer->coupled_substream_count + ilayer->substream_count) * layer->ch_layout.nb_channels;
if (nb_demixing_matrix != layer->nb_demixing_matrix)
return AVERROR(EINVAL);
avio_w8(dyn_bc, ilayer->coupled_substream_count);
for (int i = 0; i < layer->nb_demixing_matrix; i++)
avio_wb16(dyn_bc, rescale_rational(layer->demixing_matrix[i], 1 << 15));
}
return 0;
}

View File

@@ -32,7 +32,7 @@
#include "version_major.h"
#define LIBAVFORMAT_VERSION_MINOR 8
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_MICRO 102
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \