[英]FFmpeg: Encoding PCM 16 audio data Allocation error
我目前正在嘗試在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_encode_init
函數中pcm.c
所有pcm
編碼器的frame_size = 0;
。 為什么?
因為在所有PCM格式中,“事實上”都沒有像幀這樣的東西,所以PCM
不會進行壓縮。
因此,您應該自己決定要在緩沖區中存儲多少個樣本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.