Linux HLS Server including uploader, segmenter, chunks dealer and media manager
HLS Segmenter is a configurable python script to achieve Http Live Streaming segmentation, playlist and variants playlist from a given movie file.
HLS Segmenter use ffmpeg, and works great on Linux.
DEPENDENCIES: FFmpeg
CONFIGURE:
You can create "Profiles" in presets.py (see existing ones to get an idea).
USE:
./segmenter -i video_path [-u url_prefix] [-p]
Let say your input media is /var/www/video/mymovie.mp4: And that you have a webserver with http://localhost/ linked to /var/www/
The command will be
./segmenter -i /var/www/video/mymovie.mp4 -u http://localhost/video/
It will create a new directory /var/www/video/mymovie/ next to the input video location, with
To play the HLS stream you only need to provide the movie.m3u8 url, like this http://localhost/video/mymovie/mymovie.m3u8
And if your client doesn't support HLS you can fallback to http://localhost/video/mymovie/mymovie.mp4 which is a re-encode of your original movie with the first preset in the list.
Your original movie should still be available from there: http://localhost/video/mymovie.mp4
command: ./segmenter -i /var/www/myvideo.mp4 -u http://localhost/
it will generate the main playlist at url: http://localhost/myvideo/myvideo.m3u8
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=244400,RESOLUTION=416x234
http://localhost/myvideo/0-ugly/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=421120,RESOLUTION=416x234
http://localhost/myvideo/1-bad/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=733200,RESOLUTION=480x270
http://localhost/myvideo/2-tiny/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1182145,RESOLUTION=640x360
http://localhost/myvideo/3-low/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2192834,RESOLUTION=640x360
http://localhost/myvideo/4-medium/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5888165,RESOLUTION=960x540
http://localhost/myvideo/5-high/stream.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=8663048,RESOLUTION=1280x720
http://localhost/myvideo/6-hd/stream.m3u8
FFmpeg can report the bitrate of the ts stream. Use the ffprobe tool and you'll get output like this:
ffprobe ./myvideo/3-low/3-low3.ts (the third chunk for the "low" profile)
Input #0, mpegts, from '3-low3.ts':
Duration: 00:00:02.00, start: 7.423222, bitrate: 851 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 90k tbn, 48 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 93 kb/s
The bitrate is being given in kilobits per second, so multiply it by 1024 and you'll have the value you need for the BANDWIDTH tag.