Package: x9k3
Install|Use|CUE-OUT|CUE-IN|SCTE-35 Tags|Sidecar SCTE35|Byterange|playlist|Live|BugsHLS + SCTE35 =x9k3x9k3is a HLS segmenter with SCTE-35 injection and parsing, powered by threefive.Current Version:v.0.2.57Theonly supported version is the current version. Keep up.Some of the new stuff:x9k3 can now generatebyterangem3u8 files with-bor--byterangePlaylistscan now be used as input.Segmentstart timeis now always read, never calculated.Segmentduration verificationfor segments that exceed thetarget duration.adbreakscript to generate SCTE-35 Cues.m3u8 files as input. Resegment and add SCTE-35 to an existing m3u8.-i INPUT,--input INPUTcontinue an m3u8 file.Segments may be added to an existing m3u8, VOD or live.-c,--continue_m3u8discontinuity tagsmay now beomitted.-n,--no_discontinuityautoCUE-INlivethrottlingcan bedisabledwith the-N,--no_throttleflagHeads Upadbreakincluded with x9k3adbreak generates SCTE35 Cues for CUE-OUT and CUE-IN in a sidecar file.$adbreak-husage:adbreak[-h][-dDURATION][-pPTS][-sSIDECAR]options:-h,--help            show this help message and exit-dDURATION,--duration DURATIONsetdurationofadbreak.[default:60.0]-pPTS,--pts PTS     set start pts for ad break. Not setting pts willgenerateaSpliceImmediateCUE-OUT.[default:0.0]-sSIDECAR,--sidecar SIDECARSidecarfileofSCTE-35(pts,cue)pairs.[default:sidecar.txt]Usage:adbreak--pts 1234.567890 --duration 30 --sidecar sidecar.txtsidecar file has SCTE-35 Cues for CUE-OUT and CUE-IN1234.56789,/DAlAAAAAAAAAP/wFAUAAAABf+/+Bp9rxv4AKTLgAAEAAAAAhzvmvQ==1264.56789,/DAgAAAAAAAAAP/wDwUAAAABf0/+BsiepgABAAAAAPh51T0=pass to x9k3x9k3-iinput.ts-ssidecar.txtFeaturesSCTE-35 CuesinMpegts Streamsare Translated intoHLS tags.SCTE-35 Cues can be added from aSidecar File.Segments areSplit on SCTE-35 Cuesas needed.SegmentsStart on iframes.Supportsh264andh265.Multi-protocol.Input sources may beFiles, Http(s), Multicast, and Unicast UDP streams.SupportsLiveStreaming.amt-playuses x9k3.Requirespython 3.6+ or pypy3threefivenew_readeriframesInstallUse pip to install the the x9k3 lib and  executable script x9k3 (will install threefive, new_reader and iframes too)#python3python3-mpipinstallx9k3#pypy3pypy3-mpipinstallx9k3⇪ topDetailsX-SCTE35,X-CUE,X-DATERANGE, orX-SPLICEPOINTHLS tags can be generated. set with the--hls_tagswitch.reading from stdin now availableSegments are cut on iframes.Segment time is 2 seconds or more, determined by GOP size. Can be set with the-tswitch or by settingX9K3.args.timeSegments are named seg1.ts seg2.ts etc...For SCTE-35, Video segments are cut at the the first iframe >=  the splice point pts.If no pts time is present in the SCTE-35 cue, the segment is cut at the next iframe.SCTE-35 cues with a preroll are inserted at the splice point.How to Useclia@fu:~/x9k3-repo$x9k3-husage:x9k3[-h] [-iINPUT] [-b] [-c] [-d] [-l] [-n] [-N] [-oOUTPUT_DIR] [-p]
            [-r] [-sSIDECAR_FILE] [-S] [-tTIME] [-THLS_TAG]
            [-wWINDOW_SIZE] [-v]optionalarguments:-h,--helpshowthishelpmessageandexit-iINPUT,--inputINPUTTheInputvideocanbempegtsorm3u8withmpegtssegments,oraplaylistwithmpegtsfilesand/ormpegtsm3u8files.Theinputcanbealocalvideo,http(s),udp,multicastorstdin.-b,--byterangeFlagforbyterangehls[default:False]-c,--continue_m3u8Resumewritingindex.m3u8[default:False]-d,--deletedeletesegments(enables--live) [default:False]-l,--liveFlagforaliveevent(enablesslidingwindowm3u8)
                        [default:False]-n,--no_discontinuityFlagtodisableadding#EXT-X-DISCONTINUITYtagsatsplicepoints[default:False]-N,--no-throttledisablelivethrottling[default:False]-oOUTPUT_DIR,--output_dirOUTPUT_DIRDirectoryforsegmentsandindex.m3u8(createdifneeded) [default:'.']-p,--program_date_timeFlagtoaddProgramDateTimetagstoindex.m3u8(enables--live) [default:False]-r,--replayFlagforreplayakalooping(enables--live,--delete)
                        [default:False]-sSIDECAR_FILE,--sidecar_fileSIDECAR_FILESidecarfileofSCTE-35(pts,cue)pairs.[default:None]-S,--shulgaFlagtoenableShulgaiframedetectionmode[default:False]-tTIME,--timeTIMESegmenttimeinseconds[default:2]-THLS_TAG,--hls_tagHLS_TAGx_scte35,x_cue,x_daterange,orx_splicepoint[default:x_cue]-wWINDOW_SIZE,--window_sizeWINDOW_SIZEslidingwindowsize(enables--live) [default:5]-v,--versionShowversionExample Usagelocal file as inputx9k3-ivideo.mpegtsmulticast stream as input with a live sliding windowx9k3--live-iudp://@235.35.3.5:3535Live mode works with a live source or static files.x9k3 will throttle segment creation to mimic a live stream.x9k3--live-i/some/video.tslive sliding window and deleting expired segmentsx9k3-iudp://@235.35.3.5:3535--deletehttps stream for input, and writing segments to an output directorydirectory will be created if it does not exist.x9k3-ihttps://so.slo.me/longb.ts--output_dir/home/a/variant0https hls m3u8 for input, and inserting SCTE-35 from a sidecar file, and continuing from a previously create index.m3u8 in the output dirx9k3-ihttps://slow.golf/longb.m3u8--output_dir/home/a/variant0-continue_m3u8-ssidecar.txtusing stdin as inputcatvideo.ts|x9k3live m3u8 file as input, add SCTE-35 from a sidecar file, change segment duration to 3 and output as live streamx9k3-ihttps://example.com/rendition.m3u8-ssidecar.txt-t3-l⇪ topProgrammaticallyUp and Running in three Linesfromx9k3importX9K3#1x9=X9K3('/home/a/cool.ts')#2x9.decode()#3Writing Code with x9k3you can get a complete set of args and the defaults like thisfromx9k3importX9K3x9=X9K3()>>>>{print(k,':',v)fork,vinvars(x9.args).items()}input:<_io.BufferedReadername='<stdin>'>continue_m3u8:Falsedelete:Falselive:Falseno_discontinuity:Falseno_throttle:Falseoutput_dir:.program_date_time:Falsereplay:Falsesidecar_file:Noneshulga:Falsetime:2hls_tag:x_cuewindow_size:5version:Falseor just>>>>print(x9.args)Namespace(input=<_io.BufferedReadername='<stdin>'>,continue_m3u8=False,delete=False,live=False,no_discontinuity=False,no_throttle=False,output_dir='.',program_date_time=False,replay=False,sidecar_file=None,shulga=False,time=2,hls_tag='x_cue',window_size=5,version=False)Setting  parametersfromx9k3importX9K3x9=X9K3()input sourcex9.args.input="https://futzu.com/xaa.ts"hls_tagcan be x_scte35, x_cue, x_daterange, or x_splicepointx9.args.hlstag=x_cueoutput directorydefault is "."x9.args.output_dir="/home/a/stuff"livex9.args.live=Truereplay(loop video) ( also sets live )x9.args.replay=Truedeletesegments when they expire ( also sets live )x9.args.delete=Trueaddprogram date timetags ( also sets live )x9.args.program_date_time=Truesetwindow sizefor live mode ( requires live )x9.args.window_size=5runx9.decode()⇪ topbyterangewith the cli toolusefull path to video filewhen creating byterange m3u8.x9k3-i/home/a/input.ts-bprogrammaticallyfromx9k3importX9K3x9=X9K3()x9.self.args.byterange=Truex9.decode()output#EXTM3U#EXT-X-VERSION:4#EXT-X-TARGETDURATION:3#EXT-X-MEDIA-SEQUENCE:0#EXT-X-DISCONTINUITY-SEQUENCE:0#EXT-X-X9K3-VERSION:0.2.55#EXTINF:2.000000,#EXT-X-BYTERANGE:135548@0msnbc1000.ts#EXTINF:2.000000,#EXT-X-BYTERANGE:137992@135548msnbc1000.ts#EXTINF:2.000000,#EXT-X-BYTERANGE:134796@273540msnbc1000.ts#EXTINF:2.000000,#EXT-X-BYTERANGE:140436@408336msnbc1000.ts#EXTINF:2.000000,#EXT-X-BYTERANGE:130096@548772msnbc1000.ts<SNIP>playlistsplaylists can be used as inputplaylist files must end in.playlistlines are  video or  video, sidecarif video,sidecar, the sidecar file only applies to that videoplaylists can have mpegts video, mpegts m3u8, and playlists.example playlistf10.ts,f10sidecar.txt#commentscanbeheref17.tsf60.tsflat-striped.ts#Commentscangoheretoo.flat.tsinput.tsnmax.tsnmx.ts,nmx-sidecar.txthttps://futzu.com/xaa.tshttps://example.com/index.m3u8,another-sidecar.txtusingx9k3-iout.playlistSidecar Filesload scte35 cues from a Sidecar fileSidecar Cues will be handled the same as SCTE35 cues from a video stream.line format for text fileinsert_pts, cuepts is the insert time for the cue, A four second preroll is standard.
cue can be base64,hex, int, or bytesa@debian:~/x9k3$catsidecar.txt38103.868589,/DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==38199.918911,/DAsAAAAAAAAAP/wDwUAAABef0/+zPACTQAAAAAADAEKQ1VFSbGfMTIxIxGolm0=x9k3-inoscte35.ts-ssidecar.txtIn Live Mode you can do dynamic cue injection with aSidecar filetouchsidecar.txtx9k3-ivid.ts-ssidecar.txt-l#Openanotherterminalandprintfcuesintosidecar.txtprintf'38103.868589, /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==\n'>sidecar.txtSidecar filescan now accept 0 as the PTS insert time for Splice Immediate.Specify 0 as the insert time,  the cue will be insert at the start of the next segment.Using 0 only works in live modeprintf'0,/DAhAAAAAAAAAP/wEAUAAAAJf78A/gASZvAACQAAAACokv3z\n'>sidecar.txt⇪ topA CUE-OUT can be terminated early using asidecar file.In the middle of a CUE-OUT send a splice insert with the out_of_network_indicator flag not set and the splice immediate flag set.
Do the steps above ,
and then do thisprintf'0,/DAcAAAAAAAAAP/wCwUAAAABfx8AAAEAAAAA3r8DiQ==\n'>sidecar.txtIt will cause the CUE-OUT to end at the next segment start.#EXT-X-CUE-OUT13.4./seg5.ts:start:112.966667end:114.966667duration:2.233334#EXT-X-CUE-OUT-CONT2.233334/13.4./seg6.ts:start:114.966667end:116.966667duration:2.1#EXT-X-CUE-OUT-CONT4.333334/13.4./seg7.ts:start:116.966667end:118.966667duration:2.0#EXT-X-CUE-OUT-CONT6.333334/13.4./seg8.ts:start:117.0end:119.0duration:0.033333#EXT-X-CUE-INNone./seg9.ts:start:119.3end:121.3duration:2.3Using 0 only works in live modeCUESCUE-OUTA CUE-OUT is defined as:A Splice Insert Commandwith:theout_of_network_indicatorset toTrueabreak_duration.A Time Signal Commandand a Segmentation Descriptor with:asegmentation_durationasegmentation_type_idof:0x22: "Break Start",0x30: "Provider Advertisement Start",0x32: "Distributor Advertisement Start",0x34: "Provider Placement Opportunity Start",0x36: "Distributor Placement Opportunity Start",0x44: "Provider Ad Block Start",0x46: "Distributor Ad Block Start",⇪ topCUE-INA CUE-IN is defined as:A Splice Insert Commandwith theout_of_network_indicatorset toFalseA Time Signal Commandand a Segmentation Descriptor with:asegmentation_type_idof:0x23: "Break End",0x31: "Provider Advertisement End",0x33: "Distributor Advertisement End",0x35: "Provider Placement Opportunity End",0x37: "Distributor Placement Opportunity End",0x45: "Provider Ad Block End",0x47: "Distributor Ad Block End",For CUE-OUT and CUE-IN,only the first Segmentation Descriptor will be usedSupported HLS  Tags#EXT-X-CUE#EXT-X-DATERANGE#EXT-X-SCTE35#EXT-X-SPLICEPOINTx_cueCUE-OUT#EXT-X-DISCONTINUITY#EXT-X-CUE-OUT:242.0#EXTINF:4.796145,seg32.tsCUE-OUT-CONT#EXT-X-CUE-OUT-CONT:4.796145/242.0#EXTINF:2.12,CUE-IN#EXT-X-DISCONTINUITY#EXT-X-CUE-IN#EXTINF:5.020145,seg145.tsx_scte35CUE-OUT#EXT-X-DISCONTINUITY#EXT-X-SCTE35:CUE="/DAvAAAAAAAAAP/wFAUAAAKWf+//4WoauH4BTFYgAAEAAAAKAAhDVUVJAAAAAOv1oqc=",CUE-OUT=YES#EXTINF:4.796145,seg32.tsCUE-OUT-CONT#EXT-X-SCTE35:CUE="/DAvAAAAAAAAAP/wFAUAAAKWf+//4WoauH4BTFYgAAEAAAAKAAhDVUVJAAAAAOv1oqc=",CUE-OUT=CONT#EXTINF:2.12,seg33.tsCUE-IN#EXT-X-DISCONTINUITY#EXT-X-SCTE35:CUE="/DAqAAAAAAAAAP/wDwUAAAKWf0//4rZw2AABAAAACgAIQ1VFSQAAAAAtegE5",CUE-IN=YES#EXTINF:5.020145,seg145.tsx_daterangeCUE-OUT#EXT-X-DISCONTINUITY#EXT-X-DATERANGE:ID="1",START-DATE="2022-10-14T17:36:58.321731Z",PLANNED-DURATION=242.0,SCTE35-OUT=0xfc302f00000000000000fff01405000002967fefffe16a1ab87e014c562000010000000a00084355454900000000ebf5a2a7#EXTINF:4.796145,seg32.tsCUE-IN#EXT-X-DISCONTINUITY#EXT-X-DATERANGE:ID="2",END-DATE="2022-10-14T17:36:58.666073Z",SCTE35-IN=0xfc302a00000000000000fff00f05000002967f4fffe2b670d800010000000a000843554549000000002d7a0139#EXTINF:5.020145,seg145.tsx_splicepointCUE-OUT#EXT-X-DISCONTINUITY#EXT-X-SPLICEPOINT-SCTE35:/DAvAAAAAAAAAP/wFAUAAAKWf+//4WoauH4BTFYgAAEAAAAKAAhDVUVJAAAAAOv1oqc=#EXTINF:4.796145,seg32.tsCUE-IN#EXT-X-DISCONTINUITY#EXT-X-SPLICEPOINT-SCTE35:/DAqAAAAAAAAAP/wDwUAAAKWf0//4rZw2AABAAAACgAIQ1VFSQAAAAAtegE5#EXTINF:5.020145,seg145.ts⇪ topVODx9k3 defaults to VOD style playlist generation.All segment are listed in the m3u8 file.LiveActivated by the--live,--delete, or--replayswitch or by settingX9K3.live=True--liveLike VOD except:M3u8 manifests are regenerated every time a segment is writtenSegment creation is throttled when using non-live sources to simulate live streaming. ( like ffmpeg's "-re" )default Sliding Window size is 5, it can be changed with the-wswitch or by settingX9k3.window.size--deleteimplies--livedeletes segments when they move out of the sliding window of the m3u8.--replayimplies--liveimplies--deleteloops a video file and throttles segment creation to fake a live stream.⇪ top