Search code examples
c++encodingffmpegaactranscoding

FFMPEG Malformed AAC bitstream detected : use the audio bitstream filter 'aac_adtstoasc' to fix it error


I am working with ffmpeg transcoding.c example. When i set video encoder codec to AV_CODEC_ID_H264 and audio encoder codec to AV_CODEC_ID_AAC I got following error.

enter image description here

How can i fix this problem.


Solution

  • First of all, thanks for the answers.

    Solution of the my problem is AVBitStreamFilterContext*. I added following lines into the "encode_write_frame" method and it is ok.

    if(ifmt_ctx->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO && ifmt_ctx->streams[stream_index]->codec->codec_id == AV_CODEC_ID_H264){
        AVBitStreamFilterContext* h264BitstreamFilterContext = av_bitstream_filter_init("h264_mp4toannexb");
        av_bitstream_filter_filter(h264BitstreamFilterContext, ofmt_ctx->streams[stream_index]->codec, NULL, &enc_pkt.data, &enc_pkt.size, enc_pkt.data, enc_pkt.size, 0);
    } else if(ifmt_ctx->streams[stream_index]->codec->codec_id == AV_CODEC_ID_AAC) {        
        AVBitStreamFilterContext* aacBitstreamFilterContext = av_bitstream_filter_init("aac_adtstoasc");
        av_bitstream_filter_filter(aacBitstreamFilterContext, ofmt_ctx->streams[stream_index]->codec, NULL, &enc_pkt.data, &enc_pkt.size, enc_pkt.data, enc_pkt.size, 0);
    }