FFmpeg:编码PCM 16音频数据分配错误

Rob*_*nes 1 c++ audio ffmpeg pcm

我目前正在尝试在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);
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助,

罗伯特

CAM*_*BAP 5

正如你可以看到在pcm_encode_init功能pcm.c

所有pcm编码器都有frame_size = 0;。为什么?

因为在所有“事实上”的PCM格式中,都没有像帧这样的东西,所以没有本质上的压缩PCM

因此,您应该自己决定要在缓冲区中存储多少个样本