c++ - 如何使用 ffmpeg 解码 AAC 网络音频流
问题描述
我使用 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 Payload 可以像下面这样分开
AU-Header | Size Info | ADTS | Data
示例有效载荷00 10 0c 00 ff f1 60 40 30 01 7c 01 30 35 ac
根据你共享
AU-size (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 解析器
ID MPEG-4
MPEG 层 0
CRC 校验和不存在 1
Profile Low Complexity Profile (AAC LC)
采样频率 16000
私有位 0 通道配置 1
原始/副本 0
主页 0
版权标识位 0
版权标识开始 0
AAC 帧长度 384
ADTS 缓冲区充满度 95
第 0 帧中没有原始数据块
数据以 开头01 30 35 ac
。
推荐阅读
- node.js - 如何从 Reactjs 和 nodejs 应用程序制作 exe 文件?
- spring - No mapping for GET /springMVC/form.jsp
- r - 尝试使用 ggplot2 在同一个克利夫兰点图上绘制两列
- c# - How to get the width of a photo taken in Xamarin
- cuda - 如何在 GPU 上执行基本操作(+ - * /)并将结果存储在上面
- java - Spring-data 无法更新 id 为 0 的对象
- numpy - 如何从给定列表中的numpy索引的数组中返回项目列表
- jakarta-ee - 大量 Java Native Query 记录在 5 分钟后导致 Exception。javax.ejb.EJBTransactionRolledbackException
- excel - 将一些列附加到另一列,并创建一个单独的列以包含附加的列标题标题
- react-jsonschema-forms - 在 React-JsonSchema-Form 中从表单字段的开头和结尾修剪空格