You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于FDK-AAC实现RTP/RTSP最简AAC音频流配置求助

寻求FDK-AAC编码器、SDP与RTP头的最简配置方案

我需要配置FDK-AAC编码器、SDP头和RTP头,实现可被ffplay或vlc播放的最小可行RTP音频流(最简指手动配置与搭建工作量最少)。输入为单声道16位PCM数据,已确认以下fdk-aac配置可将其编码为ffplay能正常播放的AAC文件:

aacEncoder_SetParam(aac_handle, AACENC_AOT, AOT_AAC_LC);
aacEncoder_SetParam(aac_handle, AACENC_BITRATE, 96000);
aacEncoder_SetParam(aac_handle, AACENC_SAMPLERATE, 16000);
aacEncoder_SetParam(aac_handle, AACENC_CHANNELMODE, MODE_1);
aacEncoder_SetParam(aac_handle, AACENC_BANDWIDTH, 0);
aacEncoder_SetParam(aac_handle, AACENC_CHANNELORDER, 1);
aacEncoder_SetParam(aac_handle, AACENC_AFTERBURNER, 1);
aacEncoder_SetParam(aac_handle, AACENC_SBR_MODE, 0);
aacEncoder_SetParam(aac_handle, AACENC_SBR_RATIO, 0);
aacEncoder_SetParam(aac_handle, AACENC_TRANSMUX, TT_MP4_LOAS);
aacEncoder_SetParam(aac_handle, AACENC_SIGNALING_MODE, 0);

同时已确认以下SDP与RTP头配置可将原始PCM数据流传输至ffplay:

char sdp[] = "v=0\r\n"
"o=- 0 0 IN IP4 127.0.0.1\r\n"
"s=Unnamed\r\n"
"c=IN IP4 127.0.0.1\r\n"
"a=recvonly\r\n"
"a=charset:UTF-8\r\n"
"m=audio 50040 RTP/AVP 100\r\n"
"a=rtpmap:100 L16/16000\r\n";

// 发送循环中的头设置:
hdr.flags = 0x80;
hdr.mk_pt = 0x80 | 100;
hdr.sq_nb = htons(rtp_packet_count);
hdr.ts = htonl(rtp_timestamp_audio);
hdr.ssrc = htonl(10);
...
// 后续更新包计数和时间戳

但尝试通过RT(S)P流传输AAC时始终失败,试过修改编码器transmux参数(如TT_MP4_LATM_MCP1)、调整SDP包和RTP头,最近的尝试配置如下:

char sdp_aac[] =
"v=0\r\n"
"o=- 0 0 IN IP4 0.0.0.0\r\n"
"s=Unnamed\r\n"
"c=IN IP4 0.0.0.0\r\n"
"a=recvonly\r\n"
"a=charset:UTF-8\r\n"
"m=audio 0 RTP/AVP 97\r\n"
"a=rtpmap:97 MP4A-LATM/16000/1\r\n"
"a=fmtp:97 cpresent=1; config=400028100000\r\n";

// 发送循环中的头设置:
hdr.flags = 0x80;
hdr.mk_pt = 0x80 | 97;
hdr.sq_nb = htons(rtp_packet_count);
hdr.ts = htonl(rtp_timestamp_audio);
hdr.ssrc = htonl(10);

这导致ffplay持续输出大量错误:

[rtsp @ 0x7f79e4000bc0] RTP MP4A-LATM with in-band configuration is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[rtsp @ 0x7f79e4000bc0] If you want to help, upload a sample of this file to ftp://upload.ffmpeg.org/incoming/ and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)
[aac @ 0x7f79e40046c0] Number of bands (31) exceeds limit (16)./0   
Input #0, rtsp, from 'rtsp://10.66.171.29':
  Metadata:
    title           : Unnamed
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Audio: aac (LC), 16000 Hz, mono, fltp
[rtsp @ 0x7f79e4000bc0] Malformed LATM packet
    Last message repeated 1 times
[aac @ 0x7f79e40b6680] Number of bands (31) exceeds limit (16).
[rtsp @ 0x7f79e4000bc0] Malformed LATM packet
    Last message repeated 1 times
[aac @ 0x7f79e40b6680] channel element 3.4 is not allocated
[rtsp @ 0x7f79e4000bc0] Malformed LATM packet
[aac @ 0x7f79e40b6680] channel element 3.4 is not allocated
    Last message repeated 2 times
[aac @ 0x7f79e40b6680] Sample rate index in program config element does not match the sample rate index configured by the container.
[aac @ 0x7f79e40b6680] decode_pce: Input buffer exhausted before END element found
[rtsp @ 0x7f79e4000bc0] Malformed LATM packet 0KB sq=    0B f=0/0   
    Last message repeated 1 times
[rtsp @ 0x7f79e4000bc0] Malformed LATM packet 0KB sq=    0B f=0/0   
    Last message repeated 1 times
[rtsp @ 0x7f79e4000bc0] Malformed LATM packet 0KB sq=    0B f=0/0   
    Last message repeated 1 times
[aac @ 0x7f79e40b6680] Number of bands (31) exceeds limit (16).
[aac @ 0x7f79e40b6680] channel element 2.10 is not allocated
[aac @ 0x7f79e40b6680] skip_data_stream_element: Input buffer exhausted before END element found
[aac @ 0x7f79e40b6680] SBR was found before the first channel element.
[aac @ 0x7f79e40b6680] Reserved bit set.
...
错误持续输出

VLC仅报告:main decoder error: buffer deadlock prevented。

不确定是传输类型、编码器配置(见第一条ffplay错误)、头/SDP还是数据包封装发送方式出错(可能多种因素组合)。刚接触AAC/流媒体/RTP/RTSP,希望找出正确的编码器设置和SDP参数,实现ffplay或vlc可播放的最简音频流。已阅读RFC 5691、6416和3550,但信息过多,对配置项感到困惑。


编辑1

现在已实现“流传输”(虽有卡顿但可识别),使用的配置如下:

// 编码器配置:未列出的参数与之前一致
aacEncoder_SetParam(aac_handle, AACENC_TRANSMUX, TT_MP4_ADTS)
// SDP:
char sdp_aac[] =
"v=0\r\n"
"o=- 0 0 IN IP4 0.0.0.0\r\n"
"s=Unnamed\r\n"
"c=IN IP4 0.0.0.0\r\n"
"a=recvonly\r\n"
"a=charset:UTF-8\r\n"
"m=audio 50040 RTP/AVP 97\r\n"
"a=rtpmap:97 mpeg4-generic/16000/1\r\n"
"a=fmtp:97 config=1408\r\n"; // config十六进制值来自编码器配置二进制数据
// RTP包头设置:
hdr.flags = 0x80;
hdr.mk_pt = 0x80 | 97;
hdr.sq_nb = htons(rtp_packet_count);
hdr.ts = htonl(rtp_timestamp_audio);
hdr.ssrc = htonl(10);

但ffplay仍重复输出错误且无音频:[rtsp @ 0x7fc3d8000bc0] Error parsing AU headers


内容的提问来源于stack exchange,提问作者Douglas B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 08:05:02