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

Save-to-webm: use timestamp from samplebuilder #130

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions save-to-webm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ func main() {
}

type webmSaver struct {
audioWriter, videoWriter webm.BlockWriteCloser
audioBuilder, videoBuilder *samplebuilder.SampleBuilder
audioTimestamp, videoTimestamp time.Duration
audioWriter, videoWriter webm.BlockWriteCloser
audioBuilder, videoBuilder *samplebuilder.SampleBuilder
hasStartAudioOffset, hasStartVideoOffset bool
startAudioOffset, startVideoOffset uint32
}

func newWebmSaver() *webmSaver {
Expand Down Expand Up @@ -66,8 +67,11 @@ func (s *webmSaver) PushOpus(rtpPacket *rtp.Packet) {
return
}
if s.audioWriter != nil {
s.audioTimestamp += sample.Duration
if _, err := s.audioWriter.Write(true, int64(s.audioTimestamp/time.Millisecond), sample.Data); err != nil {
if !s.hasStartAudioOffset {
s.startAudioOffset = sample.PacketTimestamp
tmatth marked this conversation as resolved.
Show resolved Hide resolved
s.hasStartAudioOffset = true
}
if _, err := s.audioWriter.Write(true, int64((sample.PacketTimestamp-s.startAudioOffset)/48), sample.Data); err != nil {
panic(err)
}
}
Expand Down Expand Up @@ -95,8 +99,11 @@ func (s *webmSaver) PushVP8(rtpPacket *rtp.Packet) {
}
}
if s.videoWriter != nil {
s.videoTimestamp += sample.Duration
if _, err := s.videoWriter.Write(videoKeyframe, int64(s.videoTimestamp/time.Millisecond), sample.Data); err != nil {
if !s.hasStartVideoOffset {
s.startVideoOffset = sample.PacketTimestamp
s.hasStartVideoOffset = true
}
if _, err := s.videoWriter.Write(videoKeyframe, int64((sample.PacketTimestamp-s.startVideoOffset)/90), sample.Data); err != nil {
panic(err)
}
}
Expand Down