Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

threefive is The Leading SCTE-35 Parsing Lib for Mpeg-TS Video Streams, and Base64 or Hex Encoded Messages. threefive is Used in Production By Three of The Largest Broadcast Networks in The World..

Project description

:rocket: threefive

threefive is a SCTE35 Parser library in Python3.

  • All 2019 SCTE-35 Splice Commands and Splice Descriptors are fully Supported.

  • threefive is simple and easy to use.

Why so many releases?

  • I generate a lot 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 11/27/2020


  • Stream.decode_next() will be removed in 2.2.37.

    • The decode_next() method has proven to be problematic since the switch to parsing MPEG-TS tables directly.
    • Use Stream.decode(func=myfunc) instead. It works just like a callback function.
  • As of version 2.1.95, threefive.version returns a string for the current version.

  >>> import threefive
  >>> threefive.version()

Fast _Start


  • Python 3.6+ or pypy3
  • bitn


  • git
git clone

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 

🡡 top

Easy threefive

The decode Function

  • source
  • threefive.decode is an all purpose function to decode SCTE 35 messages from a file or string.
import threefive
  • MpegTS
  • Base64
  • Hex

🡡 top

Advanced threefive

Cue Class

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


cue = Cue(B64)
Return cue as dict

# Splice Info Section

# Splice Command

# Splice Descriptors
Return cue as JSON
jason = cue.get_json()
Print cue as JSON

🡡 top

Stream Class

 threefive.Stream(tsdata, show_null = False)
  • source

  • 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 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_program(the_program,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.

List programs and streams for a video.

# pypy3
>>>> from threefive import Stream, version
>>>> version
>>>> with open('video.ts','rb') as tsdata:
....     st = Stream(tsdata)

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


import sys
from threefive import Stream

if __name__ =='__main__':
   with open(sys.argv[1],'rb') as tsdata:
       sp = Stream(tsdata)
  • Pass in custom function

  • func should match the interface func(cue)

  • example

import sys
import threefive

def display(cue):

def do():
   with open(sys.argv[1],'rb') as tsdata:
    sp = threefive.Stream(tsdata)
    sp.decode(func = display)       

if __name__ == '__main__':

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:

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)
  • Pipe to mplayer
python3 | mplayer -

🡡 top

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.

Files for threefive, version 2.2.37
Filename, size File type Python version Upload date Hashes
Filename, size threefive-2.2.37-py3-none-any.whl (19.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size threefive-2.2.37.tar.gz (18.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page