FFmpeg: Encoding PCM 16 audio data Allocation error

爱⌒轻易说出口 提交于 2019-12-01 09:55:57

问题


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


回答1:


As you can see in pcm_encode_init function in pcm.c

All pcm encoders have frame_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



来源:https://stackoverflow.com/questions/37134003/ffmpeg-encoding-pcm-16-audio-data-allocation-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!