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

doğan  picture doğan · Oct 15, 2015 · Viewed 8.4k times · Source

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.

Answer

doğan  picture doğan · Oct 16, 2015

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);
}