HLS live streaming works normally in iOS system.
However, playing HLS live streaming generated by ffmpeg on Android using most browsers (except UC Browser) will cause the problem of playing from scratch.
That is, whenever the live stream is played, it will start from the content at the beginning of the live broadcast (the first live TS slice generated, eg: the live broadcast will be started one hour after the movie starts live broadcast, starting from 0 minutes).
Android: 4.0 (Xiaomi 2s), 4.4 (Honor 6), other versions not tested
Browser: default browser, Tencent browser
Live broadcast mode: ffmpeg obtains rtmp stream and cuts it into ts segments in real time with its own segment. The command is as follows (video stream parameters are omitted)
ffmpeg -re -i rtmp://ipaddress/live/streamname -codec:a libfaac -b:a 96k -af volume=1 -ac 2 -ar 44100 -f segment -segment_time 5 -segment_list_flags live -segment_list /path/to/m3u8 -segment_format mpegts /path/to/ts
The generated m3u8 file is as follows (adding ts list in real time)
#EXTM3U #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-ALLOW-CACHE:NO #EXT-X-TARGETDURATION:6 #EXTINF:5.000278, file0000.ts #EXTINF:5.013356, file0001.ts
HLS player: Ckplayer plus m3u8 plug-in
I don’t know if other people have encountered this problem.
The new version of FFmpeg already directly supports hls format package output, so using hls instead of segment output can solve the problem.
In m3u8 file
#EXT-X-MEDIA-SEQUENCEThe value of has always been 0.
The ts list will not remove old slices when it is added.
Of course, it is also possible that there are parameters to be set but not found.
Therefore, Android’s browser will read the m3u8 file from the first ts slice after requesting it, thus causing it to be played from scratch every time it is opened.
M3u8 file can be based on
-hls_list_sizeParameter setting preserves several ts slices.
#EXT-X-MEDIA-SEQUENCEThe value will automatically change according to the ts slice sequence number.
Therefore, the m3u8 file, sequence id and ts list requested by the browser are normal, so it can be broadcast live in normal real time without starting from scratch.