• Simple-RTMP-Server 服务器搭建


    Simple-RTMP-Server 服务器搭建

    1. 服务器镜像获取

    • github源码地址
    	git clone https://github.com/winlinvip/simple-rtmp-server.git
    
    • CSDN镜像地址
    	git clone https://code.csdn.net/winlinvip/srs-csdn.git
    
    • OSChina镜像
    	git clone https://git.oschina.net/winlinvip/srs.oschina.git
    

    2. 关闭防火墙和selinux或者开放端口

    • 关闭防火墙
    	# disable the firewall
    	sudo /etc/init.d/iptables stop
    	sudo /sbin/chkconfig iptables off
    
    • 使selinux失败
    • 编辑配置文件:sudo vi /etc/sysconfig/selinux
    • 把SELINUX的值改为disabled:SELINUX=disabled
    • 重启系统:sudo init 6

    3. 编译系统

    	./configure --disable-all --with-ssl --with-hls --with-nginx --with-ffmpeg --with-transcode
    
    	make && sudo make install
    

    安装命令会将SRS默认安装到/usr/local/srs中,可以在configure时指定其他目录,譬如./configure --prefix=pwd/_release 可以安装到当前的_release目录(可以不用sudo安装,直接用make install即可安装)

    4. 建立启动服务

    4.1 建立软连接

    	sudo ln -sf   /usr/local/srs/etc/init.d/srs  /etc/init.d/srs
    
    • 备注:若SRS安装到其他目录,将/usr/local/srs替换成其他目录。

    • 备注:也可以使用其他的名称,譬如/etc/init.d/srs,可以任意名称,启动时也用该名称。

    4.2 添加服务

    	#centos 6
    	sudo /sbin/chkconfig --add srs
    

    或者

    	#ubuntu12
    	sudo update-rc.d srs defaults
    

    4.3 使用init.d脚本管理SRS

    查看SRS状态:

    	/etc/init.d/srs status
    

    启动SRS:

    	/etc/init.d/srs start
    

    停止SRS:

    	/etc/init.d/srs stop
    

    重启SRS:

    	/etc/init.d/srs restart
    

    Reload SRS:

    	/etc/init.d/srs reload
    

    5. 启动分发hls(m3u8/ts)的nginx

    	sudo ./objs/nginx/sbin/nginx
    

    6. 编写SRS配置文件

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

    # conf/transcode2hls.audio.only.conf
    listen              1935;
    max_connections     1000;
    http_stream {
        # whether http streaming service is enabled.
        # default: off
        enabled         on;
        # the http streaming port
        # @remark, if use lower port, for instance 80, user must start srs by root.
        # default: 8080
        listen          8080;
        # the default dir for http root.
        # default: ./objs/nginx/html
        dir             ./objs/nginx/html;
    }
    vhost __defaultVhost__ {
        hls {
            enabled         on;
            hls_path        ./objs/nginx/html;
            hls_fragment    10;
            hls_window      60;
        }
        transcode {
            enabled     on;
            ffmpeg      ./objs/ffmpeg/bin/ffmpeg;
            engine ff {
                enabled         on;
                vcodec          copy;
                acodec          libaacplus;
                abitrate        45;
                asample_rate    44100;
                achannels       2;
                aparams {
                }
                output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
            }
        }
    }
    

    备注:这个配置使用只转码音频,因为视频是h.264符合要求

    7. 启动SRS

    	./objs/srs -c conf/transcode2hls.audio.only.conf
    

    或者使用服务进行启动

    8. 启动推流编码器

    使用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
    

    生成的流地址为:

    • RTMP流地址为(FMLE推流无HLS地址):rtmp://192.168.1.170/live/livestream
    • 转码后的RTMP流地址为:rtmp://192.168.1.170/live/livestream_ff
    • 转码后的HLS流地址为: http://192.168.1.170/live/livestream_ff.m3u8

    备注:因为FMLE推上来的音频有问题,不是aac,所以srs会报错(当然啦,不然就不用转码了)。这个错误可以忽略,srs是说,rtmp流没有问题,但是无法切片为hls,因为音频编码不对。没有关系,ffmpeg会转码后重新推一路流给srs。

    备注:如何只对符合要求的流切hls?可以用vhost。默认的vhost不切hls,将转码后的流推送到另外一个vhost,这个vhost切hls。

    9. 观看RTMP流

    • RTMP流地址为:rtmp://192.168.1.170/live/livestream_ff
    • 播放器:VLC
    • 或者:
    • http://winlinvip.github.io/srs.release/trunk/research/players/srs_player.html?vhost=defaultVhost&autostart=true&server=192.168.1.170&app=live&stream=livestream_ff

    • HLS流地址为: http://192.168.1.170/live/livestream_ff.m3u8
    • 播放器VLC
    • 或者
    • http://winlinvip.github.io/srs.release/trunk/research/players/jwplayer6.html?vhost=defaultVhost&hls_autostart=true&server=192.168.1.170&app=live&stream=livestream_ff

    10. 手机端查看

    10.1 Android

    <video width="640" height="360"
    	autoplay controls autobuffer 
    	src="http://127.0.0.1/live/livestream.m3u8"
    	type="application/vnd.apple.mpegurl">
    </video>
    

    10.2 IOS

    	http://127.0.0.1/live/livestream.m3u8
    
  • 相关阅读:
    赔了多少钱
    datatables使用
    Django开发汇总
    STF的DOCKER搭建
    ubuntu基本
    python 列表、元组、字典、字符串
    Appium环境搭建
    AppCrawler环境搭建
    TASK 总结
    python & jira
  • 原文地址:https://www.cnblogs.com/meetrice/p/5428975.html
Copyright © 2020-2023  润新知