summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/movenc.c25
-rw-r--r--libavformat/movenc.h1
2 files changed, 26 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) ||
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 2ac84ed070..67d6d4fb66 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -107,6 +107,7 @@ typedef struct MOVTrack {
int tag; ///< stsd fourcc
AVStream *st;
AVCodecParameters *par;
+ int mono_as_fc;
int multichannel_as_mono;
int vos_len;