Skip to content
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

Log keyframes when stream starts #672

Merged
merged 2 commits into from
May 13, 2024
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
1 change: 1 addition & 0 deletions pkg/config/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type BaseConfig struct {
type DebugConfig struct {
EnableProfiling bool `yaml:"enable_profiling"` // create dot file and pprof on internal error
PathPrefix string `yaml:"path_prefix"` // filepath prefix for uploads
LogKeyFrames bool `yaml:"log_keyframes"` // log first 15s of keyframes when streaming
StorageConfig `yaml:",inline"` // upload config (S3, Azure, GCP, or AliOSS)
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/pipeline/builder/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,26 @@ func (b *VideoBin) addEncoder() error {
return err
}

if b.conf.GetStreamConfig() != nil && b.conf.Debug.LogKeyFrames {
var firstKeyFrame *time.Duration
x264Enc.GetStaticPad("src").AddProbe(gst.PadProbeTypeBuffer, func(pad *gst.Pad, info *gst.PadProbeInfo) gst.PadProbeReturn {
buffer := info.GetBuffer()
if !buffer.HasFlags(gst.BufferFlagDeltaUnit) {
clockTime := buffer.PresentationTimestamp().AsDuration()
if firstKeyFrame == nil {
firstKeyFrame = clockTime
}
pts := *clockTime - *firstKeyFrame
logger.Debugw("keyframe generated", "pts", pts)
if pts > time.Second*15 {
return gst.PadProbeRemove
}
}

return gst.PadProbeOK
})
}

return nil

case types.MimeTypeVP9:
Expand Down
Loading