Clone
28
v2_CN_SampleRealtime
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 > Realtime

RTMP低延时配置

配置SRS为Realtime模式使用RTMP可以将延迟降低到0.8-3秒可以应用到对实时性要求不苛刻的地方譬如视频会议其实视频会议以及人类在开会的时候正常时候是会有人讲有人在听在想然后换别人讲其实1秒左右延迟没有问题的除非要吵架就需要0.3秒左右的延迟)。

配置最低延迟的服务器详细信息可以参考:LowLatency,本文举例说明部署的实例步骤。

假设服务器的IP是192.168.1.170

第一步获取SRS。详细参考GIT获取代码

git clone https://github.com/ossrs/srs
cd srs/trunk

或者使用git更新已有代码

git pull

第二步编译SRS。详细参考Build

./configure && make

第三步编写SRS配置文件。详细参考LowLatency

将以下内容保存为文件,譬如conf/realtime.conf,服务器启动时指定该配置文件(srs的conf文件夹有该文件)。

# conf/realtime.conf
listen              1935;
max_connections     1000;
vhost __defaultVhost__ {
    gop_cache       off;
    queue_length    10;
    min_latency     on;
    mr {
        enabled     off;
    }
    mw_latency      100;
    tcp_nodelay     on;
}

第四步启动SRS。详细参考LowLatency

./objs/srs -c conf/realtime.conf

第五步,启动推流编码器。详细参考LowLatency

使用FFMPEG命令推流

    for((;;)); do \
        ./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
        -vcodec copy -acodec copy \
        -f flv -y rtmp://192.168.1.170/live/livestream; \
        sleep 1; \
    done

或使用FMLE推流

FMS URL: rtmp://192.168.1.170/live
Stream: livestream

备注测量延迟可以使用FMLE推流时将智能手机的秒表功能打开用FMLE摄像头对着秒表然后对比FMLE的摄像头的图像和服务器分发的头像的延迟就知道精确的延迟多大。参考延迟的测量,如下图所示: latency

第六步观看RTMP流。详细参考LowLatency

RTMP流地址为rtmp://192.168.1.170/live/livestream

注意不要使用VLC观看VLC的延迟会很大虽然VLC能看到流。

或者使用在线SRS播放器播放http://ossrs.net/srs.release/trunk/research/players/srs_player.html?vhost=defaultVhost&autostart=true&server=192.168.1.170&app=live&stream=livestream

备注请将所有实例的IP地址192.168.1.170都换成部署的服务器IP地址。

Winlin 2014.12