avformat/movenc: write channel descriptions when a known layout or a bitmap can't be used

Fixes part of ticket #2865

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer
2022-03-28 11:24:27 -03:00
parent b4373bc422
commit c2c5f34843
3 changed files with 91 additions and 31 deletions

View File

@@ -867,28 +867,45 @@ static int mov_write_dmlp_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra
static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track)
{
uint32_t layout_tag, bitmap;
uint32_t layout_tag, bitmap, *channel_desc;
int64_t pos = avio_tell(pb);
layout_tag = ff_mov_get_channel_layout_tag(track->par->codec_id,
&track->par->ch_layout,
&bitmap);
if (!layout_tag) {
av_log(s, AV_LOG_WARNING, "not writing 'chan' tag due to "
"lack of channel information\n");
return 0;
}
int num_desc, ret;
if (track->multichannel_as_mono)
return 0;
ret = ff_mov_get_channel_layout_tag(track->par, &layout_tag,
&bitmap, &channel_desc);
if (ret < 0) {
if (ret == AVERROR(ENOSYS)) {
av_log(s, AV_LOG_WARNING, "not writing 'chan' tag due to "
"lack of channel information\n");
ret = 0;
}
return ret;
}
num_desc = layout_tag ? 0 : track->par->ch_layout.nb_channels;
avio_wb32(pb, 0); // Size
ffio_wfourcc(pb, "chan"); // Type
avio_w8(pb, 0); // Version
avio_wb24(pb, 0); // Flags
avio_wb32(pb, layout_tag); // mChannelLayoutTag
avio_wb32(pb, bitmap); // mChannelBitmap
avio_wb32(pb, 0); // mNumberChannelDescriptions
avio_wb32(pb, num_desc); // mNumberChannelDescriptions
for (int i = 0; i < num_desc; i++) {
avio_wb32(pb, channel_desc[i]); // mChannelLabel
avio_wb32(pb, 0); // mChannelFlags
avio_wl32(pb, 0); // mCoordinates[0]
avio_wl32(pb, 0); // mCoordinates[1]
avio_wl32(pb, 0); // mCoordinates[2]
}
av_free(channel_desc);
return update_size(pb, pos);
}