FFMPEG AAC bit detected: use aac_adtstoasc sound bitstream filter to fix the error

I am working with ffmpeg transcoding.c example . When I installed the video codec codec in AV_CODEC_ID_H264 and the audio encoder codec on AV_CODEC_ID_AAC, I received the following error.

enter image description here

How can I fix this problem.

+4
source share
2 answers

First of all, thanks for the answers.

The solution to my problem is AVBitStreamFilterContext *. I added the following lines to the "encode_write_frame" method, and this is normal.

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);
}
+4
source

aac - , , raw aac. Adts AAC , foo.aac .

MP4. MP4 AV_CODEC_FLAG_GLOBAL_HEADER, , , AVCodecContext.extradata. MP4 ( ), .

, CODEC_FLAG_GLOBAL_HEADER?

//ofmt_ctx is AVFormatContext
//enc_ctx is the AVCodecContext of the current stream 
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
    enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;

, . AAC ADTS, H264 SPS PPS.

+4

Source: https://habr.com/ru/post/1611774/


All Articles