我正在尝试将原始 PCM 音频数据编码为 u-law,这听起来很奇怪(当它听起来......)。我不太了解如何初始化我的AVCodecContext
结构(和我的输入AVFrame
)。
这是我的参数:
输入:PCM(16 位签名)、MONO、44,1kHz(采样率)(来自我的 Android 设备 MIC)
所需输出:G.711 u-law、MONO、8kHz(采样率)、64 kbits/s(比特率)(来自我的输出目标设备的文档)
我也知道我的输入 nb 样本,这就是我拥有的所有信息。
所以我AVCodecContext
像这样初始化我的:
AVCodec* pCodec = avcodec_find_encoder(AV_CODEC_ID_PCM_MULAW);
// ...
AVCodecContext* pCodecContext = avcodec_alloc_context3(pCodec);
// ...
// Do I need input or output params in following lines?
pCodecContext->channels = 1:
pCodecContext->channel_layout = AV_CH_LAYOUT_MONO;
pCodecContext->sample_rate = 8000;
pCodecContext->bit_rate = 64000
pCodecContext->sample_fmt = AV_SAMPLE_FMT_S16;
我AVFrame
喜欢:
AVFrame* pFrame = av_frame_alloc();
pFrame->channels = 1;
pFrame->channel_layout = AV_CH_LAYOUT_MONO;
pFrame->sample_rate = 44100;
pFrame->format = AV_SAMPLE_FMT_S16;
pFrame->nb_samples = /*my audio data samples count*/;
avcodec_fill_audio_frame(pFrame, 1, AV_SAMPLE_FMT_S16, /*my audio data*/, /*my audio data size*/, 0);
avcodec_send_frame()
然后,我用and编码avcodec_receive_packet()
。
所以我的问题是我不确定是否必须在不同的参数中输入或输出所需的值。可能我必须以一种方式进行编码,然后使用swresample
lib 进行“重新采样”。但就目前而言,我很确定我没有正确编码。请问有什么建议吗?谢谢!