summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2022-03-28 14:58:48 -0300
committerJames Almer <jamrial@gmail.com>2022-04-05 09:19:59 -0300
commit7ccc9108032aeaa21b8ad91b201ed19c88b8d239 (patch)
tree8ac10a026bab4d5633bfd5e5f7f3ee111c5682fd /libavformat/movenc.c
parentfeb3b44c1c4681eac096316fde7309192fcecb18 (diff)
avformat/movenc: don't use mono layout when a front center label is expected
On output streams where a multichannel stream needs to be stored as one track per channel, each track will have a channel layout describing the position of the channel they contain. For the track with front center, the mov muxer was using the mov layout "mono" instead of the label for the front center position. Since our channel layout API considers front center == mono, we need to do some heuristics. To achieve this, we make sure all audio tracks contain streams with a single channel, and only one of them is front center. In that case, we write the front center label instead of signaling mono layout. Fixes the last part of ticket #2865 Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r--libavformat/movenc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 263649f1da..b9956e699c 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -887,6 +887,17 @@ static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra
return ret;
}
+ if (layout_tag == MOV_CH_LAYOUT_MONO && track->mono_as_fc > 0) {
+ av_assert0(!channel_desc);
+ channel_desc = av_malloc(sizeof(*channel_desc));
+ if (!channel_desc)
+ return AVERROR(ENOMEM);
+
+ layout_tag = 0;
+ bitmap = 0;
+ *channel_desc = 3; // channel label "Center"
+ }
+
num_desc = layout_tag ? 0 : track->par->ch_layout.nb_channels;
avio_wb32(pb, 0); // Size
@@ -6970,6 +6981,20 @@ static int mov_write_header(AVFormatContext *s)
if (j == i)
continue;
+ if (stj->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ (trackj->par->ch_layout.nb_channels != 1 ||
+ !av_channel_layout_compare(&trackj->par->ch_layout,
+ &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
+ )
+ track->mono_as_fc = -1;
+
+ if (stj->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ av_channel_layout_compare(&trackj->par->ch_layout,
+ &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) &&
+ trackj->par->ch_layout.nb_channels == 1 && track->mono_as_fc >= 0
+ )
+ track->mono_as_fc++;
+
if (stj->codecpar->codec_type != AVMEDIA_TYPE_AUDIO ||
av_channel_layout_compare(&trackj->par->ch_layout,
&(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) ||