Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
alfonsosiloniz opened this issue Nov 14, 2023 · 11 comments
Closed

Comments

@alfonsosiloniz
Copy link

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
Copy link
Owner

futzu commented Nov 19, 2023

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

@futzu
Copy link
Owner

futzu commented Nov 20, 2023

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

  • If you are trying to recover from a crash, you can't do it fast enough for it not to error the client.

  • If you're trying to concatenate videos use a FIFO socket or cat.

  • Why would you ever use continue with replay?

  • Why would you ever use 0 second segments?

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

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

@alfonsosiloniz
Copy link
Author

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
Copy link
Owner

futzu commented Nov 20, 2023

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.

  • If you're testing,
    • use at least a video that fills your window size. For example if you have a window size of 5 and a segment duration of 6 , use at least 35 - 40 seconds. Really short video like 10 seconds, will tend to hang, because of the segments being deleted.
    • There is about a half a second pause at the end of the video, I believe it's because m3ufu and x9k3 throttling, I haven't figured out the best way to address that yet.

Other than those two details it should be cool.

  • Discontinuity sequence count is now incrementing correctly as well.

Here's the commit

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

@alfonsosiloniz
Copy link
Author

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
Copy link
Owner

futzu commented Nov 21, 2023

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

  • line 259 in m3ufu.py
        self.relative_uri = media_uri.removeprefix(base_uri)
  • change it to
        self.relative_uri = media_uri.replace(base_uri,'')

I use pypy3, it's way faster. Check this out.

  • the file
a@fu:~$ ls -alh msnbc.ts
-rw-r--r-- 1 a a 3.3G Oct 25 04:24 msnbc.ts
  • parsing it with threefive
engine seconds
Python 3.11.5 12.993
PyPy 7.3.12 3.437

@alfonsosiloniz
Copy link
Author

Thansk for the indications.

Just wanted to know cause the m3ufu readme indicated 3.6+

I will try it later to confirm. thanks!

@futzu
Copy link
Owner

futzu commented Nov 27, 2023

you cool on this?

@futzu
Copy link
Owner

futzu commented Nov 27, 2023

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
Copy link
Owner

futzu commented Dec 4, 2023

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

@alfonsosiloniz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants