2016-11-21 55 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);