6

流媒体服务器ZLMediaKit与FFmpeg - KeBoom

 8 months ago
source link: https://www.cnblogs.com/keboom/p/17919098.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

流媒体服务器ZLMediaKit与FFmpeg

overview#

关键字:ZLMediaKit、FFmpeg、srt、vlc

如果想快速拥有自己的流媒体服务器,那么可以使用开源项目自己搭建。开源的流媒体服务器,在国内,GitHub star数量比较高的:srsZLMediaKit。因为在工作中使用的是Mediakit,因此就介绍此开源流媒体服务器。

题外话:听说有人白嫖价低的云服务器,然后就向各个直播平台全天循环播放《周星驰系列》《铁齿铜牙纪晓岚》《小牛说电影》等等,听说收益不错嘞。

本文就说一下通过ffmpeg向mediakit推流,使用vlc拉取mediakit的视频流。

环境准备#

mediakit#

部署时使用docker是最方便的,但是他的docker镜像比较大,大约有400~500MB。如果在意大小的话,可以自己编译。自己编译的话最终的可执行文件只有11MB。

#此镜像为github持续集成自动编译推送,跟代码(master分支)保持最新状态
docker run -id -p 1935:1935 -p 8080:80 -p 8443:443 -p 8554:554 -p 10000:10000 -p 10000:10000/udp -p 8000:8000/udp -p 9000:9000/udp zlmediakit/zlmediakit:master

1935是rtmp,8080是http接口,8443是https,8554是rtsp,10000是rtp,8000是rtc,9000是srt

ffmpeg#

https://johnvansickle.com/ffmpeg/ 在此下载合适的版本,安装好后,使用ffmpeg -protocols查看ffmpeg支持的协议。查看他是否支持srt协议,因为我要用srt协议推拉流。

vlc#

https://www.videolan.org/vlc/ 下载相应的版本即可。

视频准备#

https://ssyoutube.com/en156Bz/youtube-video-downloader 去YouTube下个好看的视频吧。

推送视频流到mediakit#

当我们从YouTube下载好喜欢的视频后,我们可以通过ffmpeg将他推送到mediakit上。比如说我下载了周杰伦的《还在流浪》,然后我以srt协议推送到mediakit上。

./ffmpeg -re -stream_loop -1 -i "/opt/still_wandering.mp4" -c copy -f mpegts 'srt://127.0.0.1:9000?streamid=#!::r=live/test,m=publish'

关于mediakit对于srt支持

然后我们的mediakit就接受到这个srt流了,我们通过调用他提供的http接口:getMediaList

image-20231221140236526

https://github.com/ZLMediaKit/ZLMediaKit/blob/master/postman/ZLMediaKit.postman_collection.json 通过下载这个json文件,可以将他导入到postman中方便调用他的REST接口

mediakit默认配置会将推送到其上的流转为rtmp、rtsp、hls等协议。我们可以通过他所转换之后的流媒体协议再去拉这个流。

vlc拉取视频流#

使用vlc从mediakit上拉流。对于srt协议有些特殊,需要在vlc上配置一下stream参数。

image-20231221142253329

比如我们刚才ffmpeg推流live/test,那么这样配置就行。然后填写srt地址:

image-20231221142358094

192.168.16.152是mediakit服务器ip。

对于其他协议,比如我们使用rtmp:

image-20231221142613761

rtsp:

image-20231221142638148

image-20231221142705424.png

conclusion#

以上就是本篇内容。主要讲述了如何拥有一个自己的流媒体服务器。使用开源项目ZLMediaKit作为流媒体服务器,使用srt协议推流。使用vlc拉取流媒体服务器上的实时视频流。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK