title: ffmpeg avcodec_open2 returns -22 if I change my speaker configuration
body: <p>I keep having a strange issue lately.
  Depending on how I set up my audio configuration in windows ( stereo/quad/5.1 ), a ffmpeg call to avcodec_open2() fails with error -22 or just works.
  Not being able to find much about that error, I thought I should ask about it here.
  The main flow goes like this:</p>
  
  <pre><code>c = st-&gt;codec;
  avformat_alloc_output_context2(&amp;oc, NULL, NULL, "video.mpeg");
  oc-&gt;fmt-&gt;audio_codec = AV_CODEC_ID_MP2;
  AVDictionary* dict = NULL;
  ret = av_dict_set(&amp;dict, "ac", "2", 0);
  c-&gt;request_channels = 2;
  
  ret = avcodec_open2(c, codec, &amp;dict); //HERE IT FAILS WITH -22 if speaker configuration  is not stereo
  </code></pre>
  
  <p>The codec context 'c' is set up like this in a stream:</p>
  
  <pre><code>st = avformat_new_stream(oc, *codec);
  c = st-&gt;codec;
  c-&gt;channels     = 2;
  c-&gt;channel_layout = AV_CH_LAYOUT_STEREO;
  c-&gt;sample_fmt   = AV_SAMPLE_FMT_S16;
  c-&gt;codec_id     = codec_id;
  </code></pre>
  
  <p>Most of it is copied from their one of the muxing examples found in the documentation.
  Everything works as expected if in windows I have set the output to stereo.</p>
  
  <p>If I set my speaker configuration to 5.1 ( 6 channels ), avcodec_open2 fails with error -22.</p>
  
  <p>So I have a hard time understanding what am I doing wrong. Normally it should not be any relationship between my speaker configuration and the result of avcodec_open2. </p>
  
  <p>Are there some other parameters that I need to set ?</p>