当前位置:   article > 正文

Docker部署 SRS rtmp/flv流媒体服务器_docker流媒体

docker流媒体

一、介绍


SRS(Simple Realtime Server)是一款开源的流媒体服务器,具有高性能、高可靠性、高灵活性的特点,能够支持直播、点播、转码等多种流媒体应用场景。SRS 不仅提供了流媒体服务器,还提供了适用于多种平台的客户端 SDK 和在线转码等辅助服务,是一款十分强大的流媒体解决方案。

SRS 在流媒体直播、点播、转码等方面的应用场景十分丰富:

  • 在直播行业方面,SRS 能够支持多种流媒体协议(如 RTMP、HLS、RTSP、MPEG-TS 等)和传输模式,以及实时录制、转码等额外的功能,可以适用于直播监控、教学、演唱会等场景。

  • 在点播方面,SRS 提供了多种点播服务协议(如 HTTP-FLV、HTTP-DASH、HTTP-HLS 等),并支持高并发和多种混合流媒体格式的传输。

  • 在转码方面,SRS 支持多种常见音视频格式的转换和输出,例如 H.264, HEVC 等。


二、安装SRS

流媒体镜像docker-hub官方拉取

docker pull ossrs/srs

 二、安装并启动SRS的容器

1. 不挂载目录或修改配置文件,docker镜像原始配置运行

docker run -it -d -p 1935:1935 -p 1985:1985 -p 8080:8080 --name srs ossrs/srs

2. 挂载目录,将容器内部所需配置文件copy到宿主机然后进行映射

2.1  宿主机新建两个目录

mkdir -p /root/srs/conf

mkdir -p /root/srs/objs

2.2  在前述运行的SRS容器中,把上述三个目录内的文件和目录全部拷贝到宿主机中。

# 把容器中的配置文件复制出来

docker cp -a srs:/usr/local/srs/conf /root/srs/conf

# 把容器中的数据文件复制出来

docker cp -a srs:/usr/local/srs/objs /root/srs/objs

 2.2.1重新启动

docker run -it -p 1935:1935 -p 1985:1985 -p 8080:8080 --name srs --restart=always -v /root/srs/conf:/usr/local/srs/conf  -v  /root/srs/objs:/usr/local/srs/objs  ossrs/srs

此时流服务器已经可以使用,如果需要自定义配置文件可继续按照下面步骤。

2.2.2 自定义配置文件  

(仅供参考:具体去看官方配置文档 )
在 /root/srs/conf 创建自己的配置文件 srs.my.conf

  1. # SRS 参考配置
  2. listen 1935;
  3. max_connections 1000;
  4. srs_log_tank file;
  5. srs_log_file ./objs/srs.log;
  6. daemon on;
  7. http_api {
  8. enabled on;
  9. listen 1985;
  10. }
  11. http_server {
  12. enabled on;
  13. listen 8080;
  14. dir ./objs/nginx/html;
  15. # 开启 https 支持,需要开放 8088端口
  16. # https {
  17. # enabled on;
  18. # listen 8088;
  19. # key ./conf/xxxx.key;
  20. # cert ./conf/xxxx.crt;
  21. # }
  22. }
  23. vhost __defaultVhost__ {
  24. # http-flv设置
  25. http_remux{
  26. enabled on;
  27. mount [vhost]/[app]/[stream].flv;
  28. hstrs on;
  29. }
  30. # hls设置
  31. hls {
  32. enabled on;
  33. hls_fragment 1;
  34. hls_window 2;
  35. hls_path ./objs/nginx/html;
  36. hls_m3u8_file [app]/[stream].m3u8;
  37. hls_ts_file [app]/[stream]-[seq].ts;
  38. }
  39. # dvr设置
  40. dvr {
  41. enabled off;
  42. dvr_path ./objs/nginx/html/[app]/[stream]/[2006]/[01]/[02]/[timestamp].flv;
  43. dvr_plan segment;
  44. dvr_duration 30;
  45. dvr_wait_keyframe on;
  46. }
  47. # rtc 设置
  48. rtc {
  49. enabled on;
  50. bframe discard;
  51. }
  52. # SRS支持refer防盗链:检查用户从哪个网站过来的。譬如不是从公司的页面过来的人都不让看。
  53. refer {
  54. # whether enable the refer hotlink-denial.
  55. # default: off.
  56. enabled off;
  57. # the common refer for play and publish.
  58. # if the page url of client not in the refer, access denied.
  59. # if not specified this field, allow all.
  60. # default: not specified.
  61. all github.com github.io;
  62. # refer for publish clients specified.
  63. # the common refer is not overrided by this.
  64. # if not specified this field, allow all.
  65. # default: not specified.
  66. publish github.com github.io;
  67. # refer for play clients specified.
  68. # the common refer is not overrided by this.
  69. # if not specified this field, allow all.
  70. # default: not specified.
  71. play github.com github.io;
  72. }
  73. # http 回调
  74. http_hooks {
  75. # 事件:发生该事件时,即回调指定的HTTP地址。
  76. # HTTP地址:可以支持多个,以空格分隔,SRS会依次回调这些接口。
  77. # 数据:SRS将数据POST到HTTP接口。
  78. # 返回值:SRS要求HTTP服务器返回HTTP200并且response内容为整数错误码(0表示成功),其他错误码会断开客户端连接。
  79. # whether the http hooks enable.
  80. # default off.
  81. enabled on;
  82. # 当客户端连接到指定的vhost和app时
  83. on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
  84. # 当客户端关闭连接,或者SRS主动关闭连接时
  85. on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
  86. # 当客户端发布流时,譬如flash/FMLE方式推流到服务器
  87. on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
  88. # 当客户端停止发布流时
  89. on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
  90. # 当客户端开始播放流时
  91. on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
  92. # 当客户端停止播放时。备注:停止播放可能不会关闭连接,还能再继续播放。
  93. on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
  94. # 当DVR录制关闭一个flv文件时
  95. on_dvr http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;
  96. # 当HLS生成一个ts文件时
  97. on_hls http://127.0.0.1:8085/api/v1/hls http://localhost:8085/api/v1/hls;
  98. # when srs reap a ts file of hls, call this hook,
  99. on_hls_notify http://127.0.0.1:8085/api/v1/hls/[app]/[stream]/[ts_url][param];
  100. }
  101. }

 通过自定义配置文件启动 (未尝试,大家可以看看配置文件是否可以使用,大多数还是使用第一种方式)

docker run -it -p 1935:1935 -p 1985:1985 -p 8080:8080 --name srs --network src_network 
--restart=always  -v /root/srs/conf:/usr/local/srs/conf  -v  /root/srs/objs:/usr/local/srs/objs   ossrs/srs ./objs/srs -c conf/srs.my.conf

要想外网可以访问,需要打开1935、8080、1985 三个端口号(云服务安全组) 

3. 通过8080端口可以访问srs中心

三、命令行FFmpeg (局域网的摄像头推流到云服务上部署的流媒体服务器

ffmpeg -i "rtsp://admin:Pc@12138@192.168.7.34" -c:v libx264 -c:a aac -f flv rtmp://192.168.14.93/live/stream

 使用vlc 或者前端来进行视频播放

 

转换为flv播放

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号