summaryrefslogtreecommitdiff
path: root/doc/examples/muxing.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-07-26 22:00:07 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-26 22:01:08 +0200
commitead22f42f4fc078bb60549238233d5862da5a488 (patch)
treef7f84a52fb2db00330f3c5b1dbed01d5eda0a311 /doc/examples/muxing.c
parent9ccb9c8df256dc7a3e525bcc011938866caccce0 (diff)
doc/examples/muxing: pick a supported channel layout if stereo isnt supported by the encoder
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'doc/examples/muxing.c')
-rw-r--r--doc/examples/muxing.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index b979b6d1f7..76169a4911 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -93,6 +93,7 @@ static void add_stream(OutputStream *ost, AVFormatContext *oc,
enum AVCodecID codec_id)
{
AVCodecContext *c;
+ int i;
/* find the encoder */
*codec = avcodec_find_encoder(codec_id);
@@ -116,8 +117,15 @@ static void add_stream(OutputStream *ost, AVFormatContext *oc,
(*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
c->bit_rate = 64000;
c->sample_rate = 44100;
- c->channels = 2;
c->channel_layout = AV_CH_LAYOUT_STEREO;
+ if ((*codec)->channel_layouts) {
+ c->channel_layout = (*codec)->channel_layouts[0];
+ for (i = 0; (*codec)->channel_layouts[i]; i++) {
+ if ((*codec)->channel_layouts[i] == AV_CH_LAYOUT_STEREO)
+ c->channel_layout = AV_CH_LAYOUT_STEREO;
+ }
+ }
+ c->channels = av_get_channel_layout_nb_channels(c->channel_layout);
ost->st->time_base = (AVRational){ 1, c->sample_rate };
break;