Giter VIP home page Giter VIP logo

x9k3's Introduction

Install | Use | CUE-OUT | CUE-IN | SCTE-35 Tags | Sidecar SCTE35 | Byterange m3u8 | Playlists | Live hls | Bugs | Online SCTE-35 encoder


Q. Is x9k3 production ready?

A. I believe so.

I have an x9k3 instance on my server that has been running for 530 Days nonstop.

image

Current Version: v.0.2.57

The only supported version is the current version. Keep up.

  • Some of the new stuff:
    • x9k3 can now generate byterange m3u8 files with -b or --byterange
    • Playlists can now be used as input.
    • Segment start time is now always read, never calculated.
    • Segment duration verification for segments that exceed the target duration.
    • adbreak script to generate SCTE-35 Cues.
    • m3u8 files as input. Resegment and add SCTE-35 to an existing m3u8. -i INPUT, --input INPUT
    • continue an m3u8 file. Segments may be added to an existing m3u8, VOD or live. -c, --continue_m3u8
    • discontinuity tags may now be omitted. -n, --no_discontinuity
    • auto CUE-IN
    • live throttling can be disabled with the -N, --no_throttle flag

Heads Up

adbreak

  • included with x9k3
  • adbreak generates SCTE35 Cues for CUE-OUT and CUE-IN in a sidecar file.
$ adbreak -h
usage: adbreak [-h] [-d DURATION] [-p PTS] [-s SIDECAR]

options:
  -h, --help            show this help message and exit
  -d DURATION, --duration DURATION
                        set duration of ad break. [ default: 60.0 ]
  -p PTS, --pts PTS     set start pts for ad break. Not setting pts will
                        generate a Splice Immediate CUE-OUT. [ default: 0.0 ]
  -s SIDECAR, --sidecar SIDECAR
                        Sidecar file of SCTE-35 (pts,cue) pairs. [ default:
                        sidecar.txt ]

  • Usage:
adbreak --pts 1234.567890 --duration 30 --sidecar sidecar.txt
  • sidecar file has SCTE-35 Cues for CUE-OUT and CUE-IN
1234.56789,/DAlAAAAAAAAAP/wFAUAAAABf+/+Bp9rxv4AKTLgAAEAAAAAhzvmvQ==
1264.56789,/DAgAAAAAAAAAP/wDwUAAAABf0/+BsiepgABAAAAAPh51T0=
  • pass to x9k3
x9k3 -i input.ts -s sidecar.txt

Features

  • SCTE-35 Cues in Mpegts Streams are Translated into HLS tags.
  • SCTE-35 Cues can be added from a Sidecar File.
  • Segments are Split on SCTE-35 Cues as needed.
  • Segments Start on iframes.
  • Supports h264 and h265 .
  • Multi-protocol. Input sources may be Files, Http(s), Multicast, and Unicast UDP streams.
  • Supports Live Streaming.
  • amt-play uses x9k3.

Requires

Install

  • Use pip to install the the x9k3 lib and executable script x9k3 (will install threefive, new_reader and iframes too)
# python3

python3 -mpip install x9k3

# pypy3 

pypy3 -mpip install x9k3

⇪ top

Details

  • X-SCTE35, X-CUE, X-DATERANGE, or X-SPLICEPOINT HLS tags can be generated. set with the --hls_tag switch.

  • reading from stdin now available

  • Segments are cut on iframes.

  • Segment time is 2 seconds or more, determined by GOP size. Can be set with the -t switch or by setting X9K3.args.time

  • Segments 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 Use

cli

a@fu:~/x9k3-repo$ x9k3 -h
usage: x9k3 [-h] [-i INPUT] [-b] [-c] [-d] [-l] [-n] [-N] [-o OUTPUT_DIR] [-p]
            [-r] [-s SIDECAR_FILE] [-S] [-t TIME] [-T HLS_TAG]
            [-w WINDOW_SIZE] [-v]

optional arguments:
  -h, --help            show this help message and exit

  -i INPUT, --input INPUT
                        The Input video can be mpegts or m3u8 with mpegts
                        segments, or a playlist with mpegts files and/or
                        mpegts m3u8 files. The input can be a local video,
                        http(s), udp, multicast or stdin.

  -b, --byterange       Flag for byterange hls [default:False]

  -c, --continue_m3u8   Resume writing index.m3u8 [default:False]

  -d, --delete          delete segments (enables --live) [default:False]

  -l, --live            Flag for a live event (enables sliding window m3u8)
                        [default:False]
  -n, --no_discontinuity
                        Flag to disable adding #EXT-X-DISCONTINUITY tags at
                        splice points [default:False]

  -N, --no-throttle     disable live throttling [default:False]

  -o OUTPUT_DIR, --output_dir OUTPUT_DIR
                        Directory for segments and index.m3u8(created if
                        needed) [default:'.']

  -p, --program_date_time
                        Flag to add Program Date Time tags to index.m3u8 (
                        enables --live) [default:False]

  -r, --replay          Flag for replay aka looping (enables --live,--delete)
                        [default:False]

  -s SIDECAR_FILE, --sidecar_file SIDECAR_FILE
                        Sidecar file of SCTE-35 (pts,cue) pairs.
                        [default:None]

  -S, --shulga          Flag to enable Shulga iframe detection mode
                        [default:False]

  -t TIME, --time TIME  Segment time in seconds [default:2]

  -T HLS_TAG, --hls_tag HLS_TAG
                        x_scte35, x_cue, x_daterange, or x_splicepoint
                        [default:x_cue]

  -w WINDOW_SIZE, --window_size WINDOW_SIZE
                        sliding window size (enables --live) [default:5]

  -v, --version         Show version

Example Usage

local file as input

   x9k3 -i video.mpegts

multicast stream as input with a live sliding window

x9k3 --live -i udp://@235.35.3.5:3535

Live mode works with a live source or static files.

  • x9k3 will throttle segment creation to mimic a live stream.
x9k3 --live -i /some/video.ts

live sliding window and deleting expired segments

x9k3  -i udp://@235.35.3.5:3535 --delete

https stream for input, and writing segments to an output directory

  • directory will be created if it does not exist.
  x9k3 -i https://so.slo.me/longb.ts --output_dir /home/a/variant0

https hls m3u8 for input, and inserting SCTE-35 from a sidecar file, and continuing from a previously create index.m3u8 in the output dir

  x9k3 -i https://slow.golf/longb.m3u8 --output_dir /home/a/variant0 -continue_m3u8 -s sidecar.txt

using stdin as input

cat video.ts | x9k3

live m3u8 file as input, add SCTE-35 from a sidecar file, change segment duration to 3 and output as live stream

x9k3 -i https://example.com/rendition.m3u8 -s sidecar.txt -t 3 -l

⇪ top

Programmatically

Up and Running in three Lines

        from x9k3 import X9K3            # 1
        x9 = X9K3('/home/a/cool.ts')     # 2
        x9.decode()                      # 3

Writing Code with x9k3

  • you can get a complete set of args and the defaults like this
from x9k3 import X9K3
x9 = X9K3()

>>>> {print(k,':',v) for k,v in vars(x9.args).items()}

input : <_io.BufferedReader name='<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
  • or just
>>>> print(x9.args)

Namespace(input=<_io.BufferedReader name='<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 parameters
from x9k3 import X9K3
x9 = X9K3()
  • input source
x9.args.input = "https://futzu.com/xaa.ts"   
  • hls_tag can be x_scte35, x_cue, x_daterange, or x_splicepoint
x9.args.hls tag = x_cue 
  • output directory default is "."
x9.args.output_dir="/home/a/stuff"
  • live
x9.args.live = True
  • replay (loop video) ( also sets live )
x9.args.replay = True
  • delete segments when they expire ( also sets live )
x9.args.delete = True
  • add program date time tags ( also sets live )
x9.args.program_date_time= True
  • set window size for live mode ( requires live )
x9.args.window_size = 5 
  • run
x9.decode()

⇪ top

byterange

  • with the cli tool
    • use full path to video file when creating byterange m3u8.
x9k3 -i /home/a/input.ts -b
  • programmatically
from x9k3 import X9K3
x9 = X9K3()
x9.self.args.byterange = True
x9.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@0
msnbc1000.ts
#EXTINF:2.000000,
#EXT-X-BYTERANGE:137992@135548
msnbc1000.ts
#EXTINF:2.000000,
#EXT-X-BYTERANGE:134796@273540
msnbc1000.ts
#EXTINF:2.000000,
#EXT-X-BYTERANGE:140436@408336
msnbc1000.ts
#EXTINF:2.000000,
#EXT-X-BYTERANGE:130096@548772
msnbc1000.ts
<SNIP>

playlists

  • playlists can be used as input

  • playlist files must end in .playlist

  • lines are video or video, sidecar

    • if video,sidecar, the sidecar file only applies to that video
  • playlists can have mpegts video, mpegts m3u8, and playlists.

  • example playlist

f10.ts,f10sidecar.txt # comments can be here
f17.ts
f60.ts
flat-striped.ts
# Comments can go here too.
flat.ts
input.ts
nmax.ts
nmx.ts,nmx-sidecar.txt
https://futzu.com/xaa.ts
https://example.com/index.m3u8,another-sidecar.txt
  • using
 x9k3 -i out.playlist

Sidecar Files

load scte35 cues from a Sidecar file

Sidecar Cues will be handled the same as SCTE35 cues from a video stream.
line format for text file insert_pts, cue

pts is the insert time for the cue, A four second preroll is standard. cue can be base64,hex, int, or bytes

a@debian:~/x9k3$ cat sidecar.txt

38103.868589, /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ== 
38199.918911, /DAsAAAAAAAAAP/wDwUAAABef0/+zPACTQAAAAAADAEKQ1VFSbGfMTIxIxGolm0= 

    
x9k3 -i  noscte35.ts  -s sidecar.txt 

In Live Mode you can do dynamic cue injection with a Sidecar file

touch sidecar.txt

x9k3 -i vid.ts -s sidecar.txt -l 

# Open another terminal and printf cues into sidecar.txt

printf '38103.868589, /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==\n' > sidecar.txt

Sidecar files can 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 mode

printf '0,/DAhAAAAAAAAAP/wEAUAAAAJf78A/gASZvAACQAAAACokv3z\n' > sidecar.txt

⇪ top

A CUE-OUT can be terminated early using a sidecar 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 this

printf '0,/DAcAAAAAAAAAP/wCwUAAAABfx8AAAEAAAAA3r8DiQ==\n' > sidecar.txt

It will cause the CUE-OUT to end at the next segment start.

#EXT-X-CUE-OUT 13.4
./seg5.ts:	start:112.966667	end:114.966667	duration:2.233334
#EXT-X-CUE-OUT-CONT 2.233334/13.4
./seg6.ts:	start:114.966667	end:116.966667	duration:2.1
#EXT-X-CUE-OUT-CONT 4.333334/13.4
./seg7.ts:	start:116.966667	end:118.966667	duration:2.0
#EXT-X-CUE-OUT-CONT 6.333334/13.4
./seg8.ts:	start:117.0	        end:119.0	duration:0.033333
#EXT-X-CUE-IN None
./seg9.ts:	start:119.3	        end:121.3	duration:2.3

Using 0 only works in live mode


CUES

CUE-OUT

A CUE-OUT is defined as:

  • A Splice Insert Command with:

    • the out_of_network_indicator set to True
    • a break_duration.
  • A Time Signal Command and a Segmentation Descriptor with:

    • a segmentation_duration
    • a segmentation_type_id of:
      • 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",

⇪ top

CUE-IN

A CUE-IN is defined as:

  • A Splice Insert Command

    • with the out_of_network_indicator set to False
  • A Time Signal Command and a Segmentation Descriptor with:

    • a segmentation_type_id of:

      • 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 used


Supported HLS Tags

  • #EXT-X-CUE
  • #EXT-X-DATERANGE
  • #EXT-X-SCTE35
  • #EXT-X-SPLICEPOINT

x_cue

  • CUE-OUT
#EXT-X-DISCONTINUITY
#EXT-X-CUE-OUT:242.0
#EXTINF:4.796145,
seg32.ts
  • CUE-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.ts

x_scte35

  • CUE-OUT
#EXT-X-DISCONTINUITY
#EXT-X-SCTE35:CUE="/DAvAAAAAAAAAP/wFAUAAAKWf+//4WoauH4BTFYgAAEAAAAKAAhDVUVJAAAAAOv1oqc=" ,CUE-OUT=YES 
#EXTINF:4.796145,
seg32.ts
  • CUE-OUT-CONT
#EXT-X-SCTE35:CUE="/DAvAAAAAAAAAP/wFAUAAAKWf+//4WoauH4BTFYgAAEAAAAKAAhDVUVJAAAAAOv1oqc=" ,CUE-OUT=CONT
#EXTINF:2.12,
seg33.ts
  • CUE-IN
#EXT-X-DISCONTINUITY
#EXT-X-SCTE35:CUE="/DAqAAAAAAAAAP/wDwUAAAKWf0//4rZw2AABAAAACgAIQ1VFSQAAAAAtegE5" ,CUE-IN=YES 
#EXTINF:5.020145,
seg145.ts

x_daterange

  • CUE-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.ts
  • CUE-IN
#EXT-X-DISCONTINUITY
#EXT-X-DATERANGE:ID="2",END-DATE="2022-10-14T17:36:58.666073Z",SCTE35-IN=0xfc302a00000000000000fff00f05000002967f4fffe2b670d800010000000a000
843554549000000002d7a0139
#EXTINF:5.020145,
seg145.ts

x_splicepoint

  • CUE-OUT
#EXT-X-DISCONTINUITY
#EXT-X-SPLICEPOINT-SCTE35:/DAvAAAAAAAAAP/wFAUAAAKWf+//4WoauH4BTFYgAAEAAAAKAAhDVUVJAAAAAOv1oqc=
#EXTINF:4.796145,
seg32.ts
  • CUE-IN
#EXT-X-DISCONTINUITY
#EXT-X-SPLICEPOINT-SCTE35:/DAqAAAAAAAAAP/wDwUAAAKWf0//4rZw2AABAAAACgAIQ1VFSQAAAAAtegE5
#EXTINF:5.020145,
seg145.ts

⇪ top

VOD

  • x9k3 defaults to VOD style playlist generation.
  • All segment are listed in the m3u8 file.

Live

  • Activated by the --live, --delete, or --replay switch or by setting X9K3.live=True

--live

  • Like VOD except:
    • M3u8 manifests are regenerated every time a segment is written
    • Segment 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 -w switch or by setting X9k3.window.size

--delete

  • implies --live
  • deletes segments when they move out of the sliding window of the m3u8.

--replay

  • implies --live
  • implies --delete
  • loops a video file and throttles segment creation to fake a live stream.

⇪ top

image

x9k3's People

Contributors

chreniuc avatar edward-rafalovsky avatar futzu avatar josepowera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

x9k3's Issues

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

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.

negative EXTINF values and no X_CUE tags from scte35 mpegts stream

I tried generate m3u8 from test xaa.ts video with scte35 stream inside, but found no x_cue tags in result:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXT-X-X9K3-VERSION:0.1.89
#EXTINF:2.002000,
seg0.ts
#EXTINF:2.002011,
seg1.ts
#EXTINF:2.002000,
...
seg27.ts
#EXTINF:2.002011,
seg28.ts
#EXT-X-ENDLIST

I used bin from Dockerfile with cmd: x9k3 -i /src/xaa.ts --output_dir /results

Also it sometimes inserts wrong negative EXTINF values

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXT-X-X9K3-VERSION:0.1.89
#EXTINF:-0.000011,
seg0.ts
#EXTINF:1.001000,
seg1.ts
#EXTINF:1.001000,
seg2.ts
...

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

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.

New: Option to not to use EXT-X-DISCONTINUITY in SCTE35 marks

I've found that the current implementation is always inserting EXT-X-DISCONTINUITY tags in the m3u8 file with the segments when a CUE occurs. When you try to playout the generated playlist, this makes the play to freeze or halt at those points, as the player is trying to resync the play because it is expecting a change in the stream. (this is a guess). I've tested it with hls.js, VLC and native iPhone player with similar results

But if you remove the tags from the playlist, the playout works like a charm with the same segments.

I've not found any documentation that requires that EXT-X-DISCONTINUITY is needed when inserting the CUEs in the playlist. This is needed only when, in the Ad Insertion scenario, the original segments are replaced with a new content that requires to be signalled to the player with the EXT-X-DISCONTINUITY.

I wonder if the usage of EXT-X-DISCONTINUITY could require that the segments generated in those points by the segmenter includes some information that permits to play out that correctly, or just to remove te EXT-X-DISCONTINUITY tags by default.

Transmission dropping

I'm using x9K3 to insert SCTE 35 data and I'm using index.m3u8 to transmit but it suddenly stops and doesn't continue transmission

OS: Debian 12
Comand: sudo x9k3 -i /usr/share/ffplayout/public/live/stream.m3u8 -s sidecar.txt -l

How to create SCTE messages?

I am new to SCTE and need help on creating SCTE messages like below. I need to understand what does these string means and how I can create and use with this package.

  • /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==
  • /DC+AAAAAAAAAP/wBQb+W+M4YgCoAiBDVUVJCW3YD3+fARFEcmF3aW5nRlJJMTE1V0FCQzUBAQIZQ1VFSQlONI9/nwEKVEtSUjE2MDY3QREBAQIxQ1VFSQlw1HB/nwEiUENSMV8xMjEwMjExNDU2V0FCQ0dFTkVSQUxIT1NQSVRBTBABAQI2Q1VFSQlw1HF/3wAAFJlwASJQQ1IxXzEyMTAyMTE0NTZXQUJDR0VORVJBTEhPU1BJVEFMIAEBhgjtJQ==

Note: I have copied these messages from your examples.

I am able to insert them my livestream output using this package piping with ffmpeg.

Any help is highly appriciated.

Thank You

Can't make sidecar pts and cue to working as expected

Hi futzu

FIrst i want to say is Merry christmas and happy new year! and scte35-threefive is amazing projects

i am working on splicing segments to insert cue points.
i use simple example from readme file
x9k3 -i segment11.ts -s sidecar.txt

the segment11.ts is a 6 seconds segment with 25fps and GOP of 25 and ffprobe output for the segment with iframe information
Input #0, mpegts, from segment11.ts:
Duration: 00:00:06.07, start: 66.116444, bitrate: 3159 kb/s
Program 1
Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 99 kb/s
Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn`

1:frame,I
26:frame,I
51:frame,I
76:frame,I
101:frame,I
126:frame,I

and inside my sidecar file i have this
68.191111, /DAWAAAAAAAAAP/wBQb+AF2lcAAAYGVbDg==

i want x9k3 to splice this segement into 2 segments with first one 2 seconds and second one 4 seconds
but it always give me 3 segements in 2 seconds duration. any ideas it is possible with x9k3 or am i using tool wrong.

here is the segments and sidecar file
https://github.com/cisiwen/x9k3_help_needed/tree/main

thanks

Winston

Do You Like The Current Output of X9K3? Do You Have A Better Idea?

Say something.

I am open to suggestions.

./seg29.ts	start: 89731.181667	duration: 2.120000
./seg30.ts	start: 89733.301667	duration: 2.120000
./seg31.ts	start: 89735.421667	duration: 2.120000
./seg32.ts	start: 89737.541667	duration: 2.120000
#EXT-X-CUE-OUT:242.0
./seg33.ts	start: 89739.661667	duration: 2.520000
#EXT-X-CUE-OUT-CONT:2.520/242.0
./seg34.ts	start: 89742.181667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:4.640/242.0
./seg35.ts	start: 89744.301667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:6.760/242.0
./seg36.ts	start: 89746.421667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:8.880/242.0
./seg37.ts	start: 89748.541667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:11.000/242.0
./seg38.ts	start: 89750.661667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:13.120/242.0
./seg39.ts	start: 89752.781667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:15.240/242.0
./seg40.ts	start: 89754.901667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:17.360/242.0
./seg41.ts	start: 89757.021667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:19.480/242.0
./seg42.ts	start: 89759.141667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:21.600/242.0
./seg43.ts	start: 89761.261667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:23.720/242.0
./seg44.ts	start: 89763.381667	duration: 2.120000
#EXT-X-CUE-OUT-CONT:25.840/242.0
./seg45.ts	start: 89765.501667	duration: 2.120000
./seg27.ts	start: 89726.941667	duration: 2.120000
./seg28.ts	start: 89729.061667	duration: 2.120000
./seg29.ts	start: 89731.181667	duration: 2.120000
./seg30.ts	start: 89733.301667	duration: 2.120000
./seg31.ts	start: 89735.421667	duration: 2.120000
./seg32.ts	start: 89737.541667	duration: 2.120000
#EXT-X-DATERANGE:ID="1",START-DATE="2022-12-26T21:35:41.398909Z",PLANNED-DURATION=242.0,SCTE35-OUT=0xfc302f00000000000000fff01405000002967fefffe16a1ab87e014c562000010000000a00084355454900000000ebf5a2a7
./seg33.ts	start: 89739.661667	duration: 2.520000
./seg34.ts	start: 89742.181667	duration: 2.120000
./seg35.ts	start: 89744.301667	duration: 2.120000
./seg36.ts	start: 89746.421667	duration: 2.120000
./seg37.ts	start: 89748.541667	duration: 2.120000
./seg38.ts	start: 89750.661667	duration: 2.120000
./seg39.ts	start: 89752.781667	duration: 2.120000

Not inserting cue markers.

Hi Adrian,

I think because of latest changes there is a bug where If I try to add Cue marker immediately with
below sidecar data it is not working.
printf '0,/DAhAAAAAAAAAP/wEAUAAAAJf78A/gASZvAACQAAAACokv3z\n' > sidecar.txt

Where as if replace 0 with Time that is less than next_start it is working.

I think bug is somewhere here if I am not wrong.

x9k3/x9k3.py

Line 375 in 8ed2b65

if self.started <= splice_pts <self.next_start:

Input with multiple resolutions

I'm trying to put an m3u8 input, with 4 resolutions but x9k3 won't work in this case I have 1080p, 720p, 540p and 360p and master.m3u8 that goes to 4 resolutions
saida 2
saidas

error while coverting udp to hls

est_scte/seg56.ts: start: 1572.740000 end: 1578.740000 duration: 6.000000
deleting test_scte/seg51.ts
test_scte/seg57.ts: start: 1578.740000 end: 1584.740000 duration: 6.000000
deleting test_scte/seg52.ts
test_scte/seg58.ts: start: 1584.740000 end: 1590.740000 duration: 6.000000
deleting test_scte/seg53.ts
test_scte/seg59.ts: start: 1590.740000 end: 1596.740000 duration: 6.000000
deleting test_scte/seg54.ts
test_scte/seg60.ts: start: 1596.740000 end: 1602.740000 duration: 6.000000
deleting test_scte/seg55.ts
test_scte/seg61.ts: start: 1602.740000 end: 1608.740000 duration: 6.000000
deleting test_scte/seg56.ts
test_scte/seg62.ts: start: 1608.740000 end: 1614.740000 duration: 6.000000
deleting test_scte/seg57.ts
Traceback (most recent call last):
File "/usr/local/bin/x9k3", line 5, in
cli()
File "/usr/local/lib/python3.6/site-packages/x9k3.py", line 821, in cli
stuff.run()
File "/usr/local/lib/python3.6/site-packages/x9k3.py", line 383, in run
self.decode()
File "/usr/local/lib/python3.6/site-packages/x9k3.py", line 358, in decode
super().decode()
File "/usr/local/lib/python3.6/site-packages/threefive/stream.py", line 225, in decode
cue = self._parse(pkt)
File "/usr/local/lib/python3.6/site-packages/x9k3.py", line 335, in _parse
super()._parse(pkt)
File "/usr/local/lib/python3.6/site-packages/threefive/stream.py", line 454, in _parse
self._parse_pts(pkt, pid)
File "/usr/local/lib/python3.6/site-packages/threefive/stream.py", line 402, in _parse_pts
if self._pts_flag(payload):
File "/usr/local/lib/python3.6/site-packages/threefive/stream.py", line 345, in _pts_flag
return pay[7] & 0x80
IndexError: index out of range
[root@localhost ~]#

Last x9k3 not working correctly with Mpeg2

Hello.
Uses latest x9k3 and threefive. H264 working ok, but Mpeg2 splits with different segments duration(not 2 default seconds). It happened on file or live UDP streams. Looks like it cannot found i-frames in stream.

H264 file https://www.dropbox.com/s/5qswgdnt22ykp6d/test1.ts?dl=0
C:\Python>python.exe x9k3.py -i test1.ts
./seg0.ts start: 45.693333 duration: 2.160000 stream diff: 2.1
28998
./seg1.ts start: 47.853333 duration: 2.160000 stream diff: 4.2
58997
./seg2.ts start: 50.013333 duration: 2.160000 stream diff: 6.3
91995
./seg3.ts start: 52.173333 duration: 2.160000 stream diff: 8.5
25993
./seg4.ts start: 54.333333 duration: 2.160000 stream diff: 10.
658992
./seg5.ts start: 56.493333 duration: 2.160000 stream diff: 12.
79299
./seg6.ts start: 58.653333 duration: 2.160000 stream diff: 14.
925989
./seg7.ts start: 60.813333 duration: 2.160000 stream diff: 17.
059987
./seg8.ts start: 62.973333 duration: 2.160000 stream diff: 19.
192986
./seg9.ts start: 65.133333 duration: 2.160000 stream diff: 21.
325984
./seg10.ts start: 67.293333 duration: 2.160000 stream diff: 23.
459983
./seg11.ts start: 69.453333 duration: 2.160000 stream diff: 25.
592981
./seg12.ts start: 71.613333 duration: 2.160000 stream diff: 27.
72698
./seg13.ts start: 73.773333 duration: 2.160000 stream diff: 29.
860978
./seg14.ts start: 75.933333 duration: 2.160000 stream diff: 31.
993977
./seg15.ts start: 78.093333 duration: 2.160000 stream diff: 34.
124975
./seg16.ts start: 80.253333 duration: 2.160000 stream diff: 36.
257974
./seg17.ts start: 82.413333 duration: 2.160000 stream diff: 38.
390972
./seg18.ts start: 84.573333 duration: 2.160000 stream diff: 40.
52197
./seg19.ts start: 86.733333 duration: 2.160000 stream diff: 42.
653969
./seg20.ts start: 88.893333 duration: 2.160000 stream diff: 44.
784967
./seg21.ts start: 91.053333 duration: 2.160000 stream diff: 46.
913965
./seg22.ts start: 93.213333 duration: 2.160000 stream diff: 49.
045963
./seg23.ts start: 95.373333 duration: 2.160000 stream diff: 51.
175962
./seg24.ts start: 97.533333 duration: 2.160000 stream diff: 53.
30796
./seg25.ts start: 99.693333 duration: 2.160000 stream diff: 55.
437959
./seg26.ts start: 101.853333 duration: 2.160000 stream diff: 57.
569957
./seg27.ts start: 104.013333 duration: 2.160000 stream diff: 59.
701955
./seg28.ts start: 106.173333 duration: 2.160000 stream diff: 61.
831954

MPEG2 file https://www.dropbox.com/s/v5vrnlbqpqsc7xn/test2_mp2.ts?dl=0
C:\Python>python.exe x9k3.py -i test2_mp2.ts
./seg0.ts start: 170.317311 duration: 24.480000 stream diff: 23.
890966

Problematically its not working

I have tried below command

import x9k3
x9 = x9k3.X9K3('media-1/segment-0.ts')
x9.run()

Its stuck and I could not find any reason behind this.

Could you please suggest if I am doing this in correct way or not?

Thank You

How to merge multiple ts input into one output?

I have 5 ts file such as
test_1.ts
test_2.ts
test_3.ts
test_4.ts

I want to pragmatically parse each ts file but my output should be in one directory and one index.m3u8 should created. It like appending to one file.

Below is the sample code but its not working as currently I don't know how to do this.
import x9k3 for ts in multiple_ts: x9 = x9k3.X9K3(ts) x9.args.output_dir="output/" x9.run()

Thank you

New: --replay should not include -c by default

After adding the -c option to being able to continue a previously generated m3u8, the replay option included this option by default.

IMHO replay is an option that implies the usage of one file to produce a live feed. Not necesarily that means the previous content in the output directory is meaningful.

I would suggest to decouple --replay and -c, so if someone needs it for replay, can add it explicitely

auto return not working?

I'm using tsduck to inject SCTE35 Markers with
...
<splice_insert splice_event_id="0x00000001" out_of_network="true" splice_immediate="true" unique_program_id="0x0001">
<break_duration auto_return="true" duration="2,150,000"/>
</splice_insert>
...
However, the ad breaks runs forever:

#EXT-X-CUE-OUT-CONT:825.560/23.888889
#EXTINF:3.840,
seg1796.ts
#EXT-X-CUE-OUT-CONT:829.400/23.888889
#EXTINF:3.840,
seg1797.ts
#EXT-X-CUE-OUT-CONT:833.240/23.888889
#EXTINF:3.840,

I'm a total python newbie, but looking at the code, the _auto_return is never called / tested. Where should I insert the auto-return test?

Great tool, btw! Adds the last missing piece to the ffmpeg / tsduck eco system.

x9k3 not create .m3u

Hello. I try to use x9k3 segmenter but have no success.

First problem - its not create .m3u manifest file.
OS enviroment - Win7. I try to use Pypy3 or Python3, with admin rights - no success. Any suggestion?
Also its possible to select target directory for m3u and ts segments?

Second - it crash after some time with the same error.
image

Thank you.

paypal account

hi my brother.
you have PayPal account? or BTC/ETH ?
I need to sent some Christmas gift

Replay mode , not looping the video

Hello

I'm testing x9k3 to obtain a live signal with multiple scte35 cues. I've installed using the instructions, and tried to run the replay mode with a ts file to generate a live content.

I run as follows and added a LOOP trace to validate:

python3 x9k3.py -i ../sample.ts -r -o ../out
phosy@DESKTOP-FHL6Q1U:~/DEVEL/x9k3/x9k3-main$ python3 x9k3.py -i ../sample.ts -r -o ../out
LOOP
../out/seg0.ts:   start: 1.480000   end: 4.520000   duration: 3.040000
../out/seg1.ts:   start: 4.520000   end: 7.560000   duration: 3.040000
../out/seg2.ts:   start: 7.560000   end: 10.600000   duration: 3.040000
../out/seg3.ts:   start: 10.600000   end: 13.640000   duration: 3.040000
../out/seg4.ts:   start: 13.640000   end: 16.680000   duration: 3.040000
deleting ../out/seg0.ts
...
...
../out/seg14.ts:   start: 44.040000   end: 47.080000   duration: 3.040000
deleting ../out/seg10.ts
../out/seg15.ts:   start: 47.080000   end: 50.120000   duration: 3.040000
deleting ../out/seg11.ts
../out/seg16.ts:   start: 50.120000   end: 53.160000   duration: 3.040000
deleting ../out/seg12.ts
LOOP
LOOP
LOOP
LOOP

The problem is that the segments end when the sample video ends and I don´t see that it starts again. I've observed in the code that the while true loop is working but it seems the threefive decode stops

The sample I used is the following: https://www.dwsamplefiles.com/?dl_id=396

Any ideas? Thank you

How to pipe multi bitarte livestream content generated from ffmpeg?

I am not sure if the below command is correct or not. My requirement is to insert SCTE35 marker to multi-bitrate livestream content generated from ffmpeg.

ffmpeg -i source.mp4 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -c:v libx264 -crf 22 -c:a aac -ar 48000 -filter:v:0 scale=w=480:h=360 -maxrate:v:0 600k -b:a:0 64k -filter:v:1 scale=w=640:h=480 -maxrate:v:1 900k -b:a:1 128k -filter:v:2 scale=w=1280:h=720 -maxrate:v:2 900k -b:a:2 128k -var_stream_map "v:0,a:0,name:360p v:1,a:1,name:480p v:2,a:2,name:720p" -preset slow -hls_list_size 0 -threads 0 -f hls -hls_playlist_type event -hls_time 3 -hls_flags independent_segments -master_pl_name "master.m3u8" "stream-%v.m3u8" -f mpegts - | x9k3 -s sidecar.txt -l

When I tried with this x9k3 always generating a index.m3u8 file with single bitrate. I want a master file and that should linked to resolution specific child manifest. Example,

master.m3u8
media-1
segment-1.ts
segment-2.ts
segment-n.ts
stream.m3u8
media-2
segment-1.ts
segment-2.ts
segment-n.ts
stream.m3u8
media-3
segment-1.ts
segment-2.ts
segment-n.ts
stream.m3u8

Appreciate your quick response.

Thank you

x9k3 not show CUE-OUT=YES/CUE-IN=YES messages.

Hello.
x9k3 not show CUE-OUT=YES/CUE-IN=YES messages, only binary decoded SCTE messages.
In version 1.21 we get string like that -
#EXT-X-SCTE35:CUE="/DAgAAAAAAAAAP/wDwUAAAAAf/9+AAAAAAAAAAAAAD4xJP8=",CUE-OUT=YES
In version 1.23 and latest string always show as
#EXT-X-SCTE35:CUE="/DAgAAAAAAAAAP/wDwUAAAAAf/9+AAAAAAAAAAAAAD4xJP8="
I think its related to discontinuity control in your script.

stdin input is not working

Hey @futzu I cant tell you how useful your tools are specially this one X9K3.
recently I tried to use standard input stream as input to x9k3 and It is not working,

here is my command :

TS file i downloaded from https://so.slo.me/longb.ts

cat longb.ts | x9k3 -l

output:

No Stream Found.

however with
x9k3 -i longb.ts --live
it is working fine.

I appreciate your response.
Thanks

replay stops after last segment created

When running x9k3 with "replay" x9k3 stops on last segment and does not anymore update index file, or write new segment .ts files.

If I fully understand --replay it should keep "faking" continous live stream with updated index.m3u8 and (?maybe) new created .ts files. Everything seems OK until last segment.


x9k3 started with:
x9k3 -i longb.ts --replay
No sidecar / scte35 injection or anything similar was used.

Used version:

x9k3 --version
0.1.57

After some time (approxy 150 seconds) last index.m3u8 was created:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:3
#EXT-X-MEDIA-SEQUENCE:27
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXTINF:5.338,
seg27.ts
#EXTINF:5.339,
seg28.ts
#EXTINF:5.339,
seg29.ts
#EXTINF:5.338,
seg30.ts
#EXTINF:5.339,
seg31.ts

This fill remained static after that - no further changes occured to index.m3u8.

This are last moments of x9k3 (I waited until index.m3u8 stopped changing, then after a few seconds I pressed CTRL-C)

deleting ./seg22.ts
./seg28.ts	start: 140.238000	duration: 5.339000	stream diff: 3.712951
deleting ./seg23.ts
./seg29.ts	start: 145.577000	duration: 5.339000	stream diff: 3.65278
deleting ./seg24.ts
./seg30.ts	start: 150.916000	duration: 5.338000	stream diff: 3.595596
deleting ./seg25.ts
./seg31.ts	start: 156.254000	duration: 5.339000	stream diff: 3.549967
deleting ./seg26.ts
^CTraceback (most recent call last):
  File "/home/uporabnik/.local/bin/x9k3", line 5, in <module>
    cli()
  File "/home/uporabnik/.local/lib/python3.8/site-packages/x9k3.py", line 811, in cli
    stuff.run()
  File "/home/uporabnik/.local/lib/python3.8/site-packages/x9k3.py", line 795, in run
    self.loop()
  File "/home/uporabnik/.local/lib/python3.8/site-packages/x9k3.py", line 778, in loop
    if not self._find_start():
  File "/home/uporabnik/.local/lib/python3.8/site-packages/threefive/stream.py", line 154, in _find_start
    one = self._tsdata.read(1)
KeyboardInterrupt


input stream file used was taken from slo.me....

wget https://so.slo.me/longb.ts
ls -l longb.ts
-rw-rw-r-- 1 uporabnik uporabnik 59287492 Oct  4  2021 longb.ts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.