srs+ffmepg搭建点播直播服务器
源码仓库:
https://gitee.com/winlinvip/srs.oschina
4.0源码编译:
https://ossrs.net/lts/zh-cn/docs/v4/doc/getting-started-build
修改hls配置文件:
srs.oschina/trunk/conf/hls.conf
端口建议不为8080
运行srs:
cd 到srs.oschina/trunk
./objs/srs -c conf/srs.conf
查看srs是否运行
# 查看SRS的状态
./etc/init.d/srs status
# 或者看SRS的日志
tail -n 30 -f ./objs/srs.log
如下显示在运行
MB0:trunk $ ./etc/init.d/srs status
SRS(pid 90408) is running. [ OK ]
MB0:trunk $ tail -n 30 -f ./objs/srs.log
[2021-08-13 10:30:36.634][Trace][90408][12c97232] Hybrid cpu=0.00%,0MB, cid=1,1, timer=61,0,0, clock=0,22,25,0,0,0,0,1,0
点播
用ffmpeg对myvideo.ts视频文件按每个切片1s来切割,并生成index.m3u8:
ffmpeg -i myvideo.ts -c copy -map 0 -f segment -segment_list index.m3u8 -segment_time 1 test-%03d.ts
将切片生成的文件放到srs.oschina/trunk/objs/nginx/html/live目录下
VLC打开流播视频:
示例: http://localhost:8080/live/index.m3u8
直播查看:
编写脚本循环推流播放:
#!/bin/bash
for((;😉); do
./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.flv
-c copy
-f flv rtmp://192.168.1.170/live/livestream;
sleep 1;
done
给脚本赋777权限并运行
然后再vlc打开视频
rtmp://localhost/live/hls/index
http://localhost:8080/live/hls/index.m3u8
注:点播需要先把视频切好,然后固定一个m3u8列表,在使用vlc去播放(http)
更多推荐
所有评论(0)