This is a simple python flask hls live streaming server example.
$ git clone https://github.com/CatScarf/FlaskHlsLiveStreamingServer.git
FFmpeg must be installed. I recommend that you use docker to install.
$ docker pull jrottenberg/ffmpeg
And make sure you can run docker run jrottenberg/ffmpeg
in your terminal. If you have to use sudo docker
, please add your user to the docker user group.
If you are using another docker image, please change the parameter ffmpeg
to IMAGENAME/ffmpeg
in the init parameter of class M3U8 in main.py
. If you have installed ffmpeg without docker, please change this parameter to ffmpeg
. Please note that your ffmpeg must contain the libx264 encoder. This is why I recommend that you use docker. Generally speaking installing ffmpeg without docker is a bit tricky, so I still recommend you use docker.
$ pip install -r requirements.txt
$ cd FlaskHlsLiveStreamingServer/
$ python main.py
You can directly visit the http address show in your terminal. This page uses the popular javasccript library hls.js.
You can also play the example video in a player (PotPlayer or IINA) that supports the hls protocol by entering the following address http://127.0.0.1:5000/video/playlist.m3u8. If you have an Apple device, you can also enter this address in Safari. This is because the hls protocol was developed by apple.