请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

aac文件打不开

问题描述:音频进行aac编码后生成aac文件,使用命令 ffplay ./audio.aac报如下的错误:
录制过程中的输出:

[aac @ 0x153047000] Trying to remove 512 more samples than there are in the queue
[aac @ 0x153047000] Trying to remove 512 more samples than there are in the queue
[aac @ 0x153047000] Trying to remove 512 more samples than there are in the queue
[aac @ 0x153047000] Trying to remove 512 more samples than there are in the queue
[aac @ 0x153047000] Trying to remove 512 more samples than there are in the queue
[aac @ 0x153047000] Trying to remove 512 more samples than there are in the queue
[aac @ 0x153047000] Qavg: 120.549
finish!

Process finished with exit code 0

播放过程中的输出

[aac @ 0x121104080] Format aac detected only with low score of 1, misdetection possible!
[aac @ 0x14180f7d0] Error decoding AAC frame header.
[aac @ 0x14180f7d0] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[aac @ 0x14180f7d0] Assuming an incorrectly encoded 7.1 channel layout instead of a spec-compliant 7.1(wide) layout, use -strict 1 to decode according to the specification instead.
[aac @ 0x14180f7d0] Number of bands (7) exceeds limit (5).
[aac @ 0x14180f7d0] Multiple frames in a packet.
[aac @ 0x14180f7d0] channel element 3.0 is not allocated
[aac @ 0x14180f7d0] channel element 3.12 is not allocated
[aac @ 0x14180f7d0] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x14180f7d0] Inconsistent channel configuration.
[aac @ 0x14180f7d0] get_buffer() failed
[aac @ 0x14180f7d0] channel element 3.5 is not allocated
[aac @ 0x14180f7d0] channel element 1.1 is not allocated
[aac @ 0x14180f7d0] Reserved bit set.
[aac @ 0x14180f7d0] Number of bands (39) exceeds limit (32).
[aac @ 0x14180f7d0] Reserved bit set.
[aac @ 0x14180f7d0] Pulse data corrupt or invalid.
[aac @ 0x14180f7d0] channel element 2.8 is not allocated
[aac @ 0x14180f7d0] channel element 2.0 is not allocated
[aac @ 0x14180f7d0] Reserved bit set.
[aac @ 0x14180f7d0] Pulse tool not allowed in eight short sequence.
[aac @ 0x14180f7d0] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x14180f7d0] Inconsistent channel configuration.
[aac @ 0x14180f7d0] get_buffer() failed
[aac @ 0x14180f7d0] Number of scalefactor bands in group (15) exceeds limit (12).
[aac @ 0x14180f7d0] channel element 3.9 is not allocated
[aac @ 0x14180f7d0] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x14180f7d0] Inconsistent channel configuration.
[aac @ 0x14180f7d0] get_buffer() failed
[aac @ 0x14180f7d0] Gain control is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[aac @ 0x14180f7d0] channel element 3.14 is not allocated
[aac @ 0x14180f7d0] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x14180f7d0] Inconsistent channel configuration.
[aac @ 0x14180f7d0] get_buffer() failed
[aac @ 0x14180f7d0] channel element 3.3 is not allocated
[aac @ 0x14180f7d0] channel element 2.9 is not allocated
[aac @ 0x14180f7d0] Reserved bit set.
[aac @ 0x14180f7d0] Number of bands (55) exceeds limit (41).
[aac @ 0x14180f7d0] channel element 2.4 is not allocated
[aac @ 0x14180f7d0] channel element 3.9 is not allocated
[aac @ 0x121104080] Packet corrupt (stream = 0, dts = NOPTS).
[aac @ 0x14180f7d0] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x121104080] Estimating duration from bitrate, this may be inaccurate
[aac @ 0x121104080] Could not find codec parameters for stream 0 (Audio: aac (LTP), 7.1, fltp, 441 kb/s): unspecified sample rate
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, aac, from './audio.aac':
  Duration: 00:00:01.33, bitrate: 450 kb/s
  Stream #0:0: Audio: aac (LTP), 7.1, fltp, 441 kb/s
Failed to open file './audio.aac' or configure filtergraph

我的尝试:
1. 不编码,仅仅采集声音数据,将声音数据进行重采样,参数设置为AV_CH_LAYOUT_MONO, AV_SAMPLE_FMT_FLT,48000, 保存成pcm数据,使用命令ffplay -ar 48000 -ac 1 -f f32le ./audio.pcm 可以正常播放。
2. 我的ffmpeg的版本为4.0.6版本,我看老师的课程录制是在两年前,我就选择两年前的版本
3. 将编码器:codec_ctx->profile = FF_PROFILE_AAC_HE_V2 改为codec_ctx->profile = FF_PROFILE_AAC_LD; 还是无法打开aac。
4. ret = avcodec_receive_packet(ctx, pkt); 第一次 ret为-35, 我加了:

if(ret == -35){
            av_usleep(10000);
            continue;
        }

还是无法打开aac

最后是我的代码:里面的设置的参数,是我在保证,重采样后的音频数据能正常播放的参数

static void encode(AVCodecContext *ctx,
                   AVFrame *frame,
                   AVPacket *pkt,
                   FILE *output){

    int ret = 0;

    //将数据送编码器
    ret = avcodec_send_frame(ctx, frame);

    //如果ret>=0说明数据设置成功
    while(ret >= 0){


        //获取编码后的音频数据,如果成功,需要重复获取,直到失败为止
        ret = avcodec_receive_packet(ctx, pkt);

        if(ret == -35){
            av_usleep(10000);
            continue;
        }

        if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
            return;
        }else if( ret < 0){
            printf("Error, encoding audio frame\n");
            exit(-1);
        }

        //write file
        fwrite(pkt->data, 1, pkt->size, output);
        fflush(output);
    }

    return;
}
static AVCodecContext* open_coder(){

    //打开编码器
    //avcodec_find_encoder(AV_CODEC_ID_AAC);
//    AVCodec *codec = avcodec_find_encoder_by_name("libfdk_aac");
    AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_AAC);

    //创建 codec 上下文
    AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);

    codec_ctx->sample_fmt =AV_SAMPLE_FMT_FLT;          //输入音频的采样大小
    codec_ctx->channel_layout = AV_CH_LAYOUT_MONO;    //输入音频的channel layout
    codec_ctx->channels = 1;                            //输入音频 channel 个数
    codec_ctx->sample_rate = 48000;                     //输入音频的采样率
    codec_ctx->bit_rate = 0; //AAC_LC: 128K, AAC HE: 64K, AAC HE V2: 32K
    codec_ctx->profile = FF_PROFILE_AAC_LD; //阅读 ffmpeg 代码

    //打开编码器
    if(avcodec_open2(codec_ctx, codec, NULL)<0){
        //

        return NULL;
    }

    return codec_ctx;
}
static
SwrContext* init_swr(){

    SwrContext *swr_ctx = NULL;

    //channel, number/
    swr_ctx = swr_alloc_set_opts(NULL,                //ctx
                                 AV_CH_LAYOUT_MONO, //输出channel布局
                                 AV_SAMPLE_FMT_FLT,   //输出的采样格式
                                 48000,               //采样率
                                 AV_CH_LAYOUT_MONO, //输入channel布局
                                 AV_SAMPLE_FMT_FLT,   //输入的采样格式
                                 48000,               //输入的采样率
                                 0, NULL);

    if(!swr_ctx){

    }

    if(swr_init(swr_ctx) < 0){

    }

    return swr_ctx;
}

正在回答 回答被采纳积分+3

插入代码

1回答

李超 2022-06-28 15:18:35

profile 设置为...PROFILE_AAC_HE,另外编码时,设置的参数是重采样后的参数,检查一下设置对没

0 回复 有任何疑惑可以回复我~
  • 提问者 weixin_慕沐9189930 #1
    1.  设置:codec_ctx->profile = FF_PROFILE_AAC_HE;  还是同样的报错
    
    2. 为了干扰,我已经将所有参数都是成一样的了,而且这样的参数能保证重采样后的数据能正常播放:
    重采样的数据,还是报同样的错误。
        //channel, number/
        swr_ctx = swr_alloc_set_opts(NULL,                //ctx
                                     AV_CH_LAYOUT_MONO, //输出channel布局
                                     AV_SAMPLE_FMT_FLT,   //输出的采样格式
                                     48000,               //采样率
                                     AV_CH_LAYOUT_MONO, //输入channel布局
                                     AV_SAMPLE_FMT_FLT,   //输入的采样格式
                                     48000,               //输入的采样率
                                     0, NULL);
    回复 有任何疑惑可以回复我~ 2022-06-28 15:57:16
  • 提问者 weixin_慕沐9189930 #2
    缓冲区:
        //创建输入缓冲区
        av_samples_alloc_array_and_samples(src_data,         //输出缓冲区地址
                                           src_linesize,     //缓冲区的大小
                                           1,                 //通道个数
                                           512,               //单通道采样个数
                                           AV_SAMPLE_FMT_FLT, //采样格式
                                           0);
    
        //创建输出缓冲区
        av_samples_alloc_array_and_samples(dst_data,         //输出缓冲区地址
                                           dst_linesize,     //缓冲区的大小
                                           1,                 //通道个数
                                           512,               //单通道采样个数
                                           AV_SAMPLE_FMT_FLT, //采样格式
                                           0);
    回复 有任何疑惑可以回复我~ 2022-06-28 15:57:31
  • 提问者 weixin_慕沐9189930 #3
    重采样:
            swr_convert(swr_ctx,                    //重采样的上下文
                        dst_data,                   //输出结果缓冲区
                        512,                        //每个通道的采样数
                        (const uint8_t **)src_data, //输入缓冲区
                        512);                       //输入单个通道的采样数
    回复 有任何疑惑可以回复我~ 2022-06-28 15:57:57
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号