18个实时音视频开发中会用到开源项目 : https://blog.csdn.net/weixin_34261739/article/details/88917741

 

NGINX-RTMP 直播服务部署:

参考:https://zhuanlan.zhihu.com/p/28009037 

 >  https://blog.csdn.net/qq_22899047/article/details/118112980 :

比较详细   https://www.cnblogs.com/ziyue7575/p/13927894.html   

 webrtc 测试可用方案:https://blog.csdn.net/lixiang987654321/article/details/108714690 :原因:推流采用1935端口推流,否则webrtc播放不了 rtmp://192.168.18.129:1935/live/123

如果简单尝试:推荐 SRS ,部署方便

开源项目:https://github.com/ossrs/srs

 WebRTC:https://github.com/ossrs/srs/wiki/v4_CN_WebRTC#config-candidate

Docker 

 推荐使用Docker直接启动SRS,可用镜像在 这里 :

docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \
    ossrs/srs:4 ./objs/srs -c conf/rtc.conf

Note: 若按照文档操作遇到问题,请在 SRS星球 上发文章求助,请贴上本文档链接以及遇到的问题。

若需要支持WebRTC,需要设置CANDIATE,并开启UDP/8000端口:

 

docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \
    --env CANDIDATE="192.168.1.10" -p 8000:8000/udp \
    ossrs/srs:4 ./objs/srs -c conf/rtc.conf

Note: 请将CANDIDATE设置为服务器的外网地址,详细请阅读CANDIDATE

 

运行后:检查SRS是否成功启动,可以打开 http://localhost:8080/ , 

使用 FFmpeg 或 OBS 推流:

ffmpeg -re -i ./doc/source.flv -c copy -f flv -y rtmp://localhost:1935/live/livestream
打开下面的页面播放流(若SRS不在本机,请将localhost更换成服务器IP):

RTMP (by VLC): rtmp://localhost/live/livestream
H5(HTTP-FLV): http://localhost:8080/live/livestream.flv
H5(HLS): http://localhost:8080/live/livestream.m3u8
H5(WebRTC): webrtc://localhost/live/livestream    (隐藏了端口1985  == webrtc://127.0.0.1:1985/live/livestream)  

 

推流工具:OBS(Open Broadcaster Software)

使用:

下载地址

https://cdn-fastly.obsproject.com/downloads/OBS-Studio-27.0.1-Full-Installer-x64.exe

推流设置

 串流密钥即为该流的名:建议 时间+主旨  例如:20210826baxain发布会

....

手机推流:

 

 

 拉流工具

VLC

下载地址

https://plug-mirror.rcac.purdue.edu/vlc/vlc/3.0.14/win32/vlc-3.0.14-win32.exe

安装过程略

打开网络串流,填写流的路径/${流名}

 

 

数据流的保存:

 

sudo  docker run -itd  --name=sea_srs  -p 1935:1935 -p 1985:1985 -p 8080:8080     --env CANDIDATE="192.168.18.51" -p 8000:8000/udp     registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4 ./objs/srs -c conf/rtmp2rtc.conf

 

sudo  docker run -itd  --restart=always  --name=my_sea_srs  -p 1935:1935 -p 1985:1985 -p 8080:8080     --env CANDIDATE="192.168.18.51" -p 8000:8000/udp    \
        -v  /opt/docker/sftp/upload/p/:/opt/:rw  \
      registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4 ./objs/srs -c conf/rtmp2rtc.conf

 

 rtmp2rtc.conf

 

listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;

http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
}

http_api {
    enabled         on;
    listen          1985;
}
stats {
    network         0;
}
rtc_server {
    enabled on;
    listen 8000; # UDP port
    # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
    candidate $CANDIDATE;
}

vhost __defaultVhost__ {

    dvr {
        enabled         on;
        #dvr_path        ./objs/nginx/html/[app]/[stream].[timestamp].mp4;
        dvr_path        /opt/[app]/[stream].mp4;
        dvr_plan        session;
        #dvr_plan        segment;
        dvr_duration    60;
        dvr_wait_keyframe       on;
        time_jitter             full;
    }

    rtc {
        enabled     on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
        rtmp_to_rtc on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
        rtc_to_rtmp on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
}
View Code

 

默认数据流是不会被保存的:

可以在

vhost __defaultVhost__  节点下  添加如下配置:
vhost __defaultVhost__ {

    dvr {
        enabled         on; #是否开启持久化
        #dvr_path        /opt/[app]/[stream].[timestamp].mp4;
        dvr_path        ./objs/nginx/html/[app]/[stream][2006][01][02][15][04][05].mp4;
        dvr_plan        session;
        #dvr_plan        segment;
        dvr_duration    60;
        dvr_wait_keyframe       on;
        time_jitter             full;
    }

    rtc {
        enabled     on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
        rtmp_to_rtc on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
        rtc_to_rtmp on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
}

 

 

 

官网具体配置源配置:

  dvr {
        # whether enabled dvr features
        # default: off
        enabled         on;
        # the filter for dvr to apply to.
        #       all, dvr all streams of all apps.
        #       <app>/<stream>, apply to specified stream of app.
        # for example, to dvr the following two streams:
        #       live/stream1 live/stream2
        # default: all
        dvr_apply       all;
        # the dvr plan. canbe:
        #       session reap flv/mp4 when session end(unpublish).
        #       segment reap flv/mp4 when flv duration exceed the specified dvr_duration.
        # @remark The plan append is removed in SRS3+, for it's no use.
        # default: session
        dvr_plan        session;
        # the dvr output path, *.flv or *.mp4.
        # we supports some variables to generate the filename.
        #       [vhost], the vhost of stream.
        #       [app], the app of stream.
        #       [stream], the stream name of stream.
        #       [2006], replace this const to current year.
        #       [01], replace this const to current month.
        #       [02], replace this const to current date.
        #       [15], replace this const to current hour.
        #       [04], replace this const to current minute.
        #       [05], replace this const to current second.
        #       [999], replace this const to current millisecond.
        #       [timestamp],replace this const to current UNIX timestamp in ms.
        # @remark we use golang time format "2006-01-02 15:04:05.999" as "[2006]-[01]-[02]_[15].[04].[05]_[999]"
        # for example, for url rtmp://ossrs.net/live/livestream and time 2015-01-03 10:57:30.776
        # 1. No variables, the rule of SRS1.0(auto add [stream].[timestamp].flv as filename):
        #       dvr_path ./objs/nginx/html;
        #       =>
        #       dvr_path ./objs/nginx/html/live/livestream.1420254068776.flv;
        # 2. Use stream and date as dir name, time as filename:
        #       dvr_path /data/[vhost]/[app]/[stream]/[2006]/[01]/[02]/[15].[04].[05].[999].flv;
        #       =>
        #       dvr_path /data/ossrs.net/live/livestream/2015/01/03/10.57.30.776.flv;
        # 3. Use stream and year/month as dir name, date and time as filename:
        #       dvr_path /data/[vhost]/[app]/[stream]/[2006]/[01]/[02]-[15].[04].[05].[999].flv;
        #       =>
        #       dvr_path /data/ossrs.net/live/livestream/2015/01/03-10.57.30.776.flv;
        # 4. Use vhost/app and year/month as dir name, stream/date/time as filename:
        #       dvr_path /data/[vhost]/[app]/[2006]/[01]/[stream]-[02]-[15].[04].[05].[999].flv;
        #       =>
        #       dvr_path /data/ossrs.net/live/2015/01/livestream-03-10.57.30.776.flv;
        # 5. DVR to mp4:
        #       dvr_path ./objs/nginx/html/[app]/[stream].[timestamp].mp4;
        #       =>
        #       dvr_path ./objs/nginx/html/live/livestream.1420254068776.mp4;
        # @see https://github.com/ossrs/srs/wiki/v4_CN_DVR#custom-path
        # @see https://github.com/ossrs/srs/wiki/v4_CN_DVR#custom-path
        #       segment,session apply it.
        # default: ./objs/nginx/html/[app]/[stream].[timestamp].flv
        dvr_path        ./objs/nginx/html/[app]/[stream].[timestamp].flv;
        # the duration for dvr file, reap if exceed, in seconds.
        #       segment apply it.
        #       session,append ignore.

        # default: 30
        dvr_duration    30;
        # whether wait keyframe to reap segment,
        # if off, reap segment when duration exceed the dvr_duration,
        # if on, reap segment when duration exceed and got keyframe.
        #       segment apply it.
        #       session,append ignore.
        # default: on
        dvr_wait_keyframe       on;
        # about the stream monotonically increasing:
        #   1. video timestamp is monotonically increasing,
        #   2. audio timestamp is monotonically increasing,
        #   3. video and audio timestamp is interleaved monotonically increasing.
        # it's specified by RTMP specification, @see 3. Byte Order, Alignment, and Time Format
        # however, some encoder cannot provides this feature, please set this to off to ignore time jitter.
        # the time jitter algorithm:
        #   1. full, to ensure stream start at zero, and ensure stream monotonically increasing.
        #   2. zero, only ensure stream start at zero, ignore timestamp jitter.
        #   3. off, disable the time jitter algorithm, like atc.
        # apply for all dvr plan.
        # default: full
        time_jitter             full;

        # on_dvr, never config in here, should config in http_hooks.
        # for the dvr http callback, @see http_hooks.on_dvr of vhost hooks.callback.srs.com
        # @read https://github.com/ossrs/srs/wiki/v4_CN_DVR#http-callback
        # @read https://github.com/ossrs/srs/wiki/v4_CN_DVR#http-callback
            }
        }

 

posted on 2021-08-25 14:36  lshan  阅读(755)  评论(0编辑  收藏  举报