FFmpeg:编码PCM 16音频数据分配错误 [英] FFmpeg: Encoding PCM 16 audio data Allocation error
问题描述
我使用的视频编解码器是mpeg4,我想使用PCM_16LE对于音频编解码器,但我面临有关音频样本的 AVCodec-> frame_size 参数的问题。
完成所有正确的分配,我尝试分配音频帧和AV_CODEC_ID_PCM_S16LE编解码器我没有编解码器frame_size需要获得样本缓冲区大小。因此,示例缓冲区大小巨大,我根本不能分配这么多的内存。
有人知道如何绕过这个问题,以及如何手动计算frame_size?
frame = av_frame_alloc
中的主/ libavcodec / pcm.c#L36rel =nofollow>
if(!frame)
{
return NULL;
}
//问题就在这里与frame_size
frame-> nb_samples = m_pAudioCodecContext-> frame_size;
frame-> format = m_pAudioStream-> codec-> sample_fmt;
frame-> channel_layout = m_pAudioStream-> codec-> channel_layout;
//编解码器给出了帧大小(以样本为单位),因此我们可以计算样本缓冲区的大小(以字节为单位)
//由于null frame_size,返回一个巨大的值b $ b m_audioSampleBufferSize = av_samples_get_buffer_size(NULL,
m_pAudioCodecContext-> channels,
m_pAudioCodecContext-> frame_size,
m_pAudioCodecContext-> sample_fmt,
0);感谢您的帮助,
$ b Robert解决方案正如你可以在 pcm.c
pcm_encode_init
a>
所有
pcm
编码器都有frame_size = 0;
。为什么?
因为在所有的PCM格式中,事实上没有像框架这样的东西,没有压缩
PCM
因此,您应该自行决定要在缓冲区中存储多少个样本
I am currently trying to encode some raw audio data with some video inside an avi container.
The video codec used is mpeg4 and I would like to use the PCM_16LE for the audio codec but I am facing a problem regarding the AVCodec->frame_size parameter for the audio samples.
After doing all the correct allocation, I try allocating the audio frame and for AV_CODEC_ID_PCM_S16LE codec I don't have the codec frame_size needed to get the samples buffer size. Therefore the sample buffer size is huge and I simply can't allocate such quantity of memory. Does someone know how to bypass this issue and how to manually compute the 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);
Thank you for your help,
Robert
解决方案As you can see in
pcm_encode_init
function inpcm.c
All
pcm
encoders haveframe_size = 0;
. Why?Because in all PCM formats 'De facto' no such thing like frame, there is no compression by nature of
PCM
.So you should decide by your own how many samples you wanna to store in buffer
这篇关于FFmpeg:编码PCM 16音频数据分配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!