Clone
6
v2_CN_RTMP ATC
winlin edited this page 2022-01-06 11:57:15 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

HOME > CN > ATC

ATC支持HLS/HDS热备

RTMP的热备怎么做当边缘回源时上层出现故障可以切换到另外一个上层所以RTMP热备只需要指定多个上层/源站就可以。边缘在故障切换时,会重新连接新服务器,客户端连接还没有断开,所以看起来就像是编码器重新推流了,画面最多抖动一下或者卡一下。

HLS热备怎么做边缘从某个源站拿不到ts切片时会去另外一个服务器拿。所以就要求两个上层的ts切片一样当然如果上层服务器都从一个源站取片是没有问题的。

如果HLS的源站需要做热备怎么办参考Adobe: HDS/HLS热备,如下图所示:

                        +----------+        +----------+
               +--ATC->-+  server  +--ATC->-+ packager +-+   +---------+
+----------+   | RTMP   +----------+ RTMP   +----------+ |   | Reverse |    +-------+
| encoder  +->-+                                         +->-+  Proxy  +-->-+  CDN  +
+----------+   |        +----------+        +----------+ |   | (nginx) |    +-------+
               +--ATC->-+  server  +--ATC->-+ packager +-+   +---------+
                 RTMP   +----------+ RTMP   +----------+

实际上adobe文中所说的是encoder输出的是ATC RTMP流也没有packager直接server就打包了。如果你需要自己做打包譬如基于ffmpeg写个工具自定义HLS流的打包编码器可以将ATC RTMP流推送到SRSSRS会以ATC RTMP形式不修改时间戳分发给你的工具。

所以ATC RTMP说白了就是绝对时间server需要能接入绝对时间若切片在server上则根据绝对时间切片若server和ReverseProxy之间还有切片工具那server应该给切片工具绝对时间。

SRS配置ATC

SRS默认ATC是关闭即给客户端的RTMP流永远从0开始。若工具需要SRS不修改时间戳只将sequence header和metadata调整为第一个音视频包的时间戳可以打开ATC配置

vhost __defaultVhost__ {
    # vhost for atc for hls/hds/rtmp backup.
    # generally, atc default to off, server delivery rtmp stream to client(flash) timestamp from 0.
    # when atc is on, server delivery rtmp stream by absolute time.
    # atc is used, for instance, encoder will copy stream to master and slave server,
    # server use atc to delivery stream to edge/client, where stream time from master/slave server
    # is always the same, client/tools can slice RTMP stream to HLS according to the same time,
    # if the time not the same, the HLS stream cannot slice to support system backup.
    # 
    # @see http://www.adobe.com/cn/devnet/adobe-media-server/articles/varnish-sample-for-failover.html
    # @see http://www.baidu.com/#wd=hds%20hls%20atc
    #
    # default: off
    atc             on;
}

ATC和flash的兼容性

开启ATC之后flash客户端播放SRS流时流的起始时间不是0而是ATC时间。需要调整时间的包

  • sequence header: 调整为第一个音视频包的时间。若有gop cache则调整为gop cache中的第一个音视频包的时间。
  • metadata: 调整为第一个音视频包的时间。nginx-rtmp没有调整metadata包的时间为0所以平均每20次就有一次卡死。

经过测试SRS打开和关闭ATCflash播放器都能播放SRS的RTMP流。

ATC和编码器

编码器开启atc之后若在metadata中自动写入"bravo_atc"="true"srs会自动的开启atc。

可以禁用这个功能:

vhost atc.srs.com {
    # whether enable the auto atc,
    # if enabled, detect the bravo_atc="true" in onMetaData packet,
    # set atc to on if matched.
    # always ignore the onMetaData if atc_auto is off.
    # default: on
    atc_auto        off;
}

将自动atc关闭即可。

Winlin 2014.3