我目前正在尝试使用 avi 容器内的一些视频对一些原始音频数据进行编码。
使用的视频编解码器是 mpeg4,我想使用 PCM_16LE 作为音频编解码器,但我遇到了有关音频样本的 AVCodec->frame_size 参数的问题。
完成所有正确的分配后,我尝试分配音频帧,对于 AV_CODEC_ID_PCM_S16LE 编解码器,我没有获取样本缓冲区大小所需的编解码器frame_size。因此样本缓冲区大小很大,我根本无法分配这么大的内存量。 有人知道如何绕过这个问题以及如何手动计算frame_size吗?
frame = av_frame_alloc();
if(!frame)
{
return NULL;
}
//Problem is right here with the frame_size
frame->nb_samples = m_pAudioCodecContext->frame_size;
frame->format = m_pAudioStream->codec->sample_fmt;
frame->channel_layout = m_pAudioStream->codec->channel_layout;
//The codec gives us the frame size, in samples, so we can calculate the size of the samples buffer in bytes
//This returns a huge value due to a null frame_size
m_audioSampleBufferSize = av_samples_get_buffer_size(NULL,
m_pAudioCodecContext->channels,
m_pAudioCodecContext->frame_size,
m_pAudioCodecContext->sample_fmt,
0);
谢谢您的帮助,
罗伯特
正如您在 pcm_encode_init
中的
pcm.c
函数中看到的
所有
pcm
编码器都有 frame_size = 0;
。为什么?
因为在所有 PCM 格式中“事实上”没有像帧这样的东西,所以
PCM
本质上不存在压缩。
所以你应该自己决定要在缓冲区中存储多少样本