【发布时间】:2016-09-05 03:57:03
【问题描述】:
我目前正在尝试在 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);
感谢您的帮助,
罗伯特
【问题讨论】: