Search code examples
androidffmpeghttp-live-streamingm3u8

HLS streaming always starts from the beginning in Android Browser


Problem

HLS streaming works well in iOS browser(real time mid-stream),

But in most of Android browser, the streaming always starts from the beginning(First Ts file when streaming started).

Reference

  • Android System:4.0,4.4,etc..

  • Detail for FFmpeg command : Pull RTMP streaming, then use segment to transfer that into TS splits.

    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

  • Detail for m3u8 file

    #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.ts4

  • HLS Player:Ckplayer + m3u8 plugins

Help

Does anyone else meet this problem?


Solution

  • As Aergistal said in comment. The lastest ffmpeg supports hls directly. So just use -f hls instead of -f segment. Then problem solved.

    1. If we use -f segment

      • The value of #EXT-X-MEDIA-SEQUENCE will always be 0.
      • Previous TS records would not be removed when latest records are added.
      • Maybe there are some parameters that I didn't know.

      So that Android devices will always start from the first TS file.

    2. If we use -f hls

      • We can use -hls_list_size to define the number of TS files in m3u8 file.
      • The value of #EXT-X-MEDIA-SEQUENCE will update automatically.

      And then it works well.