Refactor the offline clip handling.

More stable, reduced function complexity.
This commit is contained in:
Gabe Kangas
2021-11-26 20:53:27 -08:00
parent 3ed7035e39
commit 73e58a7801
4 changed files with 158 additions and 94 deletions

View File

@@ -35,6 +35,7 @@ type Transcoder struct {
currentStreamOutputSettings []models.StreamOutputVariant
currentLatencyLevel models.LatencyLevel
isEvent bool
TranscoderCompleted func(error)
}
@@ -153,6 +154,16 @@ func (t *Transcoder) Start() {
}
}
// SetLatencyLevel will set the latency level for the instance of the transcoder.
func (t *Transcoder) SetLatencyLevel(level models.LatencyLevel) {
t.currentLatencyLevel = level
}
// SetIsEvent will allow you to set a stream as an "event".
func (t *Transcoder) SetIsEvent(isEvent bool) {
t.isEvent = isEvent
}
func (t *Transcoder) getString() string {
port := t.internalListenerPort
localListenerAddress := "http://127.0.0.1:" + port
@@ -170,6 +181,14 @@ func (t *Transcoder) getString() string {
t.segmentIdentifier = shortid.MustGenerate()
}
hlsEventString := ""
if t.isEvent {
hlsEventString = "-hls_playlist_type event"
} else {
// Don't let the transcoder close the playlist. We do it manually.
hlsOptionFlags = append(hlsOptionFlags, "omit_endlist")
}
hlsOptionsString := ""
if len(hlsOptionFlags) > 0 {
hlsOptionsString = "-hls_flags " + strings.Join(hlsOptionFlags, "+")
@@ -191,6 +210,7 @@ func (t *Transcoder) getString() string {
"-hls_time", strconv.Itoa(t.currentLatencyLevel.SecondsPerSegment), // Length of each segment
"-hls_list_size", strconv.Itoa(t.currentLatencyLevel.SegmentCount), // Max # in variant playlist
hlsOptionsString,
hlsEventString,
"-segment_format_options", "mpegts_flags=mpegts_copyts=1",
// Video settings
@@ -411,11 +431,6 @@ func (t *Transcoder) SetOutputPath(output string) {
t.segmentOutputPath = output
}
// SetAppendToStream enables appending to the HLS stream instead of overwriting.
func (t *Transcoder) SetAppendToStream(append bool) {
t.appendToStream = append
}
// SetIdentifier enables appending a unique identifier to segment file name.
func (t *Transcoder) SetIdentifier(output string) {
t.segmentIdentifier = output