threefive Might be The Leading SCTE-35 Parsing Lib for Mpeg-TS Video Streams, and Base64 or Hex Encoded Messages. threefive is Used in Production by Some of The Largest Broadcast Networks in The World, Maybe
Project description
:rocket: threefive
threefive is a SCTE35 Parser library in Python3.
-
2019a SCTE-35 in about 900 lines of code.
-
threefive is simple and easy to use.
-
SCTE-35 can be parsed from strings or video with one function threefive.decode().
-
threefive automatically identifies and parses Base64, Hexidecimal, or Binary .
-
Multiple programs and multiple SCTE-35 streams are well supported.
-
SCTE35 cues up to 4096 bytes long can be parsed from video streams or encoded strings.
Why so many releases?
- I generate a lot of releases, however the interface to classes and functions rarely changes
- Releases are made for incremental improvements. This keeps pip and the git repo in sync.
- Having several relases makes it much easier to resolve issues
Heads Up! Changes as of 1/1/2021
-
- HLS
- Multicast
- Splice Insert
- Splice_Null
- Time Signal
- UPID
- DTMF
- Stream
Changes
-
Back by popular demand... Stream.decode_next()
-
As of threefive v.2.2.39 threefive.Cue will require Cue.decode() to be called to parse data.
from threefive import Cue
Base64 = "/DAvAAAAAAAA///wBQb+dGKQoAAZAhdDVUVJSAAAjn+fCAgAAAAALKChijUCAKnMZ1g="
cue = Cue(Base64)
cue.decode() # Now required
cue.show()
- As of version 2.1.95, threefive.version returns a string for the current version.
>>> import threefive
>>> threefive.version()
'2.2.35'
Fast _Start
Dependencies
- Python 3.6+ or pypy3
- bitn
Install
- git
git clone https://github.com/futzu/SCTE35-threefive.git
cd SCTE-threefive
# you need root to install for the system
make install
# for pypy3
make pypy3
- pip
pip3 install threefive
# for pypy3
pypy3 -mpip install threefive
#If you don't have pip installed, try this.
pypy3 -mensurepip install pip
Easy threefive
The decode Function
- source decode.py
- threefive.decode is an all purpose function to decode SCTE 35 messages from a file or string.
- MpegTS
threefive.decode('/path/to/mpegwithscte35.ts')
- Base64
mesg='/DBUAAAAAAAA///wBQb+AAAAAAA+AjxDVUVJAAAACn+/Dy11cm46dXVpZDphYTg1YmJiNi01YzQzLTRiNmEtYmViYi1lZTNiMTNlYjc5OTkRAAB2c6LA'
threefive.decode(mesg)
- Hex
hexed='0xFC302F000000000000FFFFF014054800008F7FEFFE7369C02EFE0052CCF500000000000A0008435545490000013562DBA30A'
threefive.decode(hexed)
- Directly from a file encoded in Base64, Binary or Base64
cat cue.dat
/DCSAAAAAAAAAP/wBQb/RgeVUgB8AhdDVUVJbs6+VX+/CAgAAAAABy0IxzELGQIXQ1VFSW7MmIh/vwgIAAABGDayFhE3AQECHENVRUluzw0If/8AABvLoAgIAAAAAActVhIwDBkCKkNVRUluzw02f78MG1JUTE4xSAEAAAAAMTM3NjkyMDI1NDQ5NUgxAAEAAGnbuXg=
- pass threefive.decode the file name and it will parse it for SCTE35.
from threefive import decode
decode('cue.dat')
{
"info_section": {
"table_id": "0xfc",
"section_syntax_indicator": false,
"private": false,
"reserved": "0x3",
<--Snipped for Brevity -->
{
"tag": 2,
"identifier": "CUEI",
"name": "Segmentation Descriptor",
"segmentation_event_id": "0x6ecf0d36",
"segmentation_event_cancel_indicator": false,
"components": [],
"program_segmentation_flag": true,
"segmentation_duration_flag": false,
"delivery_not_restricted_flag": true,
"segmentation_message": "Content Identification",
"segmentation_upid_type": 12,
"segmentation_upid_length": 27,
"segmentation_upid": "MPU:{'format identifier': 1381256270, 'private data': 4720207453582705227611785054965731163782383190579622144}",
"segmentation_type_id": 1,
"segment_num": 0,
"segments_expected": 0,
"descriptor_length": 42
}
]
}
Advanced threefive
Cue Class
- source cue.py
- The threefive.Cue class decodes a SCTE35 binary, base64, or hex encoded string.
- threefive.Cue provides several methods to access the parsed data.
from threefive import Cue
b64 = "/DBIAAAAAAAA///wBQb+ek2ItgAyAhdDVUVJSAAAGH+fCAgAAAAALMvDRBEAAAIXQ1VFSUgAABl/nwgIAAAAACyk26AQAACZcuND"
cue = Cue(B64)
cue.decode()
Return Cue instance as dict
cue.get()
# Splice Info Section
cue.get_info_section()
# Splice Command
cue.get_command()
# Splice Descriptors
cue.get_descriptors()
Return Cue instance as JSON
jason = cue.get_json()
Print Cue instance as JSON
cue.show()
Stream Class
threefive.Stream(tsdata, show_null = False)
-
source stream.py
-
The threefive.Stream class parses SCTE35 messages from a file or stream.
-
tsdata is an open file handle.
-
show_null if set to True, enables showing SCTE 35 null commands.
-
| Method | Description |
|---|---|
| Stream.show() | Prints all recognized Programs and streams by pid and type. |
| Stream.decode(func=show_cue) | Prints SCTE-35 cues for SCTE-35 packets. Accepts an optional function, func, as arg. |
| Stream.decode_next() | Returns the next SCTE35 cue as a threefive.Cue instance. |
| Stream.decode_program(the_program=None, func=show_cue) | Same as Stream.decode except only packets where program == the_program |
| Stream.decode_proxy(func=show_cue) | Same as Stream.decode except raw packets are written to stdout for piping to another program. |
Stream.show()
- List programs and streams for a video.
# pypy3
>>>> from threefive import Stream, version
>>>> version
'2.2.09'
>>>> with open('video.ts','rb') as tsdata:
.... st = Stream(tsdata)
.... st.show()
....
Program: 1030 (pcr pid: 1031)
1031: [0x1b] Video
1032: [0x3] ISO/IEC 11172 Audio
1034: [0x6] ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets with private data
1035: [0x86] SCTE 35
Program: 1100 (pcr pid: 1101)
1101: [0x1b] Video
1102: [0x3] ISO/IEC 11172 Audio
1104: [0x6] ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets with private data
1105: [0x86] SCTE 35
Program: 1080 (pcr pid: 1081)
1081: [0x1b] Video
1082: [0x3] ISO/IEC 11172 Audio
1084: [0x6] ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets with private data
Stream.decode(func=show_cue)
import sys
from threefive import Stream
'''
if __name__ =='__main__':
with open(sys.argv[1],'rb') as tsdata:
sp = Stream.decode_nextStream(tsdata)
sp.decode()
-
Pass in custom function
-
func should match the interface
func(cue)
import sys
import threefive
def display(cue):
print(f'\033[92m{cue.packet_data}\033[00m')
print(f'{cue.command.name}')
def do():
with open(sys.argv[1],'rb') as tsdata:
sp = threefive.Stream(tsdata)
sp.decode(func = display)
if __name__ == '__main__':
do()
Stream.decode_next()
- Stream.decode_next returns the next SCTE35 cue as a threefive.Cue instance.
import sys
import threefive
def do():
arg = sys.argv[1]
with open(arg,'rb') as tsdata:
st = threefive.Stream(tsdata)
while True:
cue = st.decode_next()
if not cue:
return False
if cue:
cue.show()
if __name__ == "__main__":
do()
Stream.decode_program(the_program, func = show_cue)
- Use Stream.decode_program() instead of Stream.decode() to decode SCTE-35 from packets where program == the_program
import threefive
with open('../35.ts','rb') as tsdata:
threefive.Stream(tsdata).decode_program(1)
Stream.decode_proxy(func = show_cue)
-
Writes all packets to sys.stdout.
-
Writes scte35 data to sys.stderr.
import threefive
with open('vid.ts','rb') as tsdata:
sp = threefive.Stream(tsdata)
sp.proxy_decode()
- Pipe to mplayer
python3 proxy.py | mplayer -
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file threefive-2.2.51.tar.gz.
File metadata
- Download URL: threefive-2.2.51.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.8.0 tqdm/4.51.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40dfe3e64eae9dca57c46cc844907d66582250bbf8fed98886d7283d371fbb86
|
|
| MD5 |
4ac122977469fe644fe97ef7a812c71d
|
|
| BLAKE2b-256 |
e2782d7a9488f2cb58df0628a1a9b93ab92e010576da8e0c8c548e4ff9715ed3
|
File details
Details for the file threefive-2.2.51-py3-none-any.whl.
File metadata
- Download URL: threefive-2.2.51-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.8.0 tqdm/4.51.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28955c6fb1fc63e542577125a3ea92457ea1ab66192a6ad4c583323ce2655a71
|
|
| MD5 |
762916ce88bb0070c2528b4581f2b610
|
|
| BLAKE2b-256 |
568daa496da164ceb13fef409c97f0f49e23b199493c69688429ac262ed6ae2c
|