# 实时消息传输协议

**实时消息传输协议**（Real-Time Messaging Protocol，RTMP）是一种应用层协议，由 [Macromedia](https://www.edgepedia.org/zh/macromedia) 创建——Adobe 后来收购了 Macromedia——用于多路复用和打包多媒体传输流——例如音频、视频和交互内容——使其能够通过 TCP<sup>[1](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)</sup><sup> • </sup><sup>[15](https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Audio_and_video_delivery/Live_streaming_web_audio_and_video)</sup> 等适当的传输协议进行传输。它在可靠的流传输之上提供双向消息多路复用服务，在一对通信对等端之间承载带有相关定时信息的并行视频、音频和数据消息流<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。尽管它是为 Flash 平台而创建的，而 Adobe 已于 2020 年底停止了该平台播放器的支持，但 RTMP 仍然是编码器用于将直播视频推送到流媒体平台的主导贡献（摄取）协议<sup>[3](https://www.adobe.com/support/flash/releasenotes/player/rn_6.html)</sup><sup> • </sup><sup>[4](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一种 Adobe 应用层协议，用于通过 TCP 多路复用和打包音频、视频及交互内容<sup>[1](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)</sup> |
| 规范 | 由 Adobe 发布，日期为 2012 年 12 月 21 日；由 H. Parmar 和 M. Thornburgh 编辑<sup>[1](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)</sup> |
| 安全变体 | RTMPS 将 RTMP 封装在 TLS 中；Amazon IVS 要求出站端口 443 使用 TLS 1.2 或更高版本<sup>[4](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html)</sup> |
| 分块 | 消息被拆分为块；默认最大块大小为 128 字节，可按方向分别更改<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup> |
| 流容量 | 最多 65597 个块流，ID 范围为 3-65599；ID 0、1 和 2 为保留 ID<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup> |
| 现代编解码器 | 增强型 RTMP（E-RTMP）将协议扩展到 HEVC（H.265）、VP9 和 AV1，超越了传统 RTMP 的 H.264 限制<sup>[5](https://docs.antmedia.io/guides/publish-live-stream/rtmp/enhanced-rtmp/)</sup> |
| 当前角色 | YouTube Live 和 Amazon IVS 等平台的标准摄取协议，通常以 RTMPS 形式使用<sup>[6](https://developers.google.com/youtube/v3/live/docs/liveStreams)</sup><sup> • </sup><sup>[4](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html)</sup> |

## 架构

RTMP 由规范中描述的两个层组成：RTMP 块流协议和 RTMP 消息协议。块流层为更高层的多媒体流协议提供多路复用和打包服务，它可以处理任何发送消息流的协议，而不仅限于 RTMP 本身<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。每条消息携带时间戳和载荷类型标识符。当与 TCP 等可靠传输配合使用时，块流可确保所有消息在多个流之间按时间戳顺序端到端交付<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。

**分块。** 握手之后，一个连接多路复用一条或多条块流，每条块流承载来自一个消息流的一种类型的消息。块在下一条块开始之前完整传输，接收方按块流 ID 将它们重新组装为消息<sup>[1](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)</sup>。分块有两个目的：它将大消息拆分为较小的片段，使得大的低优先级消息（如视频）不会阻塞较小的高优先级消息（如音频或控制数据）；它还让小消息以更少的开销发送<sup>[1](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)</sup>。最大块大小默认为 128 字节，任一对等端都可以通过“设置块大小”控制消息来更改它；该值在每个方向上独立维护<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。

**消息头。** 每个块有一个基本头（1 到 3 字节），编码块流 ID 和格式字段，随后是 0、3、7 或 11 字节的消息头，取决于格式类型。类型 0 头为 11 字节，携带完整的时间戳、消息长度、类型 ID 和消息流 ID；它们必须在块流的起始处以及时间戳倒退时（如向后定位）使用。类型 1 和类型 2 逐步省略与前一块重复的字段，类型 3 完全不携带消息头，复用前一块的所有值<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。超过 16777215（0xFFFFFF）的时间戳和增量会触发 4 字节的扩展时间戳字段<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。

**控制消息。** 块流保留消息类型 ID 1、2、3、5 和 6 用于协议控制消息，这些消息必须使用消息流 ID 0 和块流 ID 2。它们包括设置块大小、中止、确认、窗口确认大小和设置对等端带宽。消息类型 4 承载用户控制消息，用于向对等端报告流相关通知等事件<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。

## 握手

RTMP 连接以一个与协议其余部分不同的握手开始：它由三个固定大小的块组成，而非带头的可变大小块。客户端发送 C0、C1 和 C2，服务器发送 S0、S1 和 S2。客户端首先发送 C0 和 C1，必须等待 S1 后才能发送 C2，必须等待 S2 后才能发送任何其他数据。服务器必须等待 C0 后才能发送 S0 和 S1，等待 C1 后才能发送 S2，等待 C2 后才能发送任何其他数据<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup>。C0 携带客户端使用的 RTMP 版本<sup>[7](https://trepo.tuni.fi/bitstream/handle/10024/130887/AltonenAaro.pdf?isAllowed=y&sequence=2)</sup>。

## 历史及与 Flash 的关系

RTMP 由 Macromedia（后被 Adobe 收购）为 Flash Player 平台开发，曾在 Adobe Systems 任职的 Rajesh Mallipeddi 是该规范的原始编辑，提供了其大部分原始文本<sup>[2](https://github.com/melpon/rfc/blob/master/rtmp.md)</sup><sup> • </sup><sup>[15](https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Audio_and_video_delivery/Live_streaming_web_audio_and_video)</sup>。已发布的规范日期为 2012 年 12 月 21 日，编辑为 H. Parmar 和 M. Thornburgh<sup>[1](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)</sup>。Adobe 于 2017 年 7 月宣布将于 2020 年底停止更新和分发 Flash Player，支持于 2020 年 12 月 31 日结束，自 2021 年 1 月 12 日起，Flash 内容被禁止在 Flash Player 中运行<sup>[3](https://www.adobe.com/support/flash/releasenotes/player/rn_6.html)</sup>。

该协议比其原始客户端存续更久。它的角色从浏览器播放转变为直播的第一英里：[OBS Studio](https://www.edgepedia.org/zh/obs-studio) 等编码器、硬件编码器和移动应用将 RTMP 发布到媒体服务器或云平台，然后由后者为观众重新打包流<sup>[8](https://github.com/ant-media/Ant-Media-Server/wiki/Publishing-Live-Streams/49aaf05c705c15f18f899a4fd188cffac16083b4)</sup>。典型的流水线接收 RTMP 输入，并将其重新封装或转码为基于 HTTP 的交付格式，如 HLS 或 DASH<sup>[9](https://docs.cloud.google.com/livestream/docs/overview)</sup>。

## RTMPS 与安全

普通 RTMP 发送数据时不做加密，包括流密钥。RTMPS 是 RTMP 的安全版本，通过 TLS 运行<sup>[10](https://docs.aws.amazon.com/ivs/latest/RealTimeUserGuide/rt-stream-ingest.html)</sup>。主要平台现在默认使用它：Amazon IVS 要求编码器通过 RTMPS 在出站端口 443 上使用 TLS 1.2 或更高版本连接，仅在通道明确配置为允许不安全的 RTMP 时才允许使用它<sup>[4](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html)</sup>。YouTube 的 RTMPS 摄取同样要求通过端口 443 连接，服务器主机名通过 SSL 握手期间的 SNI 扩展提供以进行身份验证<sup>[11](https://developers.google.com/youtube/v3/live/guides/rtmps-ingestion?trk=article-ssr-frontend-pulse_little-text-block)</sup>。

## 作为摄取协议的使用

RTMP 在直播中的持续存在源于它适合贡献：一条持久的 TCP 连接将一个编码器的音频和视频以低延迟传输到服务器。YouTube Live 除 DASH 和 HLS 摄取外还接受 RTMP 和 RTMPS，并为每个流分配一个主摄取 URL 和一个备份摄取 URL<sup>[6](https://developers.google.com/youtube/v3/live/docs/liveStreams)</sup>。Amazon IVS 支持 RTMP、RTMPS 和 SRT 摄取，其实时流媒体产品还接受带多轨视频的增强型 RTMP<sup>[4](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html)</sup><sup> • </sup><sup>[10](https://docs.aws.amazon.com/ivs/latest/RealTimeUserGuide/rt-stream-ingest.html)</sup>。

**编解码器限制与增强型 RTMP。** 传统 RTMP 仅限于 H.264 视频编解码器，这是开发增强型 RTMP（E-RTMP）规范的原因之一；它增加了对 HEVC（H.265）、VP9 和 AV1 的支持<sup>[5](https://docs.antmedia.io/guides/publish-live-stream/rtmp/enhanced-rtmp/)</sup>。Amazon IVS 文档记载了对 E-RTMP 多轨视频能力的支持<sup>[10](https://docs.aws.amazon.com/ivs/latest/RealTimeUserGuide/rt-stream-ingest.html)</sup>。

## 与 HLS 的比较

RTMP 和 HTTP 直播流（HLS）在流媒体流水线中占据不同的位置。HLS 由 Apple 开发，在 RFC 8216 中规定，通过将媒体拆分为播放列表中列出的分片文件，经由普通 Web 服务器和内容分发网络交付直播和点播内容，并通过在不同比特率的流之间切换来适应网络状况<sup>[12](https://developer.apple.com/documentation/HTTP-Live-Streaming)</sup>。根据 Google 面向编码器供应商的文档，由于 HLS 基于分片，其摄取延迟高于基于 RTMP 和 WebRTC 的摄取<sup>[13](https://developers.google.com/youtube/v3/live/guides/hls-ingestion)</sup>。已部署的延迟数据说明了这一差距：一家媒体服务器供应商报告 Apple HLS 播放延迟为 8 到 12 秒，使用 CMAF 的低延迟 HLS（LL-HLS）为 3 到 5 秒，而 WebRTC 播放约为 0.5 秒<sup>[14](https://github.com/ant-media/Ant-Media-Server/wiki/Specifications)</sup>。在实践中，这两种协议是互补而非竞争的：RTMP 将流从编码器传送到平台，HLS 或 DASH 将流从平台传送到观众<sup>[9](https://docs.cloud.google.com/livestream/docs/overview)</sup>。

## References

1. [Adobe's Real Time Messaging Protocol (RTMP) Specification 1.0, Adobe Systems Incorporated, December 21, 2012](https://rtmp.veriskope.com/pdf/rtmp_specification_1.0.pdf)
2. [Adobe's Real Time Messaging Protocol (RTMP), transcription of the specification](https://github.com/melpon/rfc/blob/master/rtmp.md)
3. [Adobe Flash Player End of Life, Adobe](https://www.adobe.com/support/flash/releasenotes/player/rn_6.html)
4. [Amazon IVS Streaming Configuration, Low-Latency Streaming User Guide, AWS](https://docs.aws.amazon.com/ivs/latest/LowLatencyUserGuide/streaming-config.html)
5. [Publish Enhanced RTMP, Ant Media Documentation](https://docs.antmedia.io/guides/publish-live-stream/rtmp/enhanced-rtmp/)
6. [LiveStreams, YouTube Live Streaming API, Google for Developers](https://developers.google.com/youtube/v3/live/docs/liveStreams)
7. [Design and Implementation of a Secure Real-time Transport Protocol Library for High-Speed Video Streaming, Tampere University](https://trepo.tuni.fi/bitstream/handle/10024/130887/AltonenAaro.pdf?isAllowed=y&sequence=2)
8. [Publishing Live Streams, Ant Media Server Wiki](https://github.com/ant-media/Ant-Media-Server/wiki/Publishing-Live-Streams/49aaf05c705c15f18f899a4fd188cffac16083b4)
9. [Overview of the Live Stream API, Google Cloud Documentation](https://docs.cloud.google.com/livestream/docs/overview)
10. [IVS Stream Ingest, Real-Time Streaming, AWS](https://docs.aws.amazon.com/ivs/latest/RealTimeUserGuide/rt-stream-ingest.html)
11. [Delivering Live YouTube Content via RTMPS, YouTube Live Streaming API, Google for Developers](https://developers.google.com/youtube/v3/live/guides/rtmps-ingestion?trk=article-ssr-frontend-pulse_little-text-block)
12. [HTTP Live Streaming, Apple Developer Documentation](https://developer.apple.com/documentation/HTTP-Live-Streaming)
13. [Delivering Live YouTube Content via HLS, YouTube Live Streaming API, Google for Developers](https://developers.google.com/youtube/v3/live/guides/hls-ingestion)
14. [Specifications, Ant Media Server Wiki](https://github.com/ant-media/Ant-Media-Server/wiki/Specifications)
15. [Livestreaming web audio and video - Media, MDN](https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Audio_and_video_delivery/Live_streaming_web_audio_and_video)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 19, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/real-time-messaging-protocol

English original: https://www.edgepedia.org/real-time-messaging-protocol
