Skip to content

Commit

Permalink
force keyframe interval for segments (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 authored Sep 29, 2023
1 parent 6770073 commit 2885c36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
8 changes: 8 additions & 0 deletions pkg/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
14 changes: 1 addition & 13 deletions pkg/config/output_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions pkg/config/output_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2885c36

Please sign in to comment.