futzu / SCTE-35_HLS_x9k3

HLS and SCTE-35 x9k3 is a HLS Segmenter with SCTE 35, and Live Streaming from Non-Live Soures and Looping.
67 stars 17 forks source link

Play on native player breaks in replay mode after restarting the loop #25

Closed alfonsosiloniz closed 9 months ago

alfonsosiloniz commented 9 months ago

As I mentioned on other issues, I open a new one clarifying the behavior I get when trying to use the tool to play on a native player (IOS 15) and the replay mode.

I have an input file that is an MPEG.TS generated with ffmpeg with the following characteristics:

Input #0, mpegts, from '../live.ts':
  Duration: 00:00:48.02, start: 1.458667, bitrate: 1790 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 4 kb/s

I execute x9k3 with the following arguments:

x9k3 -i live.ts -o out -t 6 --replay -c

In a first pass, the playlist is generated correctly, segmenting the file and adding them into the playlist. The number of segments for this input file is 8 (with t=6 seconds, from 0 to 7). The throttling is working correctly. The playlist for the last segment is this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:3
#EXT-X-DISCONTINUITY-SEQUENCE:4
#EXT-X-X9K3-VERSION:0.2.01
#EXTINF:6.000000,
seg3.ts
#EXTINF:6.000000,
seg4.ts
#EXTINF:7.000000,
seg5.ts
#EXTINF:6.000000,
seg6.ts
#EXTINF:4.960000,
seg7.ts

After the duration of the input file has passed, the tool re-decode the input file to start over again for the replay functionality. Now, current segment will be 8. The generated playlist file is the following:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:8
#EXT-X-DISCONTINUITY-SEQUENCE:4
#EXT-X-X9K3-VERSION:0.2.01
#EXT-X-DISCONTINUITY
#EXTINF:6.000000,
seg8.ts

As you can see, all the previous segments are removed from the playlists, and only the new "first" segment is present in it. This breaks the play of this m3u8 in an HLS player (tested with hls.js and native player). This breaks the buffer status in the player. For this to work safely for players, the playlist for the segment #8 should be like this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:3
#EXT-X-DISCONTINUITY-SEQUENCE:4
#EXT-X-X9K3-VERSION:0.2.01
#EXTINF:6.000000,
seg4.ts
#EXTINF:7.000000,
seg5.ts
#EXTINF:6.000000,
seg6.ts
#EXTINF:4.960000,
seg7.ts
#EXT-X-DISCONTINUITY
#EXTINF:6.000000,
seg8.ts

It should remove remove seg3.ts from the playlist, and should add a Discontinuity tag (as the PTS in the input file restart to 0 and the player needs to be aware of) and continue the live flow with the segment. This change has been tested to play correctly in hls.js and native IOS 15 player.

Hope it helps.

futzu commented 9 months ago

I thought I had fixed that, give me a minute.

futzu commented 9 months ago

I did it that way intentionally and it really doesn't make sense to continue for live.

alfonsosiloniz commented 9 months ago

Hi Adrian. Thanks for your responses.

I didn´t ask for "continue" "-c" feature. It was another person.

PTS doesn't restart to 0, it restart to the first PTS value it finds.

True. I simplified in my message. The thing is that PTS breaks its sequence, so a discontinuity must be signaled in the playlist. that was my point

Why would you tell me throttling works, has it been broken?

No as fas as I know. Just was describing the process at a whole.

Why would you ever use continue with replay?

Agree. As I say above, I didn´t ask for that feature. The only thing I was asking is that replay feature works and is playable.

Why would you ever use 0 second segments?

Sorry but I don´t understand why you ask me this.

My understanding of what the "replay" feature was (maybe am I wrong? ) is that I can take one input file, and the tool is able to generate a continuous linear channel that plays indefinitely. In the open issue, what it "fails" from that description is that playlist restarts loosing the previous segments making the player to stop playing.

futzu commented 9 months ago

You said you tested 0 -7 seconds, that's why I asked about zero. I actually came up with a decent way to do it.

Here's what I'm doing, when you continue or replay, I'm using m3ufu to parse the m3u8 and load the segments back into the sliding window.

Other than those two details it should be cool.

Here's the commit

v0.2.03 has the update. Try it out and let me know.

alfonsosiloniz commented 9 months ago

Oh. I see that I get you confused with my text. Sorry for that. I was testing with 6 seconds segments, having 8 segments with id 0 to id 7. My input video is 48.02 seconds long, so I have 8 segments with that time.

I am trying the last version. I need to confirm one thing. Does m3ufu requires python 3.9 ? As I am having an exception in https://github.com/futzu/x9k3/blob/f8eac35117cf382831dce8fe74972337131aa877/x9k3.py#L162 because is using the removeprefix method in the constructor of a Segment, that it seems to be python 3.9

futzu commented 9 months ago

x9k3 v0.2.05 should fix the lag from the m3ufu throttling, you still want to fill the window though.

What version of python are you using?

I try to stay a few releases back from the newest release.

I didn't realize removeprefix was 3.9, but 3.9 is reasonable, 3.12 is the latest.

if you just flatly refuse to update python

engine seconds
Python 3.11.5 12.993
PyPy 7.3.12 3.437
alfonsosiloniz commented 9 months ago

Thansk for the indications.

Just wanted to know cause the m3ufu readme indicated 3.6+

I will try it later to confirm. thanks!

futzu commented 9 months ago

you cool on this?

futzu commented 9 months ago

I fixed the m3ufu remove prefix thing, update to the latest x9k3 0.2.09. I also added support for m3u8 input files, so you can re-segment, re-size segments and add SCTE-35 to an exist m3u8 file via sidecar file.

futzu commented 9 months ago

grab v0.2.19, I think things are working a bit better.

alfonsosiloniz commented 9 months ago

Confirm it works with v0.2.19. Now it plays correctly. Thank you!!