2016-11-21 60 views
0

我试图建立一个rtp encoderacc latm support个大气压的编码,但无论我尝试我似乎无法得到它的工作:如何激活与avformatcontext

AVCodec *codec = avcodec_find_encoder_by_name("aac"); 
AVCodecContext *codecCtx = avcodec_alloc_context3(codec); 

AVFormatContext *formatCtx = avformat_alloc_context(); 
avformat_alloc_output_context2(&formatCtx, NULL, "rtp", NULL); 
av_opt_set(m_formatCtx, "rtpflags", "+latm",0); 
formatCtx->flags |= (AVFMT_FLAG_MP4A_LATM | AVFMT_FLAG_BITEXACT); 

AVStream *avStream = avformat_new_stream(formatCtx, codec); 
avStream->codec = codecCtx; 

我使用了错误的编解码器?我跑ffmpeg -codecs | grep latm找到唯一的解码器,所以latm编码只能用作输出格式。我发现rtpenc_chain source的标志。

当我瞄准'MP4A-LATM'时,我的输出总是'MPEG4-GENERIC'。

在此先感谢您的帮助!

回答

0

您需要在标题中添加rtp标志,无需编辑avcontext标志。所以:

AVDictionary *optionsDict = nullptr; 
av_dict_set(&optionsDict, "rtpflags", "latm",0); 
avformat_write_header(formatCtx,&optionsDict) != 0);