Skip to content

Support Scte35 Splice Inserts in EventStream. #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ go get -u github.com/zencoder/go-dash
* DRM (ContentProtection)
* PlayReady
* Widevine
* Scte35 Splice Insert

## Known Limitations (for now) (PRs welcome)

* No PSSH/PRO generation
* Limited Profile Support
* Scte35 Time Signal

## Example Usage

Expand Down
9 changes: 5 additions & 4 deletions mpd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ type EventStream struct {
}

type Event struct {
XMLName xml.Name `xml:"Event"`
ID *string `xml:"id,attr,omitempty"`
PresentationTime *int64 `xml:"presentationTime,attr,omitempty"`
Duration *int64 `xml:"duration,attr,omitempty"`
XMLName xml.Name `xml:"Event"`
ID *string `xml:"id,attr,omitempty"`
SpliceInfoSection *Scte35SpliceInfoSection `xml:"SpliceInfoSection,omitempty"`
PresentationTime *int64 `xml:"presentationTime,attr,omitempty"`
Duration *int64 `xml:"duration,attr,omitempty"`
}
55 changes: 55 additions & 0 deletions mpd/fixtures/scte35.mpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:scte35="urn:scte:scte35:2013:xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="dynamic" minBufferTime="PT30S" availabilityStartTime="2020-10-26T20:23:21.839000+00:00" minimumUpdatePeriod="PT15S" publishTime="2020-10-26T21:31:19" timeShiftBufferDepth="PT118.999S" suggestedPresentationDelay="PT25S" id="201">
<Period id="545" start="PT32.808S">
<SupplementalProperty schemeIdUri="urn:scte:dash:utc-time" value="2020-10-26T00:54:05.508Z"></SupplementalProperty>
<AdaptationSet mimeType="video/mp4" startWithSAP="1" subsegmentStartsWithSAP="1" segmentAlignment="true" subsegmentAlignment="true" bitstreamSwitching="true">
<Representation bandwidth="249984" codecs="avc1.64000D" frameRate="30000/1001" height="224" id="1" width="400">
<SegmentTemplate presentationTimeOffset="97434268" initialization="manifest_video_1_0_init.mp4?m=1603743253" media="manifest_video_1_0_$Number$.mp4?m=1603743253" startNumber="665" timescale="30000">
<SegmentTimeline>
<S t="118867680" d="180180" r="19"></S>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
<AdaptationSet mimeType="audio/mp4" segmentAlignment="false" lang="und">
<Representation audioSamplingRate="48000" bandwidth="66574" codecs="mp4a.40.2" id="8">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"></AudioChannelConfiguration>
<SegmentTemplate presentationTimeOffset="155895040" initialization="manifest_audio_2_0_init.mp4?m=1603743253" media="manifest_audio_2_0_$Number$.mp4?m=1603743253" startNumber="665" timescale="48000">
<SegmentTimeline>
<S t="190188800" d="288768"></S>
<S t="190477568" d="287744"></S>
<S t="190765312" d="288768"></S>
<S t="191054080" d="287744"></S>
<S t="191341824" d="288768"></S>
<S t="191630592" d="287744"></S>
<S t="191918336" d="288768"></S>
<S t="192207104" d="287744"></S>
<S t="192494848" d="288768"></S>
<S t="192783616" d="287744"></S>
<S t="193071360" d="288768"></S>
<S t="193360128" d="287744"></S>
<S t="193647872" d="288768"></S>
<S t="193936640" d="287744"></S>
<S t="194224384" d="288768"></S>
<S t="194513152" d="287744"></S>
<S t="194800896" d="288768" r="1"></S>
<S t="195378432" d="287744"></S>
<S t="195666176" d="288768"></S>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
<EventStream schemeIdUri="urn:scte:scte35:2013:xml" timescale="90000">
<Event duration="4051047">
<scte35:SpliceInfoSection protocolVersion="0" ptsAdjustment="207000" tier="4095">
<scte35:SpliceInsert spliceEventId="1603904856" spliceEventCancelIndicator="false" outOfNetworkIndicator="true" spliceImmediateFlag="false" uniqueProgramId="1" availNum="1" availsExpected="1">
<scte35:Program>
<scte35:SpliceTime ptsTime="5905840702"></scte35:SpliceTime>
</scte35:Program>
<scte35:BreakDuration autoReturn="true" duration="4051047"></scte35:BreakDuration>
</scte35:SpliceInsert>
</scte35:SpliceInfoSection>
</Event>
</EventStream>
</Period>
</MPD>
102 changes: 73 additions & 29 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ var (

type MPD struct {
XMLNs *string `xml:"xmlns,attr"`
Scte35NS *Scte35NS `xml:"scte35,attr,omitempty"`
XsiNS *XsiNS `xml:"xsi,attr,omitempty"`
XsiSchemaLocation *XsiSL `xml:"schemaLocation,attr,omitempty"`
Profiles *string `xml:"profiles,attr"`
Type *string `xml:"type,attr"`
MediaPresentationDuration *string `xml:"mediaPresentationDuration,attr"`
Expand All @@ -82,18 +85,56 @@ type MPD struct {
period *Period
Periods []*Period `xml:"Period,omitempty"`
UTCTiming *DescriptorType `xml:"UTCTiming,omitempty"`
ID string `xml:"id,attr,omitempty"`
}

type XsiNS struct {
XmlName xml.Name
Value string
}

func (s *XsiNS) UnmarshalXMLAttr(attr xml.Attr) error {
s.XmlName = attr.Name
s.Value = attr.Value
return nil
}

func (s *XsiNS) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
if strings.Contains(s.XmlName.Local, "xsi") {
return xml.Attr{Name: xml.Name{Local: "xmlns:xsi"}, Value: s.Value}, nil
}
return xml.Attr{}, nil
}

type XsiSL struct {
XmlName xml.Name
Value string
}

func (s *XsiSL) UnmarshalXMLAttr(attr xml.Attr) error {
s.XmlName = attr.Name
s.Value = attr.Value
return nil
}

func (s *XsiSL) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
if strings.Contains(s.XmlName.Local, "schemaLocation") {
return xml.Attr{Name: xml.Name{Local: "xsi:schemaLocation"}, Value: s.Value}, nil
}
return xml.Attr{}, nil
}

type Period struct {
ID string `xml:"id,attr,omitempty"`
Duration Duration `xml:"duration,attr,omitempty"`
Start *Duration `xml:"start,attr,omitempty"`
BaseURL string `xml:"BaseURL,omitempty"`
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"`
AdaptationSets []*AdaptationSet `xml:"AdaptationSet,omitempty"`
EventStreams []EventStream `xml:"EventStream,omitempty"`
SupplementalProperty []DescriptorType `xml:"SupplementalProperty,omitempty"`
ID string `xml:"id,attr,omitempty"`
Duration Duration `xml:"duration,attr,omitempty"`
Start *Duration `xml:"start,attr,omitempty"`
BaseURL string `xml:"BaseURL,omitempty"`
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"`
AdaptationSets []*AdaptationSet `xml:"AdaptationSet,omitempty"`
EventStreams []EventStream `xml:"EventStream,omitempty"`
}

type DescriptorType struct {
Expand All @@ -115,6 +156,7 @@ type CommonAttributesAndElements struct {
Codecs *string `xml:"codecs,attr"`
MaximumSAPPeriod *string `xml:"maximumSAPPeriod,attr"`
StartWithSAP *int64 `xml:"startWithSAP,attr"`
SubsegmentStartsWithSAP *int64 `xml:"subsegmentStartsWithSAP,attr,omitempty"`
MaxPlayoutRate *string `xml:"maxPlayoutRate,attr"`
ScanType *string `xml:"scanType,attr"`
FramePacking []DescriptorType `xml:"FramePacking,omitempty"`
Expand Down Expand Up @@ -167,26 +209,28 @@ type dtoAdaptationSet struct {

type AdaptationSet struct {
CommonAttributesAndElements
XMLName xml.Name `xml:"AdaptationSet"`
ID *string `xml:"id,attr"`
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
Lang *string `xml:"lang,attr"`
Group *string `xml:"group,attr"`
PAR *string `xml:"par,attr"`
MinBandwidth *string `xml:"minBandwidth,attr"`
MaxBandwidth *string `xml:"maxBandwidth,attr"`
MinWidth *string `xml:"minWidth,attr"`
MaxWidth *string `xml:"maxWidth,attr"`
MinHeight *string `xml:"minHeight,attr"`
MaxHeight *string `xml:"maxHeight,attr"`
ContentType *string `xml:"contentType,attr"`
SelectionPriority *uint64 `xml:"selectionPriority,attr"`
Roles []*Role `xml:"Role,omitempty"`
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
Representations []*Representation `xml:"Representation,omitempty"`
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
XMLName xml.Name `xml:"AdaptationSet"`
ID *string `xml:"id,attr"`
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
SubsegmentAlignment *bool `xml:"subsegmentAlignment,attr,omitempty"`
BitstreamSwitching *bool `xml:"bitstreamSwitching,attr,omitempty"`
Lang *string `xml:"lang,attr"`
Group *string `xml:"group,attr"`
PAR *string `xml:"par,attr"`
MinBandwidth *string `xml:"minBandwidth,attr"`
MaxBandwidth *string `xml:"maxBandwidth,attr"`
MinWidth *string `xml:"minWidth,attr"`
MaxWidth *string `xml:"maxWidth,attr"`
MinHeight *string `xml:"minHeight,attr"`
MaxHeight *string `xml:"maxHeight,attr"`
ContentType *string `xml:"contentType,attr"`
SelectionPriority *uint64 `xml:"selectionPriority,attr"`
Roles []*Role `xml:"Role,omitempty"`
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
Representations []*Representation `xml:"Representation,omitempty"`
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
}

func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
Expand Down
66 changes: 33 additions & 33 deletions mpd/mpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ import (
)

const (
VALID_MEDIA_PRESENTATION_DURATION string = "PT6M16S"
VALID_MIN_BUFFER_TIME string = "PT1.97S"
VALID_AVAILABILITY_START_TIME string = "1970-01-01T00:00:00Z"
VALID_MINIMUM_UPDATE_PERIOD string = "PT5S"
VALID_SCAN_TYPE string = "progressive"
VALID_SEGMENT_ALIGNMENT bool = true
VALID_START_WITH_SAP int64 = 1
VALID_LANG string = "en"
VALID_DURATION int64 = 1968
VALID_INIT_PATH_AUDIO string = "$RepresentationID$/audio/en/init.mp4"
VALID_MEDIA_PATH_AUDIO string = "$RepresentationID$/audio/en/seg-$Number$.m4f"
VALID_START_NUMBER int64 = 0
VALID_TIMESCALE int64 = 1000
VALID_AUDIO_SAMPLE_RATE int64 = 44100
VALID_AUDIO_BITRATE int64 = 67095
VALID_AUDIO_CODEC string = "mp4a.40.2"
VALID_AUDIO_ID string = "800"
VALID_VIDEO_BITRATE int64 = 1518664
VALID_VIDEO_CODEC string = "avc1.4d401f"
VALID_VIDEO_ID string = "800"
VALID_VIDEO_FRAMERATE string = "30000/1001"
VALID_VIDEO_WIDTH int64 = 960
VALID_VIDEO_HEIGHT int64 = 540
VALID_BASE_URL_VIDEO string = "800k/output-video-1.mp4"
VALID_INDEX_RANGE string = "629-756"
VALID_INIT_RANGE string = "0-628"
VALID_PLAYREADY_PRO string = "BgIAAAEAAQD8ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4ATAA5AFcAOQBXAGsAcABWAEsAawArADQAMABHAEgAMwBZAFUASgBSAFYAUQA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBJAEsAegBZADIASABaAEwAQQBsAEkAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA="
VALID_WV_HEADER string = "CAESEFq91S9VSk8quNBh92FCUVUaCGNhc3RsYWJzIhhXcjNWTDFWS1R5cTQwR0gzWVVKUlZRPT0yB2RlZmF1bHQ="
VALID_SUBTITLE_BANDWIDTH int64 = 256
VALID_SUBTITLE_ID string = "subtitle_en"
VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt"
VALID_ROLE string = "main"
VALID_LOCATION string = "https://example.com/location.mpd"
VALID_MEDIA_PRESENTATION_DURATION string = "PT6M16S"
VALID_MIN_BUFFER_TIME string = "PT1.97S"
VALID_AVAILABILITY_START_TIME string = "1970-01-01T00:00:00Z"
VALID_MINIMUM_UPDATE_PERIOD string = "PT5S"
VALID_SCAN_TYPE string = "progressive"
VALID_SEGMENT_ALIGNMENT bool = true
VALID_START_WITH_SAP int64 = 1
VALID_LANG string = "en"
VALID_DURATION float64 = 1968.0
VALID_INIT_PATH_AUDIO string = "$RepresentationID$/audio/en/init.mp4"
VALID_MEDIA_PATH_AUDIO string = "$RepresentationID$/audio/en/seg-$Number$.m4f"
VALID_START_NUMBER int64 = 0
VALID_TIMESCALE int64 = 1000
VALID_AUDIO_SAMPLE_RATE int64 = 44100
VALID_AUDIO_BITRATE int64 = 67095
VALID_AUDIO_CODEC string = "mp4a.40.2"
VALID_AUDIO_ID string = "800"
VALID_VIDEO_BITRATE int64 = 1518664
VALID_VIDEO_CODEC string = "avc1.4d401f"
VALID_VIDEO_ID string = "800"
VALID_VIDEO_FRAMERATE string = "30000/1001"
VALID_VIDEO_WIDTH int64 = 960
VALID_VIDEO_HEIGHT int64 = 540
VALID_BASE_URL_VIDEO string = "800k/output-video-1.mp4"
VALID_INDEX_RANGE string = "629-756"
VALID_INIT_RANGE string = "0-628"
VALID_PLAYREADY_PRO string = "BgIAAAEAAQD8ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0AbABuAHMAPQAiAGgAdAB0AHAAOgAvAC8AcwBjAGgAZQBtAGEAcwAuAG0AaQBjAHIAbwBzAG8AZgB0AC4AYwBvAG0ALwBEAFIATQAvADIAMAAwADcALwAwADMALwBQAGwAYQB5AFIAZQBhAGQAeQBIAGUAYQBkAGUAcgAiACAAdgBlAHIAcwBpAG8AbgA9ACIANAAuADAALgAwAC4AMAAiAD4APABEAEEAVABBAD4APABQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsARQBZAEwARQBOAD4AMQA2ADwALwBLAEUAWQBMAEUATgA+ADwAQQBMAEcASQBEAD4AQQBFAFMAQwBUAFIAPAAvAEEATABHAEkARAA+ADwALwBQAFIATwBUAEUAQwBUAEkATgBGAE8APgA8AEsASQBEAD4ATAA5AFcAOQBXAGsAcABWAEsAawArADQAMABHAEgAMwBZAFUASgBSAFYAUQA9AD0APAAvAEsASQBEAD4APABDAEgARQBDAEsAUwBVAE0APgBJAEsAegBZADIASABaAEwAQQBsAEkAPQA8AC8AQwBIAEUAQwBLAFMAVQBNAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA="
VALID_WV_HEADER string = "CAESEFq91S9VSk8quNBh92FCUVUaCGNhc3RsYWJzIhhXcjNWTDFWS1R5cTQwR0gzWVVKUlZRPT0yB2RlZmF1bHQ="
VALID_SUBTITLE_BANDWIDTH int64 = 256
VALID_SUBTITLE_ID string = "subtitle_en"
VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt"
VALID_ROLE string = "main"
VALID_LOCATION string = "https://example.com/location.mpd"
)

func TestNewMPDLive(t *testing.T) {
Expand Down
Loading