A Fast SCTE 35 Decoder for Mpeg-TS Video, and Base64 or Hex Encoded Messages.
Project description
threefive
SCTE35 Decoder
-
- Using threefive with HLS Manifests
- Splice Insert
- Splice Insert Too
- Splice Null
- Time Signal Blackout Override Program End
- Time Signal Placement Opportunity Start
- Time Signal Placement Opportunity End
- Time Signal Program Overlap
- Time Signal Program Start End
- Parsing SCTE-35 from a Multicast Source
- StreamProxy Example
- Upids with Custom Output
-
Splice Commands
- source command.py
- Splice Null
- Splice Schedule
- Splice Insert
- Time Signal
- Bandwidth Reservation
Splice Descriptors
- source descriptor.py
- DTMF Descriptor
- Segmentation Descriptor (all segmentation Upids)
- Segmentation Types and Messages
- Time Descriptor
- Audio Descriptor
Fast Start Directions
Dependencies
- Python 3
- 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
...
Processing threefive-2.1.39-py3.8.egg
Copying threefive-2.1.39-py3.8.egg to /usr/local/lib/python3.8/dist-packages
Adding threefive 2.1.39 to easy-install.pth file
Installed /usr/local/lib/python3.8/dist-packages/threefive-2.1.39-py3.8.egg
Processing dependencies for threefive==2.1.39
Searching for bitn==0.0.27
Best match: bitn 0.0.27
Processing bitn-0.0.27-py3.8.egg
bitn 0.0.27 is already the active version in easy-install.pth
Using /usr/local/lib/python3.8/dist-packages/bitn-0.0.27-py3.8.egg
Finished processing dependencies for threefive==2.1.39
pip3
pip3 install threefive
Collecting threefive
Downloading threefive-2.0.99-py3-none-any.whl (12 kB)
Collecting bitn>=0.0.27
Downloading bitn-0.0.27-py3-none-any.whl (3.0 kB)
Installing collected packages: bitn, threefive
Successfully installed bitn-0.0.27 threefive-2.0.99
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.
import threefive
MpegTS
threefive.decode('/path/to/mpegwithscte35.ts')
Binary
threefive.decode('/mnt/build/file.bin')
Base64 Encoded Strings
mesg='/DBUAAAAAAAA///wBQb+AAAAAAA+AjxDVUVJAAAACn+/Dy11cm46dXVpZDphYTg1YmJiNi01YzQzLTRiNmEtYmViYi1lZTNiMTNlYjc5OTkRAAB2c6LA'
threefive.decode(mesg)
Hex Encoded Strings
hexed='0xFC302F000000000000FFFFF014054800008F7FEFFE7369C02EFE0052CCF500000000000A0008435545490000013562DBA30A'
threefive.decode(hexed)
Advanced threefive
Splice Class
-
source splice.py
-
The threefive.Splice class decodes a SCTE35 binary, base64, or hex encoded string.
-
threefive.Splice provides several methods to access the parsed data.
from threefive import Splice
b64 = "/DBIAAAAAAAA///wBQb+ek2ItgAyAhdDVUVJSAAAGH+fCAgAAAAALMvDRBEAAAIXQ1VFSUgAABl/nwgIAAAAACyk26AQAACZcuND"
scte35 = Splice(b64)
JSON Pretty Print SCTE 35 Message
scte35.show()
Return SCTE 35 Message
scte35.get()
JSON Pretty Print Splice Info Section
scte35.show_info_section()
Return Splice Info Section
scte35.get_info_section()
JSON Pretty Print Splice Command
scte35.show_command()
Return Splice Command
scte35.get_command()
JSON Pretty Print Splice Descriptors
scte35.show_descriptors()
Return Splice Descriptors
scte35.get_descriptors()
Stream Class
-
source stream.py
-
The threefive.Stream class parses SCTE35 messages from a file or stream.
threefive.Stream(tsdata, show_null = False)
- tsdata is an open file handle or sys.stdin.buffer to read 'piped' in data.
- show_null if set to True, enables showing SCTE 35 null commands.
Stream.decode()
- Calls Splice.show() when a SCTE-35 message is found
Parse a Local File with a Stream Instance
import sys
from threefive import Stream
'''
if __name__ =='__main__':
with open(sys.argv[1],'rb') as tsdata:
Stream(tsdata).decode()
Pipe a Video to Stream
curl -s https://futzu.com/xaa.ts -o - \
| python3 -c 'import sys;import threefive; threefive.Stream(sys.stdin.buffer).decode()'
Stream.decode_until_found()
- Use the Stream.decode_until_found method instead of Stream.decode().
- Returns Splice instances when SCTE-35 packets are found.
- Allows for customized SCTE-35 message handling.
Customized SCTE-35 Message Handling
import sys
from threefive import Stream
def do():
with open(sys.argv[1],'rb') as tsdata:
while True:
cue = Stream(tsdata).decode_until_found()
if not cue :
sys.exit()
else:
# Customized output
print('pid :',cue.header.pid, 'command:',
cue.command.name,'@',cue.command.pts_time,
'Out of Network:',
cue.command.out_of_network_indicator)
if __name__ == '__main__':
do()
- Output:
pid : 1055 command: Splice Insert @ 21951.133267 Out of Network: True
pid : 1015 command: Splice Insert @ 22516.907656 Out of Network: True
pid : 1055 command: Splice Insert @ 22026.133267 Out of Network: False
pid : 1045 command: Splice Insert @ 22864.350067 Out of Network: True
pid : 1015 command: Splice Insert @ 22696.907656 Out of Network: False
pid : 1045 command: Splice Insert @ 22960.350067 Out of Network: False
pid : 1015 command: Splice Insert @ 23516.827656 Out of Network: True
pid : 1015 command: Splice Insert @ 23696.827656 Out of Network: False
StreamPlus Class
- source streamplus.py
- threefive.StreamPlus is a sub class of threefive.Stream
threefive.StreamPlus(tsdata, show_null = False)
-
tsdata is an open file handle or sys.stdin.buffer to read 'piped' in data.
-
show_null if set to True, enables showing SCTE 35 null commands.
-
threefive.StreamPlus adds PTS timestamp for each SCTE 35 packet.
StreamPlus.decode()
- See Stream.decode()
StreamPlus.decode_until_found()
StreamProxy Class
- source streamproxy.py
- threefive.StreamProxy is a sub class of threefive.StreamPlus
threefive.StreamProxy(tsdata, show_null = False)
- Writes scte35 data to sys.stderr
- Writes all packets to sys.stdout
- Parse the scte35 and pipe the MPEG-TS stream.
StreamProxy.decode()
import threefive
# Name this proxy.py
with open('vid.ts','rb') as tsdata:
threefive.StreamProxy(tsdata).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
threefive-2.1.75.tar.gz
(15.4 kB
view hashes)
Built Distribution
threefive-2.1.75-py3-none-any.whl
(15.1 kB
view hashes)
Close
Hashes for threefive-2.1.75-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb80b8f6794394bb0c9ee412c6f794a2ada53979eeed3ca6821c06073c891655 |
|
MD5 | 2abd6025b0888345e724259215f08f47 |
|
BLAKE2b-256 | 86b512c8750076778ddeb9f3fb0e69396be051b540bed17ba57e10d60c3031f0 |