手把手带你实现srs流媒体推流和拉流操作
一、前言
大家晚上好,今天给大家来一个简单的流媒体的推流和拉流的实际操作,废话不多说,赶紧上车!
二、srs流媒体服务器
1、什么是srs流媒体服务器:
srs(Simple Realtime Server),简单实时服务器,它支持是一个流媒体集成,支持RTMP / HLS / FLV,高效,稳定,易用,简单而快乐。SRS是RTMP / HLS / FLV流式群集,高效,稳定,简单。它是一个国内大佬写的一个非常优秀的一个流媒体服务器,它的开源地址在github和gitee上都有:
github地址:
https://github.com/ossrs/srs
gitee地址:
https://gitee.com/winlinvip/srs.oschina
从这个github上大概我了解到,现在srs暂时支持3.0版本,4.0版本应该快发布了,在3.0版本的wiki教程中有一部分视频教程在b站上,感兴趣的小伙伴可以看看:
3.0版本中文wiki教程:
https://github.com/ossrs/srs/wiki/v3_CN_Home
2安装srs流媒体服务器:
我们直接下载3.0版本:
git clone https://gitee.com/winlinvip/srs.oschina.git cd srs.oschina
下载来后:
root@ubuntu:/home/txp/share/srs# cd srs.oschina/
root@ubuntu:/home/txp/share/srs/srs.oschina# ls
AUTHORS.txt LICENSE README.md trunk
查看当前版本是否是3.0版本:
root@ubuntu:/home/txp/share/srs/srs.oschina# git branch -a* develop remotes/origin/2.0release remotes/origin/3.0release remotes/origin/4.0release remotes/origin/HEAD -> origin/develop remotes/origin/develop remotes/origin/feature/h265 remotes/origin/master remotes/origin/min
切换到3.0版本:
root@ubuntu:/home/txp/share/srs/srs.oschina# git checkout -b 3.0 remotes/origin/3.0release
Branch 3.0 set up to track remote branch 3.0release from origin.
Switched to a new branch '3.0'
root@ubuntu:/home/txp/share/srs/srs.oschina# git branch -a* 3.0 develop remotes/origin/2.0release remotes/origin/3.0release remotes/origin/4.0release remotes/origin/HEAD -> origin/develop remotes/origin/develop remotes/origin/feature/h265 remotes/origin/master remotes/origin/min
开始编译安装:
root@ubuntu:/home/txp/share/srs/srs.oschina# cd trunk/
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# ./configure
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# make
配置启动文件:
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# ls3rdparty auto conf configure doc etc ide Makefile modules objs research scripts src usrroot@ubuntu:/home/txp/share/srs/srs.oschina/trunk# vim conf/rtmp.conf
#现在后期的版本不用配置,默认就是已经配置好的# the config for srs to delivery RTMP# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleRTMP# @see full.conf for detail config.
listen 1935;max_connections 1000;vhost __defaultVhost__ {}
启动srs:
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# ./objs/srs -c conf/rtmp.conf
[2021-03-13 23:14:46.387][Trace][1974][0] XCORE-SRS/3.0.156(OuXuli)
[2021-03-13 23:14:46.387][Trace][1974][0] config parse complete
[2021-03-13 23:14:46.387][Trace][1974][0] you can check log by: tail -f ./objs/srs.log (@see https://github.com/ossrs/srs/wiki/v1_CN_SrsLog)
[2021-03-13 23:14:46.387][Trace][1974][0] please check SRS by: ./etc/init.d/srs status
我们可以查看日志来看启动过程中详细的信息:
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# tail -f ./objs/srs.log[2021-03-13 23:14:46.389][Trace][1976][0] son(daemon) process running.[2021-03-13 23:14:46.390][Trace][1974][0] grandpa process exit.[2021-03-13 23:14:46.390][Trace][1976][0] st_init success, use epoll[2021-03-13 23:14:46.390][Trace][1976][764] server main cid=764, pid=1976, ppid=1568, asprocess=0[2021-03-13 23:14:46.390][Error][1976][764][11] srs is already running!(Resource temporarily unavailable)[2021-03-13 23:14:46.390][Error][1976][764][11] Failed, code=1035 : run : daemon run master : acquire pid file : srs is already runningthread [1976][764]: do_main() [src/main/srs_main_server.cpp:186][errno=11]thread [1976][764]: run() [src/main/srs_main_server.cpp:448][errno=11]thread [1976][764]: run_master() [src/main/srs_main_server.cpp:467][errno=11]thread [1976][764]: acquire_pid_file() [src/app/srs_app_server.cpp:824][errno=11](Resource temporarily unavailable)
注意上面的提示说我的服务器已经在运行了,不能再运行了,我们把它给关闭了来:
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# sudo lsof -i:1935
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
srs 1601 root 8u IPv4 20067 0t0 TCP *:1935 (LISTEN)
通过查看srs的端口被一个进程给占用了,所以我们现在把这个进程给杀死掉来:
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# sudo kill -9 1601
重新启动srs:
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# ./objs/srs -c conf/rtmp.conf
[2021-03-13 23:25:49.235][Trace][2037][0] XCORE-SRS/3.0.156(OuXuli)
[2021-03-13 23:25:49.235][Trace][2037][0] config parse complete
[2021-03-13 23:25:49.235][Trace][2037][0] you can check log by: tail -f ./objs/srs.log (@see https://github.com/ossrs/srs/wiki/v1_CN_SrsLog)
[2021-03-13 23:25:49.235][Trace][2037][0] please check SRS by: ./etc/init.d/srs status
root@ubuntu:/home/txp/share/srs/srs.oschina/trunk# tail -f ./objs/srs.log
[2021-03-13 23:25:49.238][Trace][2037][0] start daemon mode...
[2021-03-13 23:25:49.239][Trace][2038][0] father process exit
[2021-03-13 23:25:49.239][Trace][2039][0] son(daemon) process running.
[2021-03-13 23:25:49.239][Trace][2039][0] st_init success, use epoll
[2021-03-13 23:25:49.239][Trace][2039][236] server main cid=236, pid=2039, ppid=1568, asprocess=0
[2021-03-13 23:25:49.240][Trace][2039][236] write pid=2039 to ./objs/srs.pid success!
[2021-03-13 23:25:49.240][Trace][2037][0] grandpa process exit.
[2021-03-13 23:25:49.240][Trace][2039][236] RTMP listen at tcp://0.0.0.0:1935, fd=8
[2021-03-13 23:25:49.240][Trace][2039][236] signal installed, reload=1, reopen=10, fast_quit=15, grace_quit=3
[2021-03-13 23:25:49.241][Trace][2039][236] http: api mount /console to ./objs/nginx/html/console
三、实战演示推流和拉流操作:
1、使用ffmpeg进行推流和ffplay进行拉流:
所谓的推流,简单理解就是把流媒体文件上传到流媒体服务器上去;所以拉流,也可以简单理解就是从流媒体服务器上获取流媒体文件。下面我演示把一个流媒体文件格式为flv的视频流上传到srs上去:
E:\ffmpeg\bin>ffmpeg -re -i test.flv -vcodec copy -acodec copy -f flv -y rtmp://192.168.0.104/live/livestream
上传上去后,我们可以使用ffplay来进行拉流:
E:\ffmpeg\bin>ffplay rtmp://192.168.0.104/live/livestream
注意:这里拉流的时候,你的虚拟机最好搞成桥接模式,和本地的物理机windows在同一个网段;而且上面192.168.0.104代表的是我安装srs流媒体服务器的那台ubunut机器的ip地址。
2、使用vlc来进行拉流:
vlc下载地址:
<!--StartFragment--><https://get.videolan.org/vlc/3.0.12/win64/vlc-3.0.12-win64.exe><!--EndFragment-->
3、使用OBS进行推流
OBS下载地址:
https://pc.qq.com/detail/4/detail_23604.html
下面是OBS推流演示(两种方式,另外一种是使用电脑摄像头来获取):
本地文件推流:
摄像头捕获推流
四、总结
好了,本次的分享就到这里结束了,下面我将开始更多音视频方面的学习总结更新,敬请期待!
参考:
https://gitee.com/winlinvip/srs.oschina
https://ke.qq.com/webcourse/index.html#cid=468797&term_id=100561187&taid=4217056589719357&vid=5285890796286162335
赞 (0)