ffmpeg保存avframe中pcm数据到文件。 代码如下:
data_size &#61; av_get_bytes_per_sample(dec_ctx->sample_fmt);if (data_size < 0) {LOGI("get size error");return -1;}LOGI("audio frame size:%d---%d---%d", data_size, frame->nb_samples, frame->sample_rate);frameBufferSize &#61; frame->nb_samples*data_size*dec_ctx->channels;if (frameBuf&#61;&#61;NULL){frameBuf&#61; static_cast<unsigned char *>(malloc(static_cast<size_t>(frameBufferSize)));}sum&#61;0;for (i &#61; 0; i < frame->nb_samples; i&#43;&#43;){for (ch &#61; 0; ch < dec_ctx->channels; ch&#43;&#43;){memcpy(frameBuf&#43;sum, frame->data[ch] &#43; data_size*i,static_cast<size_t>(data_size));sum&#43;&#61;data_size;}}
如果对你有用记得点赞&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;