Migrate from NGINX-RTMP, support HLS variant, multiple bitrate, HLS multi-bitrate
winlinvip opened this issue · 6 comments
https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_variant
NGINX-RTMP matches several stream names and then generates a single HLS multi-bitrate stream.
TRANS_BY_GPT3
@winlinvip Is this something you're looking for contributions on or do you plan to write this yourself? Thanks for everything!
Both are ok.
This would be crazy useful. I stumbled upon SRS and was very excited but with no support for HLS variants SRS does not fit my use case :) Unfortunately am unable to contribute to this :(
Plan in SRS4.
For people how needs this feature: you can realize this now already with srs:
- prepare your defaultVhost with transcoding:
transcode live/stream {
enabled on;
ffmpeg /usr/local/bin/ffmpeg;
engine half {
enabled on;
iformat live_flv;
vfilter {
v quiet;
}
vcodec libx264;
vfps 25;
vwidth 512;
vheight 288;
vprofile main;
vpreset medium;
vparams {
crf 23;
x264opts keyint=50:min-keyint=50:no-scenecut;
maxrate 650k;
bufsize 1300k;
}
acodec copy;
oformat flv;
output rtmp://localhost:1935/live/half;
}
}
hls {
enabled on;
hls_path /var/www/srs/live;
hls_fragment 6;
hls_window 1800;
hls_cleanup on;
hls_dispose 5;
hls_m3u8_file [stream]_hq.m3u8;
hls_ts_file [stream]_hq-[seq].ts;
}
- then add a second vhost for localhost and add there a new hls statement:
hls {
enabled on;
hls_path /var/www/srs/live;
hls_fragment 6;
hls_window 1800;
hls_cleanup on;
hls_dispose 5;
hls_m3u8_file [stream]_lq.m3u8;
hls_ts_file [stream]_lq-[seq].ts;
}
- then create a master.m3u8:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:15
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2149280,CODECS="mp4a.40.2,avc1.64001f",RESOLUTION=1024x576,NAME="1024"
live/stream_hq.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=460560,CODECS="mp4a.40.5,avc1.420016",RESOLUTION=512x288,NAME="512"
live/half_lq.m3u8
- set the correct
BANDWIDTH
If you need more resolutions just add in transcode more outputs under vparams
, maybe like this:
...
s 1024x576;
crf 23;
x264opts keyint=50:min-keyint=50:no-scenecut;
maxrate 1300k;
bufsize 2600k;
f flv;
c:a copy;
y rtmp://127.0.1.1:1935/live/big;
crf 23;
x264opts keyint=50:min-keyint=50:no-scenecut;
maxrate 650k;
bufsize 1300k;
...
and add more vhosts.
Here is a working gist
@jb-alvarado 👍 Thanks! It's a better solution to use FFMPEG to transcode RTMP to multiple HLS streams.