[FFmpeg-cvslog] lavc: set channel count from channel layout in avcodec_open2().

Anton Khirnov git at videolan.org
Sat Sep 29 14:46:46 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Fri Sep 28 20:46:20 2012 +0200| [12e1e834611afed8121ccc368a83e7eb5c564565] | committer: Anton Khirnov

lavc: set channel count from channel layout in avcodec_open2().

Some decoders (e.g. nellymoser) only set channel_layout and do not set
channel count.

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

 libavcodec/utils.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c08bad5..7c02d33 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -856,10 +856,15 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
 
     if (av_codec_is_decoder(avctx->codec)) {
         /* validate channel layout from the decoder */
-        if (avctx->channel_layout &&
-            av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) {
-            av_log(avctx, AV_LOG_WARNING, "channel layout does not match number of channels\n");
-            avctx->channel_layout = 0;
+        if (avctx->channel_layout) {
+            int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
+            if (!avctx->channels)
+                avctx->channels = channels;
+            else if (channels != avctx->channels) {
+                av_log(avctx, AV_LOG_WARNING,
+                       "channel layout does not match number of channels\n");
+                avctx->channel_layout = 0;
+            }
         }
     }
 end:



More information about the ffmpeg-cvslog mailing list