<div dir="ltr">Hi guys,
<div><br></div><div>I'm working on an iOS app that allows people to turn specific channels on or off while playing videos with surround audio tracks. I'm using kxmovie (<a href="https://github.com/kolyvan/kxmovie">https://github.com/kolyvan/kxmovie</a>) as the base for it.</div>
<div><br></div><div>The render callback on the audio unit is currently calling swresample, which is remixing sound to match the 2-ch output of the Apple remote I/O. As you probably know, different audio codecs encode their channels in different orders, so I can't just always ask for the second channel in an audio track, for example.</div>
<div><br></div><div>Is there a way for me to get a specific audio channel in mono (e.g. ask for surround left and let ffmpeg figure out which one it is for the selected codec) or to get it to set a default channel order and reorder it if the format doesn't match it (which would then allow me to always point to the same channel number if I want the surround left channel, for example).</div>
<div><br></div><div>Right now this is the code I have for the buffer:</div><div><br></div><div><div>- (kxMovieError) openAudioStream: (NSInteger) audioStream</div><div>{ </div><div> AVCodecContext *codecCtx = _formatCtx->streams[audioStream]->codec;</div>
<div> SwrContext *swrContext = NULL;</div><div> </div><div> AVCodec *codec = avcodec_find_decoder(codecCtx->codec_id);</div><div> if(!codec)</div><div> return kxMovieErrorCodecNotFound;</div><div>
</div><div> if (avcodec_open2(codecCtx, codec, NULL) < 0)</div><div> return kxMovieErrorOpenCodec;</div><div> </div><div> if (!audioCodecIsSupported(codecCtx)) {</div><div><br></div><div> id<KxAudioManager> audioManager = [KxAudioManager audioManager];</div>
<div> swrContext = swr_alloc_set_opts(NULL,</div><div> av_get_default_channel_layout(audioManager.numOutputChannels),</div><div> AV_SAMPLE_FMT_S16,</div>
<div> audioManager.samplingRate,</div><div> av_get_default_channel_layout(codecCtx->channels),</div><div> codecCtx->sample_fmt,</div>
<div> codecCtx->sample_rate,</div><div> 0,</div><div> NULL);</div><div> </div><div> if (!swrContext ||</div>
<div> swr_init(swrContext)) {</div><div> </div><div> if (swrContext)</div><div> swr_free(&swrContext);</div><div> avcodec_close(codecCtx);</div><div><br></div>
<div> return kxMovieErroReSampler;</div><div> }</div><div> }</div><div> </div><div> _audioFrame = avcodec_alloc_frame();</div><div> if (!_audioFrame) {</div><div> if (swrContext)</div>
<div> swr_free(&swrContext);</div><div> avcodec_close(codecCtx);</div><div> return kxMovieErrorAllocateFrame;</div><div> }</div><div> </div><div> _audioStream = audioStream;</div><div>
_audioCodecCtx = codecCtx;</div><div> _swrContext = swrContext;</div><div> </div><div> AVStream *st = _formatCtx->streams[_audioStream];</div><div> avStreamFPSTimeBase(st, 0.025, 0, &_audioTimeBase);</div>
<div> </div><div> return kxMovieErrorNone; </div><div>}</div></div><div><br></div><div>Can you help me out? Thanks!</div></div>