HLS Segmenter with SCTE-35 Support
Project description
Details | Install | Use | Customize | Live Events | Bugs | Feedback | Cue
x9k3
HLS Segmenter with SCTE-35 baked in.
scte-35 by threefive.
- SCTE-35 Cues in Mpegts Streams are Translated into HLS tags.
- Segments are Split on SCTE-35 Cues as needed.
- M3U8 Manifests are created with SCTE-35 HLS tags.
- Supports h264 and h265 and mpeg2 video.
- Multi-protocol. Files, Http(s), Multicast, and Udp.
- Supports Live Streaming.
- Customizable Ad Break Criteria
This is not yet stable. Expect changes.
Be Cool.
-
I'm cool, you be cool too.
-
If you have a question, ask it.
-
If you have something to say, say it.
-
If you have a patch or idea or suggestion, Open an issue, and tell me about it.
Requires
- python 3.6+ or pypy3
- threefive
pip3 install threefive
How to Use
$ pypy3 x9k3.py -h
usage: x9k3.py [-h] [-i INPUT] [-l]
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
Input source, like "/home/a/vid.ts" or "udp://@235.35.3.5:3535" or "https://futzu.com/xaa.ts"
-l, --live Flag for a live event.(enables sliding window m3u8)
- Example Usage
python3 x9k3.py -i video.mpegts
python3 x9k3.py --live -i udp://@235.35.3.5:3535
cat video.ts | python3 x9k3.py
Details
-
Segments are cut on iframes.
-
Segment size is 2 seconds or more, determined by GOP size.
-
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 are added when received.
-
All SCTE35 cue commands are added.
# Time Signal
#EXT-X-SCTE35:CUE="/DC+AAAAAAAAAP/wBQb+W+M4YgCoAiBDVUVJCW3YD3+fARFEcmF3aW5nRlJJMTE1V0FCQzUBAQIZQ1VFSQlONI9/nwEKVEtSUjE2MDY3QREBAQIxQ1VFSQlw1HB/nwEiUENSMV8xMjEwMjExNDU2V0FCQ0dFTkVSQUxIT1NQSVRBTBABAQI2Q1VFSQlw1HF/3wAAFJlwASJQQ1IxXzEyMTAyMTE0NTZXQUJDR0VORVJBTEhPU1BJVEFMIAEBhgjtJQ=="
#EXTINF:2.085422,
seg1.ts
- SCTE-35 cues with a preroll are inserted again at the splice point.
# Splice Point @ 17129.086244
#EXT-X-SCTE35:CUE="/DC+AAAAAAAAAP/wBQb+W+M4YgCoAiBDVUVJCW3YD3+fARFEcmF3aW5nRlJJMTE1V0FCQzUBAQIZQ1VFSQlONI9/nwEKVEtSUjE2MDY3QREBAQIxQ1VFSQlw1HB/nwEiUENSMV8xMjEwMjExNDU2V0FCQ0dFTkVSQUxIT1NQSVRBTBABAQI2Q1VFSQlw1HF/3wAAFJlwASJQQ1IxXzEyMTAyMTE0NTZXQUJDR0VORVJBTEhPU1BJVEFMIAEBhgjtJQ=="
#EXTINF:0.867544,
seg2.ts
- CUE-OUT ans CUE-IN are added at the splice point.
#EXT-X-SCTE35:CUE="/DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==" CUE-OUT=YES
#EXTINF:1.668334,
seg13.ts
VOD
- x9k3 defaults to VOD style playlist generation.
- All segment are listed in the m3u8 file.
Live
-
Activated by the --live switch or by setting X9K3.live=True
-
Like VOD except:
- M3u8 manifests are regenerated every time a segment is written.
- Sliding Window for 10 MEDIA_SLOTS
- A cue out continue tag is added to first segment in manifest during an ad break.
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:3
#EXT-X-SCTE35:CUE="/DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==",CUE-OUT=CONT
#EXTINF:2.002,
seg43.ts
#EXTINF:2.002,
seg44.ts
#EXTINF:2.002,
seg45.ts
# Splice Insert
#EXT-X-SCTE35:CUE="/DAsAAAAAAAAAP/wDwUAAABef0/+zPACTQAAAAAADAEKQ1VFSbGfMTIxIxGolm0="
#EXTINF:2.168834,
seg46.ts
# Splice Point @ 38203.125478
#EXT-X-SCTE35:CUE="/DAsAAAAAAAAAP/wDwUAAABef0/+zPACTQAAAAAADAEKQ1VFSbGfMTIxIxGolm0=",CUE-IN=YES
#EXTINF:1.001,
seg47.ts
#EXTINF:2.836166,
seg48.ts
#EXTINF:2.002,
seg49.ts
#EXTINF:2.002,
....
FAQ
Q.
How do I Customize CUE-OUT and CUE-IN ad break events?
A.
Override the X9K3.is_cue_out
and X9K3.is_cue_in
static methods.
The X9K3 class has three static methods you can override and customize.
@staticmethod | arg | return value | details |
---|---|---|---|
mk_cue_tag | cue | text | called to generate scte35 hls tags |
is_cue_out | cue | bool | returns True if the cue is a CUE-OUT |
is_cue_in | cue | bool | returns True if the cue is a CUE-IN |
Example
- Override the static method X9K3.is_cue_out(cue)
- Require
- a Splice Command of type
6
, Time Signal - a Splice Descriptor tag of type
2
, Segmentation Descriptor - a Segmentation Type Id of
0x22
, "Break Start"
- a Splice Command of type
def my_cue_out(cue):
"""
my_cue_out returns True
if the splice command is a time signal
"""
if cue.command.command_type == 6: # time signal
for d in cue.descriptors: # cue.descriptors is always list
if d.tag ==2: # Segmentation Descriptor tag
if d.segmentation_type_id == 0x22: # Break Start
return True
return False
- Create an X9K3 instance
from x9k3 import X9K3
x9 = X9K3("vid.ts")
- set is_cue_out to your custom function
x9.is_cue_out = my_cue_out
x9.decode()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file x9k3-0.1.13.tar.gz
.
File metadata
- Download URL: x9k3-0.1.13.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
db4e5a854fc8f86e76858a17fc8ee64080841864e1e13b9de71b5c4f10c297c6
|
|
MD5 |
912fab87040c60f7a046255253a1f854
|
|
BLAKE2b-256 |
15c251ac8f7913beadcd8555749a8f0f6dfa4ee4f49cc2070b33dfb9248ccc17
|
File details
Details for the file x9k3-0.1.13-py3-none-any.whl
.
File metadata
- Download URL: x9k3-0.1.13-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
aa3b9c5a055b1168fb949ac4dec7dcb019eec7358168becb90ebac0a2d596751
|
|
MD5 |
fd3f4efd3c253fb72a5c733c2d793934
|
|
BLAKE2b-256 |
6509c9bdbbbea716bf88c0ea3efd09feb4a8a82f27c07cb6f79c5113b6c64195
|