diff --git a/revid/revid.go b/revid/revid.go index 62e22d64..0c989ba8 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -125,9 +125,6 @@ type Revid struct { isRunning bool } -var now = time.Now() -var prevTime = now - // packer takes data segments and packs them into clips // of the number frames specified in the owners config. type packer struct { @@ -136,6 +133,10 @@ type packer struct { packetCount uint } +// lastTime is used in the packer's Write method to determine how much time has +// passed since last write to packer +var lastTime time.Time + // Write implements the io.Writer interface. // // Unless the ring buffer returns an error, all writes @@ -156,11 +157,11 @@ func (p *packer) Write(frame []byte) (int, error) { return n, err } p.packetCount++ - now = time.Now() - if (p.owner.config.Output1 != Rtmp && now.Sub(prevTime) > clipDuration && p.packetCount%7 == 0) || p.owner.config.Output1 == Rtmp { + now := time.Now() + if (p.owner.config.Output1 != Rtmp && now.Sub(lastTime) > clipDuration && p.packetCount%7 == 0) || p.owner.config.Output1 == Rtmp { p.owner.buffer.Flush() p.packetCount = 0 - prevTime = now + lastTime = now } return len(frame), nil }