From 63b56d02a432fa649acfcd68ee49bbc4913d9e24 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Thu, 28 Sep 2023 23:33:45 -0700 Subject: [PATCH] force keyframe interval for segments --- pkg/config/output.go | 8 ++++++++ pkg/config/output_segment.go | 14 +------------- pkg/config/output_stream.go | 5 ----- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/pkg/config/output.go b/pkg/config/output.go index 7f862698..954c7e79 100644 --- a/pkg/config/output.go +++ b/pkg/config/output.go @@ -148,6 +148,14 @@ func (p *PipelineConfig) updateEncodedOutputs(req EncodedOutput) error { } } + if segmentConf := p.Outputs[types.EgressTypeSegments]; segmentConf != nil { + // double the segment length + p.KeyFrameInterval = float64(2 * segmentConf.(*SegmentConfig).SegmentDuration) + } else if p.KeyFrameInterval == 0 && p.Outputs[types.EgressTypeStream] != nil { + // default 4s for streams + p.KeyFrameInterval = 4 + } + if p.OutputCount == 0 { return errors.ErrInvalidInput("output") } diff --git a/pkg/config/output_segment.go b/pkg/config/output_segment.go index fb07b52d..ba822d46 100644 --- a/pkg/config/output_segment.go +++ b/pkg/config/output_segment.go @@ -64,19 +64,7 @@ func (p *PipelineConfig) getSegmentConfig(segments *livekit.SegmentedFileOutput) } if conf.SegmentDuration == 0 { - if p.KeyFrameInterval >= 1 { - conf.SegmentDuration = int(p.KeyFrameInterval) - } else { - conf.SegmentDuration = 4 - } - } - - if p.KeyFrameInterval == 0 { - // The splitMuxSink should request key frames from the encoder at expected frame boundaries. - // Set the key frame interval to twice the segment duration as a failsafe - p.KeyFrameInterval = 2 * float64(conf.SegmentDuration) - } else if p.KeyFrameInterval < float64(conf.SegmentDuration) && p.KeyFrameInterval >= 1 { - conf.SegmentDuration = int(p.KeyFrameInterval) + conf.SegmentDuration = 4 } switch segments.Protocol { diff --git a/pkg/config/output_stream.go b/pkg/config/output_stream.go index a32fea05..92940f86 100644 --- a/pkg/config/output_stream.go +++ b/pkg/config/output_stream.go @@ -71,10 +71,5 @@ func (p *PipelineConfig) getStreamConfig(outputType types.OutputType, urls []str p.AudioOutCodec = types.MimeTypeRawAudio } - // Use a 4s default key frame interval for streaming - if p.KeyFrameInterval == 0 { - p.KeyFrameInterval = 4 - } - return conf, nil }