-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add parser for SCTE35 markers
- Loading branch information
Showing
10 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package internal | ||
|
||
import ( | ||
"github.com/Comcast/gots/v2/scte35" | ||
) | ||
|
||
type SCTE35Info struct { | ||
PID uint16 `json:"pid"` | ||
SpliceCommand SpliceCommand `json:"spliceCommand"` | ||
SegDesc []SegmentationDescriptor `json:"segmentationDes,omitempty"` | ||
} | ||
|
||
type SpliceCommand struct { | ||
Type string `json:"type"` | ||
EventId uint32 `json:"eventId"` | ||
PTS uint64 `json:"pts"` | ||
Duration uint64 `json:"duration,omitempty"` | ||
Out bool `json:"outOfNetwork,omitempty"` | ||
Immediate bool `json:"immediate,omitempty"` | ||
} | ||
|
||
type SegmentationDescriptor struct { | ||
SegmentNumber uint8 `json:"segmentNumber"` | ||
EventId uint32 `json:"eventId"` | ||
Type string `json:"type"` | ||
Duration uint64 `json:"duration,omitempty"` | ||
} | ||
|
||
func toSCTE35(pid uint16, msg scte35.SCTE35) SCTE35Info { | ||
scte35Info := SCTE35Info{PID: pid, SpliceCommand: toSpliceCommand(msg.CommandInfo())} | ||
|
||
if insert, ok := msg.CommandInfo().(scte35.SpliceInsertCommand); ok { | ||
scte35Info.SpliceCommand = toSpliceInsertCommand(insert) | ||
} | ||
for _, desc := range msg.Descriptors() { | ||
segDesc := toSegmentationDescriptor(desc) | ||
scte35Info.SegDesc = append(scte35Info.SegDesc, segDesc) | ||
} | ||
|
||
return scte35Info | ||
} | ||
|
||
func toSpliceCommand(spliceCommand scte35.SpliceCommand) SpliceCommand { | ||
spliceCmd := SpliceCommand{Type: getCommandType(spliceCommand)} | ||
if spliceCommand.HasPTS() { | ||
spliceCmd.PTS = uint64(spliceCommand.PTS()) | ||
} | ||
|
||
return spliceCmd | ||
} | ||
|
||
func toSegmentationDescriptor(segdesc scte35.SegmentationDescriptor) SegmentationDescriptor { | ||
segDesc := SegmentationDescriptor{} | ||
segDesc.EventId = segdesc.EventID() | ||
segDesc.Type = scte35.SegDescTypeNames[segdesc.TypeID()] | ||
segDesc.SegmentNumber = segdesc.SegmentNumber() | ||
if segdesc.HasDuration() { | ||
segDesc.Duration = uint64(segdesc.Duration()) | ||
} | ||
return segDesc | ||
} | ||
|
||
func toSpliceInsertCommand(spliceCommand scte35.SpliceInsertCommand) SpliceCommand { | ||
spliceCmd := SpliceCommand{Type: getCommandType(spliceCommand)} | ||
spliceCmd.EventId = spliceCommand.EventID() | ||
spliceCmd.Immediate = spliceCommand.SpliceImmediate() | ||
spliceCmd.Out = spliceCommand.IsOut() | ||
if spliceCommand.HasPTS() { | ||
spliceCmd.PTS = uint64(spliceCommand.PTS()) | ||
} | ||
if spliceCommand.HasDuration() { | ||
spliceCmd.Duration = uint64(spliceCommand.Duration()) | ||
} | ||
|
||
return spliceCmd | ||
} | ||
|
||
func getCommandType(spliceCommand scte35.SpliceCommand) string { | ||
return scte35.SpliceCommandTypeNames[spliceCommand.CommandType()] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"pid":256,"codec":"AVC","type":"video"} | ||
{"pid":257,"codec":"AAC","type":"audio"} | ||
{"pid":1001,"codec":"SCTE35","type":"cue"} | ||
{"pid":1001,"spliceCommand":{"type":"SpliceInsert","eventId":255,"pts":1032000,"duration":1800000,"outOfNetwork":true}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"pid":256,"codec":"AVC","type":"video"} | ||
{"pid":257,"codec":"AAC","type":"audio"} | ||
{"pid":1001,"codec":"SCTE35","type":"cue"} | ||
{"SDT":[{"serviceId":1,"descriptors":[{"serviceName":"Service01","providerName":"FFmpeg"}]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters