sangwonl / python-mpegdash

MPEG-DASH MPD(Media Presentation Description) Parser
MIT License
103 stars 54 forks source link

Decode signal SCTE-35 <binary> strings with threefive #62

Open futzu opened 4 months ago

futzu commented 4 months ago

I've been wanting to add DASH support to threefive, but it seems like it makes more sense to add SCTE-35 support to a DASH parser.

if you want to pull the SCTE-35 values from  a <binary> tag  base64 string  in a signal 
       <Signal
          xmlns="http://www.scte.org/schemas/35/2016">
          <Binary>/DAgAAAAAAAAAP/wDwUA15FRf//+ADS8AMAAAAAAAORhJCQ=</Binary>
        </Signal>

You can use threefive like this

from threefive import Cue

b64 ="/DAgAAAAAAAAAP/wDwUA15FRf//+ADS8AMAAAAAAAORhJCQ="
cue = Cue(b64)
cue.decode()

after calling decode all the SCTE-35 vars can be accessed via dot notation

>>>> cue.command.break_duration
38.4

cue.show() prints thje cue in json

>>>> cue.show()
{
    "info_section": {
        "table_id": "0xfc",
        "section_syntax_indicator": false,
        "private": false,
        "sap_type": "0x03",
        "sap_details": "No Sap Type",
        "section_length": 32,
        "protocol_version": 0,
        "encrypted_packet": false,
        "encryption_algorithm": 0,
        "pts_adjustment_ticks": 0,
        "pts_adjustment": 0.0,
        "cw_index": "0x00",
        "tier": "0x0fff",
        "splice_command_length": 15,
        "splice_command_type": 5,
        "descriptor_loop_length": 0,
        "crc": "0xe4612424"
    },
    "command": {
        "command_length": 15,
        "command_type": 5,
        "name": "Splice Insert",
        "break_auto_return": true,
        "break_duration": 38.4,
        "break_duration_ticks": 3456000,
        "splice_event_id": 14127441,
        "splice_event_cancel_indicator": false,
        "out_of_network_indicator": true,
        "program_splice_flag": true,
        "duration_flag": true,
        "splice_immediate_flag": true,
        "event_id_compliance_flag": true,
        "unique_program_id": 49152,
        "avail_num": 0,
        "avail_expected": 0
    },
    "descriptors": []
}
davemevans commented 4 months ago

Related: https://github.com/sangwonl/python-mpegdash/issues/23