[英]How to decode AAC network audio stream using ffmpeg
我使用 ffmpeg 實現了一個網絡視頻播放器(如 VLC)。 但它無法解碼從 IP 攝像機接收的 AAC 音頻流。 它可以解碼其他音頻信號,如 G711、G726 等。我將編解碼器 ID 設置為 AV_CODEC_ID_AAC,並設置 AvCodecContext 的通道和采樣率。 但是 avcodec_decode_audio4 失敗,錯誤代碼為 INVALID_DATA。 我檢查了之前提出的問題,我嘗試使用“config=1408”的媒體格式特定參數向 AvCodecContext 添加額外字節。 我將 extradatabytes 設置為“20”和“8”的 2 個字節,但它也不起作用。 我感謝任何幫助,謝謝。
IP CAMERA SDP:
a=rtpmap:96 mpeg4-generic/16000/1
a=fmtp:96 streamtype=5; profile-level-id=5; mode=AAC-hbr; config=1408; SizeLength=13; IndexLength=3; IndexDeltaLength=3
AVCodec* decoder = avcodec_find_decoder((::AVCodecID)id);//set as AV_CODEC_ID_AAC
AVCodecContext* decoderContext = avcodec_alloc_context3(decoder);
char* test = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi("1408").ToPointer();
unsigned int length;
uint8_t* extradata = parseGeneralConfigStr(test, length);//it is set as 0x14 and 0x08
decoderContext->channels = number_of_channels; //set as 1
decoderContext->sample_rate = sample_rate; //set as 16000
decoderContext->channel_layout = AV_CH_LAYOUT_MONO;
decoderContext->codec_type = AVMEDIA_TYPE_AUDIO;
decoderContext->extradata = (uint8_t*)av_malloc(AV_INPUT_BUFFER_PADDING_SIZE + length);
memcpy(decoderContext->extradata, extradata, length);
memset(decoderContext->extradata+ length, 0, AV_INPUT_BUFFER_PADDING_SIZE);
您是否檢查了 INVALID_DATA 的數據?
您可以根據RFC進行檢查
AAC有效載荷可以像下面這樣分開AU-Header | Size Info | ADTS | Data
示例有效載荷00 10 0c 00 ff f1 60 40 30 01 7c 01 30 35 ac
根據你分享的配置
AU 大小(SizeLength=13)
AU-Index / AU-Index-delta (IndexLength=3/IndexDeltaLength=3)
AU-Header 的比特長度為13(SizeLength) + 3(IndexLength/IndexDeltaLength) = 16
。
AU-標題00 10
您應該使用 AU-size(SizeLength) 值作為尺寸信息
AU-size:表示同一個RTP包中Access Unit Data Section中相關Access Unit的字節大小。
前 13 (SizeLength) 位0000000000010
等於 2。因此讀取 2 個八位字節以獲取大小信息。
尺寸信息0c 00
ADTS ff f1 60 40 30 01 7c
ADTS解析器
標識 MPEG-4
MPEG 第 0 層
CRC 校驗和缺失 1
配置文件低復雜度配置文件 (AAC LC)
采樣頻率 16000
專用位 0 通道配置 1
原件/復印件 0
主頁 0
版權識別位 0
版權識別開始0
AAC 幀長 384
ADTS 緩沖區填充度 95
第 0 幀中沒有原始數據塊
數據以01 30 35 ac
開頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.