[FFmpeg-devel] [PATCH]Warn if the flac encoder outputs files with incorrect channel layout or guesses the channel layout

Carl Eugen Hoyos cehoyos at ag.or.at
Mon Apr 25 01:43:40 CEST 2011


Hi!

Attached patch allows the flac encoder to warn if multichannel audio was 
provided, but no channel layout defined, and shows an error if the specified 
layout is different from the one flac supports (but still encodes).

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index 051de69..637d09d 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -425,6 +425,28 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
     if (!avctx->coded_frame)
         return AVERROR(ENOMEM);
 
+    if (channels == 3 &&
+            avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
+        channels == 4 &&
+            avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
+            avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
+        channels == 5 &&
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
+        channels == 6 &&
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
+            avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) {
+        if (avctx->channel_layout) {
+            av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, "
+                                             "output stream will have incorrect "
+                                             "channel layout.\n");
+        } else {
+            av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder "
+                                               "will use Flac channel layout for "
+                                               "%d channels.\n", channels);
+        }
+    }
+
     ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size,
                       s->options.max_prediction_order, AV_LPC_TYPE_LEVINSON);
 


More information about the ffmpeg-devel mailing list