I have had a strange question lately. Depending on how I configured my sound configuration in windows (stereo / quad / 5.1), the ffmpeg call for avcodec_open2 () failed with a -22 error or just works. Unable to find much about this error, I thought I should ask about it here. The main thread is as follows:
c = st->codec; avformat_alloc_output_context2(&oc, NULL, NULL, "video.mpeg"); oc->fmt->audio_codec = AV_CODEC_ID_MP2; AVDictionary* dict = NULL; ret = av_dict_set(&dict, "ac", "2", 0); c->request_channels = 2; ret = avcodec_open2(c, codec, &dict);
The codec context 'c' is set this way in the stream:
st = avformat_new_stream(oc, *codec); c = st->codec; c->channels = 2; c->channel_layout = AV_CH_LAYOUT_STEREO; c->sample_fmt = AV_SAMPLE_FMT_S16; c->codec_id = codec_id;
Most of it is copied from one of the multiplexer examples found in the documentation. Everything works as expected if on Windows I set the output to stereo.
If I configure the speaker configuration to 5.1 (6 channels), avcodec_open2 will fail with a -22 error.
So it's hard for me to understand what I'm doing wrong. Usually this should not be any connection between my speaker configuration and the result of avcodec_open2.
Are there any other parameters that I need to set?
source share