Package: sideways
There has got to be a better way.This is the better way.Sideways is SCTE-35 Injection for live ABR HLSLatest Version is0.0.23released 02/13/2024Input is a master.m3u8 file,local or over http(s), as input.SCTE-35 data is from asidecar file.The master. m3u8 and rendition index.m3u8 files are rewritten locally on your server with SCTE-35 Added to them.Segments with a CUE-OUT or CUE-IN tag in them, they are split at the SCTE-35 splicepoint.It's fast, light on the network, and uses very little CPU time.#EXTM3U#EXT-X-VERSION:4<---headersandsettingsarecopiedover.#EXT-X-TARGETDURATION:7#EXTINF:6.0https://example.com/0/seg541.ts    <-- expands existing segment URI, but doesn't parse the segments#EXTINF:0.266667./0/a-seg542.ts<---WhenthereisaSCTE-35Cue,itsplitsthesegmentatthesplicepoint.#EXT-X-CUE-OUT:13.0#EXT-X-DISCONTINUITY#EXTINF:5.466666./0/b-seg542.ts<--thesecondsplitsegmentisthewheretheCUE-OUTstarts#EXT-X-CUE-OUT-CONT:5.466666/13.0#EXTINF:6.0https://example.com/0/seg543.ts     <--- during  the ad break, the segments are not parsed, URIs are expanded.#EXT-X-CUE-OUT-CONT:11.466666/13.0#EXTINF:1.533334./0/a-seg544.ts#EXT-X-CUE-IN#EXT-X-DISCONTINUITY#EXTINF:4.199999./0/b-seg544.ts#EXTINF:6.0https://example.com/0/seg545.tsThe new master.m3u8 is written to your serverEach rendition has an index.m3u8 and just the split segments in sub directories on your server.Each sub-directory looks like thisls0/a-seg542.tsb-seg542.tsa-seg544.tsb-seg544.tsindex.m3u8sidecar.txtHow to UseInstallpython3-mpipinstallsidewaysCli toola@fu:~$sideways-husage:sideways[-h][-iINPUT][-sSIDECAR_FILE][-oOUTPUT_DIR][-tHLS_TAG][-v]options:-h,--helpshowthishelpmessageandexit-iINPUT,--inputINPUTInputsource,isamaster.m3u8(localorhttp(s)withMPEGTSsegmentsdefault:None-sSIDECAR_FILE,--sidecar_fileSIDECAR_FILESCTE-35Sidecarfiledefault:None-oOUTPUT_DIR,--output_dirOUTPUT_DIRoutputdirectorydefault:None-THLS_TAG,--hls_tagHLS_TAGx_scte35,x_cue,x_daterange,orx_splicepointdefault:x_cue-v,--versionShowversion-iInput is a master.m3u8, local or over a network via http(s)-sthe sidecar file with  PTS,Cue pairs.Sidecar File details-oOutput is a directory on your system, the default is the current directory.The new master.m3u8 is written to the output directory.Each rendition has a numerical subdirectory, starting a 0.rendition sub-directories have an index.m3u8When segments are split for SCTE-35 splice points, the split segments are stored in the rendition subdiectory.-THLS_TAG has been lightly tested. The default x_cue works well, x_daterange works too. I havent really tested the others.Running:thesidecar filecontains two lines, a CUE-OUT and a CUE-IN, the  ad break is for 17 seconds.3274.0,/DAlAAAAAAAAAP/wFAUAAAABf+/+EZAnoP4AF1iQAAEAAAAAE5sHRg==3291.0,/DAgAAAAAAAAAP/wDwUAAAABf0/+EaeAMAABAAAAAJlXlzg=the commanda@fu:~/testme$ sideways -i /home/a/foam4/master.m3u8 -s ../sidecar.txtthe outputa@fu:~/testme$ ls -R.:01master.m3u8./0:a-seg544.tsa-seg547.tsb-seg544.tsb-seg547.tsindex.m3u8sidecar.txt./1:a-seg544.tsa-seg547.tsb-seg544.tsb-seg547.tsindex.m3u8sidecar.txt0 and 1 are renditon sub-directories.When a segment is split for SCTE-35 the name is prepended with a- and b-sideways  writes a copy of the sidecar to each rendition directoryyou can play the master.m3u8.the SCTE-35 Cues come out like this:#start:3268.266667#EXTINF:5.733333./0/a-seg544.ts<--seg544.tsissplitintoa-seg544.tsandb-seg544.ts.#start:3274.0#EXT-X-CUE-OUT:17.0#EXT-X-DISCONTINUITY#EXTINF:0.266667./0/b-seg544.ts<--Thesplicepointisalwaysatthestartofb-segment.#start:3274.266667#EXT-X-CUE-OUT-CONT:0.266667/17.0#EXTINF:6.0/home/a/foam4/0/seg545.ts#start:3280.266667#EXT-X-CUE-OUT-CONT:6.266667/17.0#EXTINF:6.0/home/a/foam4/0/seg546.ts#start:3286.266667#EXT-X-CUE-OUT-CONT:12.266667/17.0#EXTINF:4.733333./0/a-seg547.ts#start:3291.0#EXT-X-CUE-IN#EXT-X-DISCONTINUITY#EXTINF:1.266667./0/b-seg547.ts#start:3292.266667Sidecar filesload scte35 cues from a Sidecar fileSidecar Cues will be handled the same as SCTE35 cues from a video stream.line format for text file insert_pts, cuepts is the insert time for the cue, cue can be base64,hex, int, or bytesa@debian:~/sidweways$catsidecar.txt38103.868589,/DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==38199.918911,/DAsAAAAAAAAAP/wDwUAAABef0/+zPACTQAAAAAADAEKQ1VFSbGfMTIxIxGolm0=you can do dynamic cue injection with a Sidecar filetouchsidecar.txtsideways-imaster.m3u8-ssidecar.txt-obobOpen another terminal and printf cues into sidecar.txtprintf'38103.868589, /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==\n'>sidecar.txtA CUE-OUT can be terminated early using a sidecar file.