Python SCTE Plugin

Use the Python SCTE plugin to process your SCTE 35/104 signal with a custom Python file. Your code should contain specific functions that hook into SCTE processing and control the state of the Live Slicer.

Python

Python and its libraries must be installed to your system's shared library path. By default, the Live Slicer uses Python 2.7, which is included with Mac OS X and Ubuntu versions 14.04 LTS or lower. However, you may configure the Live Slicer (version 20031300 or higher) to use Python 3.6 by including the following configuration in your Live Slicer configuration file:

Syntax (Python 3.6):

scte_python_version: 3.6

Syntax (Python 3.6 installed with pymalloc support):

scte_python_version: 3.6m

Setting up a Live Slicer

Set up a Live Slicer to use your Python SCTE plugin by adding the following settings to your Live Slicer configuration file:

scte_type: python

scte_module: my_scte_plugin

scte_python_version: 3.6m

If you have not installed Python 3.6 with pymalloc support, then you should update the scte_python_version setting with the correct version.

Copy your Python plugin to the plugins subfolder of your Live Slicer's installation directory and then replace my_scte_plugin with your Python plugin's file name.

Learn more.

Encrypted Plugins

Plugins may be either be plaintext or encrypted. The configuration for both plaintext and encrypted plugins is the same with the exception of file name. The file name for an encrypted plugin is the SHA-1 hash of the plaintext plugin's file name. Although the file name will be encrypted, the scte_module parameter should still be set to the plaintext file name.

If both an encrypted and plaintext version of your plugin are found, then the plaintext version will take precedence.

Sample Scenario

In this sample scenario:

Set the scte_module parameter to the following value:

scte_module: scte_example

If you would like to use the encrypted version of this plugin, please verify that the plaintext version of the plugin is not present in the Live Slicer's plugins folder.

Plugin Functions

The most basic plugin, which does nothing, must appear as:

import slicer
def Initialize():
    return slicer.Initialize()

This function is necessary to establish proper communication between the plugin and the slicer. The second, optional, function is where you perform SCTE logic:

def Process35(slice_info):
    slicer.Blackout(long(0))
    return long(0)

This function receives the SCTE35 packets and inside you may inspect the slice_info object containing the SCTE packet or call slicer module functions to control the slicer. SCTE104 packets are converted to SCTE35 and passed to this function for unified handling of SCTE.

Slicer Module

The slicer module provides a way for your plugin to call functions and manipulate slicer state.

The available functions are:

Function Description

AdEnd

Explicitly ends an ad break.

AdMeta

Adds metadata to an ad break.

AdStart

Starts an ad break.

Blackout

Initiates blackout mode.

ContentStart

Starts a new asset.

EndBoundary

Ends an ad boundary.

FlushBreakMeta

Defines the presentation timestamp (PTS) at which the metadata defined via the MetaMetadata function will be applied.

GetState

Indicates the current Live Slicer state.

GetStatus

Returns Live Slicer status and configuration information.

Initialize

Initializes the slicer module.

Metadata

Adds metadata to the asset currently being sliced.

MetaMetadata

Adds metadata to the asset associated with the next segment.

SlicerLogger

Logs error conditions, informational messages, and debug messages.

StartBoundary

Starts an ad boundary.

TimedMeta

Adds metadata as an ID3 tag at the presentation timestamp (PTS).

Initialize

Initializes the slicer module. Call this function via the Initialize() function as shown above.

GetState

Returns a string that indicates the current Live Slicer state.

Valid values are:

Sample request:

print slicer.GetState()

GetStatus

Returns Live Slicer status and configuration information. The response for this function may contain the following parameters:

Parameter

Type

Description

status

Object

Contains Live Slicer status information. This object is similar to the status object returned by the status endpoint from the Live Slicer API.

config

Object

Contains Live Slicer configuration file settings.

slicerID

String

Identifies the Live Slicer's ID as defined in the Live Slicer configuration file.

externalID

String

Indicates the external ID that will be assigned to the CMS asset created from the live stream.

Sample request:

print slicer.GetStatus()

Blackout

Initiates blackout mode.

Sample request:

print slicer.Blackout(long(pts))

ContentStart

Starts a new asset. Description and External ID are optional.

Sample request:

print slicer.ContentStart(long(pts), "Description", "External ID")

AdStart

Starts an ad break. Duration is optional. If omitted, you must call AdEnd() to end the ad break.

Sample request:

print slicer.AdStart(long(pts), long(duration))

AdEnd

Explicitly ends an ad break.

Sample request:

print slicer.AdEnd(long(pts))

AdMeta

Adds metadata to a specific ad break. Call AdMeta before starting an ad break.

This function only adds metadata to a specific ad break. It is not applied globally across all ad breaks.

Sample request:

print slicer.AdMeta("key", "value")

FlushBreakMeta

Defines the presentation timestamp (PTS) at which the metadata defined via the MetaMetadata function will be applied.

Sample request:

print slicer.FlushBreakMeta(long(pts))

Metadata

Adds metadata to the asset currently being sliced as determined by the next video frame.

Metadata may be incorrectly applied to an asset under certain conditions. For example, metatadata may be applied to the previous asset when this function is called directly after a content_start. The recommended method for setting metadata is via the MetaMetadata and FlushBreakMeta functions.

View the metadata associated with an asset from within the CMS.

Sample request:

print slicer.Metadata("key", "value")

MetaMetadata

Adds metadata to the asset associated with the next segment as determined by content start, ad start, etc.

The recommended method for associating metadata with an asset is to set it via the MetaMetadata function and then setting the presentation timestamp (PTS) at which it will be applied to an asset via the FlushBreakMeta function.

View the metadata associated with an asset from within the CMS.

Sample request:

print slicer.MetaMetadata("key", "value")

SlicerLogger

Logs error conditions, informational messages, and debug messages to the terminal and syslog.

Learn more about logging.

Valid log levels are:

Syntax:

print slicer.SlicerLogger("Log Level", "Log Message")

Sample request:

print slicer.SlicerLogger("info", "Started an asset boundary.")

StartBoundary

Starts an asset boundary. If a boundary is already active, this is ignored. Duration is optional. If omitted, call EndBoundary() to explicitly end an asset boundary.

Sample request:

print slicer.StartBoundary(long(pts), name, long(duration))

EndBoundary

Ends an asset boundary. This function is ignored when there isn't an active boundary.

Sample request:

print slicer.EndBoundary(long(pts))

TimedMeta

Adds metadata as an ID3 tag at the presentation timestamp (PTS).

Syntax:

print slicer.TimedMeta(Presentation Timestamp, Metadata Key, Metadata Value)

Sample request:

print slicer.TimedMeta(long(pts), "key", "value")