[FFmpeg-cvslog] avformat/mov_chan: never override number of channels based on chan atom

Marton Balint git at videolan.org
Mon Feb 12 00:27:19 EET 2024


ffmpeg | branch: release/5.1 | Marton Balint <cus at passwd.hu> | Mon Jan 29 20:15:28 2024 +0100| [352fe0d4bf09b170245787fab1d70878b01aeb3d] | committer: Marton Balint

avformat/mov_chan: never override number of channels based on chan atom

The channel designation metadata should not override the number of channels.
Let's warn the user if it is inconsistent, and keep the channel layout
unspecified.

Before the conversion to the channel layout API the code only set the mask, but
never overridden the channel count, so this restores the old behaviour.

Signed-off-by: Marton Balint <cus at passwd.hu>
(cherry picked from commit dc9d64f7941f5b071283e16fa56e3af86e5c84d6)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=352fe0d4bf09b170245787fab1d70878b01aeb3d
---

 libavformat/mov_chan.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index 5863018a79..dc26399eee 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -548,8 +548,13 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
         mask = mov_get_channel_layout(layout_tag, bitmap);
 
     if (mask) {
-        av_channel_layout_uninit(&st->codecpar->ch_layout);
-        av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
+        if (!st->codecpar->ch_layout.nb_channels || av_popcount64(mask) == st->codecpar->ch_layout.nb_channels) {
+            av_channel_layout_uninit(&st->codecpar->ch_layout);
+            av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
+        } else {
+            av_log(s, AV_LOG_WARNING, "ignoring channel layout with %d channels because the real number of channels is %d\n",
+                   av_popcount64(mask), st->codecpar->ch_layout.nb_channels);
+        }
     }
     avio_skip(pb, size - 12);
 



More information about the ffmpeg-cvslog mailing list