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

Allow media-sequence to continue from last saved index.m3u8 #4

Closed josepowera closed 1 year ago

josepowera commented 1 year ago

When x9k3 is restarted it could keep media-sequence going on - it would reread last index.m3u8. If developer want's to reset mediaseq it could just delete index.m3u8 before start.

Reason: if we run x9k3 on LIVE and sidecar.txt gets big, we can't delete sidecar.txt without breaking clients. (when sidecar.txt is deleted x9k3 crashes).

Alternative could be to allow to receive sidecar txt lines using TCP/UDP just to leave sidecar.txt out.

futzu commented 1 year ago

I'm sure it does crash if you delete the file its reading :) TCP connect to send SCTE35 is called SCTE 104, I just don't have the time to do all that any time soon. If you want to hire me, I can do it for you.

hold on, I think I have an idea.....

futzu commented 1 year ago

try this out, it blanks out the sidecar file each time it loads the cues.

from x9k3 import X9K3
from new_reader import reader
from collections import deque
from operator import itemgetter

class X9K5(X9K3):

    def load_sidecar(self, file, pid):
        """
        load_sidecar reads (pts, cue) pairs from
        the sidecar file and loads them into X9K3.sidecar
        if live, blank out the sidecar file after cues are loaded.
        """
        if self.sidecar_file:
            with reader(file) as sidefile:
                for line in sidefile:
                    line = line.decode().strip().split("#", 1)[0]
                    if len(line):
                        pts, cue = line.split(",", 1)
                        if float(pts) >= self.pid2pts(pid):
                            if [float(pts), cue] not in self.sidecar:
                                print("loading",pts,cue)
                                self.sidecar.append([float(pts), cue])
                                self.sidecar = deque(
                                    sorted(self.sidecar, key=itemgetter(0))
                                )
                sidefile.close()
            if self.live:
                with open(self.sidecar_file,'w') as scf:
                    scf.close()

if __name__ == "__main__":
    stuff = X9K5()
    stuff.run()
futzu commented 1 year ago

This fix is in 0.1.49