From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 6/7] avformat/movenc: don't use mono layout when a front center label is expected Date: Mon, 28 Mar 2022 20:24:52 -0300 Message-ID: <20220328232453.54773-6-jamrial@gmail.com> (raw) In-Reply-To: <20220328232453.54773-1-jamrial@gmail.com> 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> --- libavformat/movenc.c | 25 +++++++++++++++++++++++++ libavformat/movenc.h | 1 + 2 files changed, 26 insertions(+) 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; -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-03-28 23:26 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-28 23:24 [FFmpeg-devel] [PATCH 1/7] avformat/mov_chan: rename mov_get_channel_label() to better reflect its purpose James Almer 2022-03-28 23:24 ` [FFmpeg-devel] [PATCH 2/7] avformat/mov_chan: add a few missing channel label mappings James Almer 2022-03-28 23:24 ` [FFmpeg-devel] [PATCH 3/7] avformat/mov_chan: use a higher log level for a debug message James Almer 2022-03-28 23:24 ` [FFmpeg-devel] [PATCH 4/7] avformat/movenc: write channel descriptions when a known layout or a bitmap can't be used James Almer 2022-03-28 23:24 ` [FFmpeg-devel] [PATCH 5/7] avformat/mov_chan: move the definition of MovChannelLayoutTag to the header James Almer 2022-03-28 23:24 ` James Almer [this message] 2022-03-28 23:24 ` [FFmpeg-devel] [PATCH 7/7] fate: add a test for writing channel descriptions in mov James Almer 2022-04-05 12:20 ` [FFmpeg-devel] [PATCH 1/7] avformat/mov_chan: rename mov_get_channel_label() to better reflect its purpose James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220328232453.54773-6-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git