https://github.com/superkabuki/threefive
threefive3 is the best SCTE-35 Parser, SCTE-35 Decoder and SCTE-35 Encoder Available. SCTE-35 Cli and SCTE-35 python3 library. threefive3 parses SCTE-35 from MPEGTS, HLS, XML,Base64,Bytes, Integers, Hex, JSON, etc.. Multicast support is built in.
https://github.com/superkabuki/threefive
adbreak adrianofdoom adtech hls-live-streaming hls-scte35 mpegts python3 scte scte-214 scte-35 scte-35-hls scte35 spliceinfosection threefive threefive3
Last synced: about 1 year ago
JSON representation
threefive3 is the best SCTE-35 Parser, SCTE-35 Decoder and SCTE-35 Encoder Available. SCTE-35 Cli and SCTE-35 python3 library. threefive3 parses SCTE-35 from MPEGTS, HLS, XML,Base64,Bytes, Integers, Hex, JSON, etc.. Multicast support is built in.
- Host: GitHub
- URL: https://github.com/superkabuki/threefive
- Owner: superkabuki
- License: gpl-2.0
- Created: 2025-03-14T08:55:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-10T22:09:40.000Z (about 1 year ago)
- Last Synced: 2025-05-11T20:22:43.961Z (about 1 year ago)
- Topics: adbreak, adrianofdoom, adtech, hls-live-streaming, hls-scte35, mpegts, python3, scte, scte-214, scte-35, scte-35-hls, scte35, spliceinfosection, threefive, threefive3
- Language: Python
- Homepage: https://iodisco.com/scte35
- Size: 692 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-broadcasting - threefive - SCTE-35 Parser and Encoder for MPEGTS. (SCTE-35)
README
[__Install__](#install) |[__SCTE-35 Cli__](#the-cli-tool) | [__SCTE-35 HLS__](https://github.com/superkabuki/threefive/blob/main/hls.md) | [__Cue__ Class](https://github.com/superkabuki/threefive/blob/main/cue.md) | [__Stream__ Class](https://github.com/superkabuki/threefive/blob/main/stream.md) | [__Online SCTE-35 Parser__](https://iodisco.com/scte35) | [__Encode SCTE-35__](https://github.com/superkabuki/threefive/blob/main/encode.md) | [__SCTE-35 Examples__](https://github.com/superkabuki/threefive/tree/main/examples)
| [__SCTE-35 XML__ ](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) and [More __XML__](node.md) | [__SuperKabuki SCTE-35 MPEGTS Packet Injection__](inject.md) | [__SCTE-35 As a Service__](sassy.md)
# `Heads up`
I called this repo threefive3 in an attempt to avoid confusion with my old threefive repo,
that didn't work at all.
Going forward, this will be threefive and will be released as such.
Adrian
### `Q.` What is SCTE-35?
### `A.` SCTE-35 is just encoded binary data. The SCTE-35 data is used to signal when to splice in commercials and such. The decoded variables in SCTE-35 are used determine the type and length of commercials. As with most things related to streaming video, it's way too complicated. Don't worry though, threefive makes it much easier.
# threefive is the most advanced SCTE-35 tool available*
\* _No asterisks, no exceptions._
* __Decode SCTE-35__ in __TEN__ formats: __MPEGTS, Base64, Bytes, Dicts, Hex,HLS, Integers,JSON,XML and XML+Binary__.
* __Encode SCTE-35__ in __EIGHT__ formats: __MPEGTS, Base64, Bytes, Hex, Int, JSON,XML, and Xml+binary.__
* __All HLS SCTE-35 Tags__ are Supported.
* __Automatic AES decryption__ for HLS.
* Built-in __Multicast Sender and Receiver__
* [The __SuperKabuki SCTE-35 MPEGTS Packet Injection Engine__](inject.md) was added to __threefive__ v3.0.39
### [Sassy, the new SCTE-35 as a service, Decode SCTE-35 in your browser](sassy.md)
* returns decoded SCTE-35 as JSON
* https://iodisco.com/cb/sassy?scte35=0xfc302f00019164e7980000000506fe849f2fa80019021743554549ffffffff7fbf010866756d6174696361100100ae05fd2e
* open that URL in a browser
* curl works too.
* If you can make an https request, you can decode SCTE-35 with sassy, no installation required.
* powered by nstuff
### MPEGTS streams can be parsed for SCTE-35 with three lines of code.
```py3
a@fu:~/build5/scte35/scte35$ pypy3
>>>> from threefive import Stream
>>>> strm=Stream('https://futzu.com/xaa.ts')
>>>> strm.decode()
```
### Checkout the Super Cool SCTE-35 [__Examples__](https://github.com/superkabuki/threefive/tree/main/examples)
----
### [Super Cool new xml stuff in threefive v3.0.45](node.md)
### The new xml stuff is really sweet, you can even pass an DASH MPD directly to a Cue instance, and it will parse the first Event with SCTE-35 it finds. Let me show you.
```py3
a@fu:~/threefive$ pypy3
Python 3.9.16 (7.3.11+dfsg-2+deb12u3, Dec 30 2024, 22:36:23)
[PyPy 7.3.11 with GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>>
>>>> from threefive import Cue,reader
>>>> data = reader('https://demo.unified-streaming.com/k8s/live/stable/scte35-n\
o-splicing.isml/.mpd').read() # use reader to pull the mpd over a network.
>>>> cue=Cue(data) # pass in to a Cue instance
>>>> cue.show()
{
"info_section": {
"table_id": "0xfc",
"section_syntax_indicator": false,
"private": false,
"sap_type": "0x03",
"sap_details": "No Sap Type",
"section_length": 32,
"protocol_version": 0,
"encrypted_packet": false,
"encryption_algorithm": 0,
"pts_adjustment": 0.0,
"cw_index": "0x00",
"tier": "0x0fff",
"splice_command_length": 15,
"splice_command_type": 5,
"descriptor_loop_length": 0,
"crc": "0xe4612424"
},
"command": {
"command_length": 15,
"command_type": 5,
"name": "Splice Insert",
"break_auto_return": true,
"break_duration": 38.4,
"splice_event_id": 14432855,
"splice_event_cancel_indicator": false,
"out_of_network_indicator": true,
"program_splice_flag": true,
"duration_flag": true,
"splice_immediate_flag": true,
"event_id_compliance_flag": true,
"unique_program_id": 49152,
"avail_num": 0,
"avails_expected": 0
},
"descriptors": []
}
```
# Latest release is v3.0.49
* cyclomatic complexity __2.01__ ,__That's a kickass score.__
* pylint score is __9.62/10__, _this needs a liitle work_.
> Stay up to date, only the latest release is supported.
>
* Xml is back and better than ever. __The new Ultra Xml Parser Supreme__ replaces the Super Xml Parser.
#### [__threefive runs Four Times Faster on pypy3__](https://pypy.org/) |
# `Documentation`
### `Install`
* [Install](#install)
### `Examples`
* [__Examples__](https://github.com/superkabuki/threefive/tree/main/examples)
### `XML`
* [XML](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) __New__! _updated 05/01/2025_
### `Cli`
* [SCTE-35 Cli Super Tool](#the-cli-tool) Encodes, Decodes, and Recodes. This is pretty cool, it does SCTE-35 seven different ways.
* The cli tool comes with builtin documentation just type `threefive help`
### `HLS`
* [Advanced Parsing of SCTE-35 in HLS with threefive](https://github.com/superkabuki/threefive/blob/main/hls.md) All HLS SCTE-35 tags, Sidecar Files, AAC ID3 Header Timestamps, SCTE-35 filters... Who loves you baby?
### `MPEGTS Packet Injection`
* [The SuperKabuki MPEGTS Packet Injection Engine in the Cli](inject.md)
### `SCTE-35 As a Service`
* Decode SCTE-35 without installing anything. [__Sassy__](sassy.md) is SCTE-35 as a service.
### `Classes`
* The python built in help is always the most up to date docs for the library.
```py3
a@fu:~/build7/threefive$ pypy3
>>>> from threefive import Stream
>>>> help(Stream)
```
* [Class Structure](https://github.com/superkabuki/threefive/blob/main/classes.md)
* [Cue Class](https://github.com/superkabuki/threefive/blob/main/cue.md) Cue is the main SCTE-35 class to use.
* [Stream Class](https://github.com/superkabuki/threefive/blob/main/stream.md) The Stream class handles MPEGTS SCTE-35 streams local, Http(s), UDP, and Multicast.
___
### `| more`
* [Online SCTE-35 Parser](https://iodisco.com/scte35) Supporte Base64, Bytes,Hex,Int, Json, Xml, and Xml+binary.
* [Encode SCTE-35](https://github.com/superkabuki/threefive/blob/main/encode.md) Some encoding code examples.
___
### `Install`
* python3 via pip
```rebol
python3 -mpip install threefive
```
* pypy3
```rebol
pypy3 -mpip install threefive
```
* from the git repo
```rebol
git clone https://github.com/superkabuki/scte35.git
cd threefive
make install
```
___
### `Using the library`
* Let me show you how easy threefive is to use.
* well start off reading SCTE-35 xml from a file
```py3
a@fu:~/threefive$ pypy3
Python 3.9.16 (7.3.11+dfsg-2+deb12u3, Dec 30 2024, 22:36:23)
[PyPy 7.3.11 with GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>> from threefive import reader
>>>> from threefive import Cue
>>>> data =reader('/home/a/xml.xml').read()
* load it into a threefive.Cue instance
```py3
>>>> cue = Cue(data)
```
* Show the data as JSON
```py3
>>>> cue.show()
{
"info_section": {
"table_id": "0xfc",
"section_syntax_indicator": false,
"private": false,
"sap_type": "0x03",
"sap_details": "No Sap Type",
"section_length": 92,
"protocol_version": 0,
"encrypted_packet": false,
"encryption_algorithm": 0,
"pts_adjustment": 0.0,
"cw_index": "0x00",
"tier": "0x0fff",
"splice_command_length": 15,
"splice_command_type": 5,
"descriptor_loop_length": 60,
"crc": "0x7632935"
},
"command": {
"command_length": 15,
"command_type": 5,
"name": "Splice Insert",
"break_auto_return": false,
"break_duration": 180.0,
"splice_event_id": 1073743095,
"splice_event_cancel_indicator": false,
"out_of_network_indicator": true,
"program_splice_flag": false,
"duration_flag": true,
"splice_immediate_flag": false,
"event_id_compliance_flag": true,
"unique_program_id": 1,
"avail_num": 12,
"avails_expected": 5
},
"descriptors": [
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 12,
"descriptor_length": 8
},
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 13,
"descriptor_length": 8
},
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 14,
"descriptor_length": 8
},
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 15,
"descriptor_length": 8
},
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 16,
"descriptor_length": 8
},
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 17,
"descriptor_length": 8
}
]
}
```
* convert the data back to xml
```py3
>>>> print(cue.xml())
```
* convert to xml+binary
```py3
>>>> print(cue.xmlbin())
/DBcAAAAAAAAAP/wDwVAAAT3f69+APcxQAABDAUAPAAIQ1VFSQAAAAwACENVRUkAAAANAAhDVUVJAAAADgAIQ1VFSQAAAA8ACENVRUkAAAAQAAhDVUVJAAAAEQdjKTU=
```
* convert to base64
```py3
>>>> print(cue.base64())
/DBcAAAAAAAAAP/wDwVAAAT3f69+APcxQAABDAUAPAAIQ1VFSQAAAAwACENVRUkAAAANAAhDVUVJAAAADgAIQ1VFSQAAAA8ACENVRUkAAAAQAAhDVUVJAAAAEQdjKTU=
```
* convert to hex
```py3
>>>> print(cue.hex())
0xfc305c00000000000000fff00f05400004f77faf7e00f7314000010c05003c0008435545490000000c0008435545490000000d0008435545490000000e0008435545490000000f000843554549000000100008435545490000001107632935
```
* show just the splice command
```py3
>>>> cue.command.show()
{
"command_length": 15,
"command_type": 5,
"name": "Splice Insert",
"break_auto_return": false,
"break_duration": 180.0,
"splice_event_id": 1073743095,
"splice_event_cancel_indicator": false,
"out_of_network_indicator": true,
"program_splice_flag": false,
"duration_flag": true,
"splice_immediate_flag": false,
"event_id_compliance_flag": true,
"unique_program_id": 1,
"avail_num": 12,
"avails_expected": 5
}
```
* edit the break duration
```py3
>>>> cue.command.break_duration=30
>>>> cue.command.show()
{
"command_length": 15,
"command_type": 5,
"name": "Splice Insert",
"break_auto_return": false,
"break_duration": 30,
"splice_event_id": 1073743095,
"splice_event_cancel_indicator": false,
"out_of_network_indicator": true,
"program_splice_flag": false,
"duration_flag": true,
"splice_immediate_flag": false,
"event_id_compliance_flag": true,
"unique_program_id": 1,
"avail_num": 12,
"avails_expected": 5
}
```
* re-encode to base64 with the new duration
```py3
>>>> cue.base64()
'/DBcAAAAAAAAAP/wDwVAAAT3f69+ACky4AABDAUAPAAIQ1VFSQAAAAwACENVRUkAAAANAAhDVUVJAAAADgAIQ1VFSQAAAA8ACENVRUkAAAAQAAhDVUVJAAAAEe1FB6g='
```
* re-encode to xml with the new duration
```py3
>>>> print(cue.xml())
```
* show just the descriptors
```py3
>>>> _ = [d.show() for d in cue.descriptors]
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 12,
"descriptor_length": 8
}
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 13,
"descriptor_length": 8
}
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 14,
"descriptor_length": 8
}
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 15,
"descriptor_length": 8
}
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 16,
"descriptor_length": 8
}
{
"tag": 0,
"identifier": "CUEI",
"name": "Avail Descriptor",
"provider_avail_id": 17,
"descriptor_length": 8
}
```
* pop off the last descriptor and re-encode to xml
```py3
>>>> cue.descriptors.pop()
{'tag': 0, 'identifier': 'CUEI', 'name': 'Avail Descriptor', 'private_data': None, 'provider_avail_id': 17, 'descriptor_length': 8}
>>>> print(cue.xml())
```
### `The Cli tool`
#### The cli tool installs automatically with pip or the Makefile.
* [__SCTE-35 Inputs__](#inputs)
* [__SCTE-35 Outputs__](#outputs)
* [Parse __MPEGTS__ streams for __SCTE-35__](#streams)
* [Parse __SCTE-35__ in __hls__](#hls)
* [Display __MPEGTS__ __iframes__](#iframes)
* [Display raw __SCTE-35 packets__ from __video streams__](#packets)
* [__Repair SCTE-35 streams__ changed to __bin data__ by __ffmpeg__](#sixfix)
#### `Inputs`
* Most __inputs__ are __auto-detected.__
* __stdin__ is __auto selected__ and __auto detected.__
* __SCTE-35 data is printed to stderr__
* __stdout is used when piping video__
* mpegts can be specified by file name or URI.
```rebol
threefive udp://@235.2.5.35:3535
```
* If a file comtains a SCTE-35 cue as a string( base64,hex,int,json,or xml+bin), redirect the file contents.
```rebol
threefive < json.json
```
* quoted strings(( base64,hex,int,json or xml+bin), can be passed directly on the command line as well.
```awk
threefive '/DAWAAAAAAAAAP/wBQb+ztd7owAAdIbbmw=='
```
| Input Type | Cli Example |
|------------|-------------------------------------------------------------------------------------------------------------|
| __Base64__ | `threefive '/DAsAAAAAyiYAP/wCgUAAAABf1+ZmQEBABECD0NVRUkAAAAAf4ABADUAAC2XQZU='`
| __Hex__ |`threefive 0xfc301600000000000000fff00506fed605225b0000b0b65f3b`|
| __HLS__ |`threefive hls https://example.com/master.m3u8` |
| __JSON__ |`threefive < json.json` |
| __Xmlbin__ | `js threefive < xmlbin.xml` |
# `Streams`
|Protocol | Cli Example |
|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| File | `threefive video.ts` |
| Http(s) | `threefive https://example.com/video.ts` |
| Stdin | `threefive < video.ts` |
| UDP Multicast| `threefive udp://@235.35.3.5:9999` |
| UDP Unicast | `threefive udp://10.0.0.7:5555` |
| HLS | `threefive hls https://example.com/master.m3u8`|
| | |
#### Outputs
* output type is determined by the key words __base64, bytes, hex, int, json, and xmlbin__.
* __json is the default__.
* __Any input (except HLS,) can be returned as any output__
* examples __Base64 to Hex__ etc...)
| Output Type | Cli Example |
|-------------|----------------------------------------------------------|
|__Base 64__ | `threefive 0xfc301600000000000000fff00506fed605225b0000b0b65f3b base64 ` |
| __Bytes__ | `threefive 0xfc301600000000000000fff00506fed605225b0000b0b65f3b bytes` |
| __Hex__ | `threefive '/DAsAAAAAyiYAP/wCgUAAAABf1+ZmQEBABECD0NVRUkAAAAAf4ABADUAAC2XQZU=' hex` |
| __Integer__ | `threefive '/DAsAAAAAyiYAP/wCgUAAAABf1+ZmQEBABECD0NVRUkAAAAAf4ABADUAAC2XQZU=' int` |
| __JSON__ | `threefive 0xfc301600000000000000fff00506fed605225b0000b0b65f3b json ` |
| __Xml+bin__ | `threefive 0xfc301600000000000000fff00506fed605225b0000b0b65f3b xmlbin ` |`
#### `hls`
* parse hls manifests and segments for SCTE-35
```smalltalk
threefive hls https://example.com/master.m3u8
```
___
#### `Iframes`
* Show iframes PTS in an MPEGTS video
```smalltalk
threefive iframes https://example.com/video.ts
```
___
#### `packets`
* Print raw SCTE-35 packets from multicast mpegts video
```smalltalk
threefive packets udp://@235.35.3.5:3535
```
___
#### `proxy`
* Parse a https stream and write raw video to stdout
```smalltalk
threefive proxy video.ts
```
___
#### `pts`
* Print PTS from mpegts video
```smalltalk
threefive pts video.ts
```
___
#### `sidecar`
* Parse a stream, write pts,write SCTE-35 Cues to sidecar.txt
```smalltalk
threefive sidecar video.ts
```
___
#### `sixfix`
* Fix SCTE-35 data mangled by ffmpeg
```smalltalk
threefive sixfix video.ts
```
___
#### `show`
* Probe mpegts video _( kind of like ffprobe )_
```smalltalk
threefive show video.ts
```
___
#### `version`
* Show version
```smalltalk
threefive version
```
___
#### `help`
* Help
```rebol
threefive help
```
___
### Stream Multicast with the threefive cli, it's easy.
* The threefive cli has long been a Multicast Receiver( client )
* The cli now comes with a builtin Multicast Sender( server).
* It's optimized for MPEGTS (1316 byte Datagrams) but you can send any video or file.
* The defaults will work in most situations, you don't even have to set the address.
* threefive cli also supports UDP Unicast Streaming.

```js
a@fu:~$ threefive mcast help
usage: threefive mcast [-h] [-i INPUT] [-a ADDR] [-b BIND_ADDR] [-t TTL]
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
like "/home/a/vid.ts" or "udp://@235.35.3.5:3535" or
"https://futzu.com/xaa.ts"
[default:sys.stdin.buffer]
-a ADDR, --addr ADDR Destination IP:Port [default:235.35.3.5:3535]
-b BIND_ADDR, --bind_addr BIND_ADDR
Local IP to bind [default:0.0.0.0]
-t TTL, --ttl TTL Multicast TTL (1 - 255) [default:32]
a@fu:~$
```
### [iodisco.com/scte35](https://iodisco.com/scte35)
___
[__Install__](#install) |[__SCTE-35 Cli__](#the-cli-tool) | [__SCTE-35 HLS__](https://github.com/superkabuki/threefive/blob/main/hls.md) | [__Cue__ Class](https://github.com/superkabuki/threefive/blob/main/cue.md) | [__Stream__ Class](https://github.com/superkabuki/threefive/blob/main/stream.md) | [__Online SCTE-35 Parser__](https://iodisco.com/scte35) | [__Encode SCTE-35__](https://github.com/superkabuki/threefive/blob/main/encode.md) | [__SCTE-35 Examples__](https://github.com/superkabuki/threefive/tree/main/examples)
| [__SCTE-35 XML__ ](https://github.com/superkabuki/SCTE-35/blob/main/xml.md) and [More __XML__](node.md) | [__threefive runs Four Times Faster on pypy3__](https://pypy.org/) | [__SuperKabuki SCTE-35 MPEGTS Packet Injection__](inject.md)