赞
踩
SRS(Simple Realtime Server)是一款开源的流媒体服务器,具有高性能、高可靠性、高灵活性的特点,能够支持直播、点播、转码等多种流媒体应用场景。SRS 不仅提供了流媒体服务器,还提供了适用于多种平台的客户端 SDK 和在线转码等辅助服务,是一款十分强大的流媒体解决方案。
SRS 在流媒体直播、点播、转码等方面的应用场景十分丰富:
在直播行业方面,SRS 能够支持多种流媒体协议(如 RTMP、HLS、RTSP、MPEG-TS 等)和传输模式,以及实时录制、转码等额外的功能,可以适用于直播监控、教学、演唱会等场景。
在点播方面,SRS 提供了多种点播服务协议(如 HTTP-FLV、HTTP-DASH、HTTP-HLS 等),并支持高并发和多种混合流媒体格式的传输。
在转码方面,SRS 支持多种常见音视频格式的转换和输出,例如 H.264, HEVC 等。
流媒体镜像docker-hub官方拉取
docker pull ossrs/srs
docker run -it -d -p 1935:1935 -p 1985:1985 -p 8080:8080 --name srs ossrs/srs
mkdir -p /root/srs/conf
mkdir -p /root/srs/objs
# 把容器中的配置文件复制出来
docker cp -a srs:/usr/local/srs/conf /root/srs/conf
# 把容器中的数据文件复制出来
docker cp -a srs:/usr/local/srs/objs /root/srs/objs
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
此时流服务器已经可以使用,如果需要自定义配置文件可继续按照下面步骤。
(仅供参考:具体去看官方配置文档 )
在 /root/srs/conf 创建自己的配置文件 srs.my.conf
- # SRS 参考配置
-
- listen 1935;
- max_connections 1000;
- srs_log_tank file;
- srs_log_file ./objs/srs.log;
- daemon on;
- http_api {
- enabled on;
- listen 1985;
- }
- http_server {
- enabled on;
- listen 8080;
- dir ./objs/nginx/html;
- # 开启 https 支持,需要开放 8088端口
- # https {
- # enabled on;
- # listen 8088;
- # key ./conf/xxxx.key;
- # cert ./conf/xxxx.crt;
- # }
- }
- vhost __defaultVhost__ {
- # http-flv设置
- http_remux{
- enabled on;
- mount [vhost]/[app]/[stream].flv;
- hstrs on;
- }
-
- # hls设置
- hls {
- enabled on;
- hls_fragment 1;
- hls_window 2;
- hls_path ./objs/nginx/html;
- hls_m3u8_file [app]/[stream].m3u8;
- hls_ts_file [app]/[stream]-[seq].ts;
- }
-
- # dvr设置
- dvr {
- enabled off;
- dvr_path ./objs/nginx/html/[app]/[stream]/[2006]/[01]/[02]/[timestamp].flv;
- dvr_plan segment;
- dvr_duration 30;
- dvr_wait_keyframe on;
- }
-
- # rtc 设置
- rtc {
- enabled on;
- bframe discard;
- }
-
- # SRS支持refer防盗链:检查用户从哪个网站过来的。譬如不是从公司的页面过来的人都不让看。
- refer {
- # whether enable the refer hotlink-denial.
- # default: off.
- enabled off;
- # the common refer for play and publish.
- # if the page url of client not in the refer, access denied.
- # if not specified this field, allow all.
- # default: not specified.
- all github.com github.io;
- # refer for publish clients specified.
- # the common refer is not overrided by this.
- # if not specified this field, allow all.
- # default: not specified.
- publish github.com github.io;
- # refer for play clients specified.
- # the common refer is not overrided by this.
- # if not specified this field, allow all.
- # default: not specified.
- play github.com github.io;
- }
-
- # http 回调
- http_hooks {
-
- # 事件:发生该事件时,即回调指定的HTTP地址。
- # HTTP地址:可以支持多个,以空格分隔,SRS会依次回调这些接口。
- # 数据:SRS将数据POST到HTTP接口。
- # 返回值:SRS要求HTTP服务器返回HTTP200并且response内容为整数错误码(0表示成功),其他错误码会断开客户端连接。
-
- # whether the http hooks enable.
- # default off.
- enabled on;
-
- # 当客户端连接到指定的vhost和app时
- on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
-
- # 当客户端关闭连接,或者SRS主动关闭连接时
- on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
-
- # 当客户端发布流时,譬如flash/FMLE方式推流到服务器
- on_publish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
-
- # 当客户端停止发布流时
- on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
-
- # 当客户端开始播放流时
- on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
-
- # 当客户端停止播放时。备注:停止播放可能不会关闭连接,还能再继续播放。
- on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;
-
- # 当DVR录制关闭一个flv文件时
- on_dvr http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;
-
- # 当HLS生成一个ts文件时
- on_hls http://127.0.0.1:8085/api/v1/hls http://localhost:8085/api/v1/hls;
-
- # when srs reap a ts file of hls, call this hook,
- on_hls_notify http://127.0.0.1:8085/api/v1/hls/[app]/[stream]/[ts_url][param];
- }
- }

通过自定义配置文件启动 (未尝试,大家可以看看配置文件是否可以使用,大多数还是使用第一种方式)
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 三个端口号(云服务安全组)
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播放
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。