<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 21, 2013, at 9:28 AM, Paul B Mahol <<a href="mailto:onemda@gmail.com">onemda@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I don't see any problem, ffmpeg can resample and encode at same time.<br></blockquote><div><br></div>I didn't see any problem in principle either. In practice, it all works fine until encountering an audio device with a lower sample rate that pushes the resampled frame size above the codec's max frame size, then it blows up. Here's the problem:</div><div><br></div><div>source sample rate = 16000</div><div>source number of samples = 512</div><div>destination sample rate = 44100</div><div>(using libmp3lame, which sets its frame size to 1152). </div><div><br></div><div>if you resample prior to encoding, av_encode_audio2 fails with error -22, due to libavcodec's utils.c line 1208 as the result of this check in the preceding line failing: </div><br>           if (frame->nb_samples > avctx->frame_size) {<div><br></div><div>If you do it your suggested way, letting av_encode_audio2 handle both the resampling and encoding, FFmpeg crashes outright. </div><div><br><img id="e490e78a-89c1-43ca-9bf9-dccd208f6fb8" height="43" width="272" apple-width="yes" apple-height="yes" src="cid:7F093885-4E99-4189-B297-A052D87A3EE8"></div><div><br></div><div>However, if you use a source sample rate of 44100, or 48000 (no other changes to above data) everything works fine. That's the problem. </div><div><br></div><div>Brad</div></body></html>