我的frame采样数是2048,直接编码aac格式会失败,采用重采样的方式,把一个frame拆分成两个采样数1024的frame,不需要依赖缓冲。
// 2014个重采样为1024个 int count = swr_convert(swr, outs, AAC_ENCODE_SIZE, (const uint8_t **)pFrameOut->extended_data, pFrameOut->nb_samples); if (count < 0){ LOGD("swr_convert error 1 ret = %d, %s", count, av_err2str(count)); } else { LOGD("count = %d, outs[0] = %s, outs[1] = %s", count, NULL, NULL/*outs[0], outs[1]*/); pFrameOut->nb_samples = count;//aac 为1024 pFrameOut->data[0] = (uint8_t*)outs[0]; pFrameOut->data[1] = (uint8_t*)outs[1]; } // 进行编码 encode: ret = avcodec_encode_audio2(pOutFormatCtx->streams[audioIndex]->codec, &enc_pkt, pFrameOut, &enc_got_frame); **** //重采样剩余的1024个采样,不需要输入数据 count = swr_convert(swr, outs, AAC_ENCODE_SIZE, NULL, 0); LOGD("cache count = %d, outs[0] = %s, outs[1] = %s", count, NULL, NULL/*outs[0], outs[1]*/); if (count > 0){ pFrameOut->nb_samples = count; pFrameOut->data[0] = (uint8_t*)outs[0]; pFrameOut->data[1] = (uint8_t*)outs[1]; }这种情况下需要注意的是,第二次重采样1024个数据时,不需要输入数据。
