ffmpeg使用AV_CODEC_ID_PCM_MULAW编码器

时间:2016-08-20 23:11:13

标签: c++ audio ffmpeg decoding libavformat

我正在尝试使用ffmpeg初始化AV_CODEC_ID_PCM_MULAW的编码器,但是当我初始化mContext时,它给出0 frame_size是否正确?如果它是正确的,那么我怎样才能找到原始数据的frame_size或nb_sampels。原始数据是pcmu格式。并且av_samples_get_buffer_size函数返回-22,这是无效参数。为什么??

   avcodec_register_all();
   mCodec = avcodec_find_encoder(AV_CODEC_ID_PCM_MULAW);
    if(mCodec == NULL) {
            return -1;
            }
   mContext = avcodec_alloc_context3(mCodec);
    if(mContext == NULL) {
            return -1;
        }
   mContext->channels = numberOfChannel;
   mContext->sample_rate = sampelRate;
   mContext->bit_rate = bitRate;
   mContext->sample_fmt = AV_SAMPLE_FMT_S16;
   mContext->channel_layout = AV_CH_LAYOUT_MONO;
   mContext->channels = 1;
   mContext->sample_rate=8;
        if(mCodecType == Audio_Encoder && !checkSampleFmt(mCodec,mContext->sample_fmt)) {
            return -1;
         }
    if(avcodec_open2(mContext, mCodec, NULL) < 0) {
            return -1;
        }
    mFrame = av_frame_alloc();
    mFrame->nb_samples = mContext->frame_size;
    mFrame->format = mContext->sample_fmt;
    mFrame->channel_layout = 
    mContext->channel_layout;
    int len = av_samples_get_buffer_size(NULL, mContext->channels,
    mContext->frame_size, mContext->sample_fmt, 0);

0 个答案:

没有答案