Creating SCTE-35 messages using Python involves generating the necessary binary data and constructing the message payload according to the SCTE-35 specification. In this example, we will use the struct module in Python to pack the SCTE-35 payload into a binary format.

Here is an simple example code snippet that shows how to create an SCTE-35 message using Python:

import struct

# Construct the splice_info_section_payload according to the SCTE-35 specification
splice_info_section_payload = struct.pack('>BIBHBBBBHBIBHHIBB', 
    0xFC, # table_id
    0x000001, # section_syntax_indicator and private_indicator
    0x00, # section_length (will be set later)
    0x0000, # protocol_version and splice_command_type
    0x0001, # descriptor_loop_length
    0x0000, # identifier
    0xFF, # segmentation_upid_type
    0x00, # segmentation_upid_length
    0x01, # segmentation_type_id
    0x00, # segmentation_type_id_reserved and segmentation_event_id
    0x00000000, # segmentation_duration (in 90kHz clock ticks)
    0x00, # segmentation_cancel_indicator and program_segmentation_flag
    0x00, # segmentation_duration_flag and delivery_not_restricted_flag
    0x00, # web_delivery_allowed_flag, no_regional_blackout_flag, and archive_allowed_flag
    0x0000, # device_restrictions
    0x0F) # segmentation_component_count

# Set the section length field to the length of the splice_info_section_payload
splice_info_section_payload = splice_info_section_payload[:2] + struct.pack('>H', len(splice_info_section_payload)) + splice_info_section_payload[4:]

# Construct the SCTE-35 message using the splice_info_section_payload
scte_35_message = struct.pack('>BHB', 0x00, 0x00, 0x0001) + splice_info_section_payload

# Display the SCTE-35 message as a hex string
print('SCTE-35 message:', scte_35_message.hex())

Explanation:

This code snippet creates an SCTE-35 message that contains a splice_info_section_payload with a single segmentation descriptor. The struct module is used to pack the data into a binary format that conforms to the SCTE-35 specification. The splice_info_section_payload is constructed using the following fields:

  • table_id: The table_id field is set to 0xFC, which indicates that the message is an SCTE-35 splice information section.
  • section_syntax_indicator and private_indicator: These fields are set to 0x000001 to indicate that the section uses the long form syntax and is not encrypted.
  • section_length: This field is initially set to 0x00 and will be updated later to reflect the actual length of the payload.
  • protocol_version and splice_command_type: These fields are set to 0x0000 to indicate that the protocol version is 0 and the splice command is a splice null command.
  • descriptor_loop_length: This field is set to 0x0001 to indicate that there is one segmentation descriptor in the payload.
  • identifier: This field is set to 0x0000 to indicate that the descriptor is an SCTE segmentation descriptor.
  • segmentation_upid_type: This field is set to 0xFF to indicate that there is no segmentation UPID.
  • segmentation_upid_length: This field is set to 0x00 to indicate that there is no segmentation UPID.
  • segmentation_type_id: This field is set to 0x01 to indicate that the segmentation descriptor contains a program segmentation component.
  • segmentation_type_id_reserved and segmentation_event_id: These fields are set to 0x00 to indicate that there is no segmentation event.
  • segmentation_duration: This field is set to 0x00000000 to indicate that the segmentation duration is unknown.
  • segmentation_cancel_indicator and program_segmentation_flag: These fields are set to 0x00 to indicate that the segment is not cancelled and there is no program segmentation.
  • segmentation_duration_flag and delivery_not_restricted_flag: These fields are set to 0x00 to indicate that the segment duration is not signaled and the delivery is not restricted.
  • web_delivery_allowed_flag, no_regional_blackout_flag, and archive_allowed_flag: These fields are set to 0x00 to indicate that web delivery is not allowed, there is no regional blackout, and the content is not intended for archival.
  • device_restrictions: This field is set to 0x0000 to indicate that there are no device restrictions.
  • segmentation_component_count: This field is set to 0x0F to indicate that there are 15 segmentation components.

The section length field is then updated to reflect the actual length of the splice_info_section_payload. The SCTE-35 message is constructed by appending the splice_info_section_payload to a header that contains the message_type field set to 0x00 and the message_version and reserved fields set to 0x00.

Finally, the SCTE-35 message is printed as a hex string.

This code snippet provides a basic example of how to create an SCTE-35 message using Python. However, it is important to note that the SCTE-35 specification is complex and there are many different types of SCTE-35 messages that can be created. It is recommended to refer to the SCTE-35 specification and seek expert guidance when working with SCTE-35 messages.

Thanks for reading

2 Replies to “Create SCTE-35 messages using Python”

Leave a Reply

Your email address will not be published. Required fields are marked *