Re-calculate time offset from CPU time to real time on each frame
This commit is contained in:
parent
3b89a499d0
commit
a7b298889a
1 changed files with 4 additions and 3 deletions
|
|
@ -86,8 +86,6 @@ class PicameraStreamOutput(Output):
|
||||||
Output.__init__(self)
|
Output.__init__(self)
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
self.encoder = encoder
|
self.encoder = encoder
|
||||||
# The difference between unix time and the CPU time
|
|
||||||
self.cpu_dt = time.time() - time.monotonic()
|
|
||||||
|
|
||||||
def outputframe(
|
def outputframe(
|
||||||
self,
|
self,
|
||||||
|
|
@ -101,10 +99,13 @@ class PicameraStreamOutput(Output):
|
||||||
if timestamp is None or self.encoder.firsttimestamp is None:
|
if timestamp is None or self.encoder.firsttimestamp is None:
|
||||||
frame_timestamp = None
|
frame_timestamp = None
|
||||||
else:
|
else:
|
||||||
|
# The difference between unix time and the CPU time. Do not cache this
|
||||||
|
# number as it can change with clock slew or other time adjustments.
|
||||||
|
cpu_dt = time.time() - time.monotonic()
|
||||||
# Reconstruct full CPU time of the frame in us
|
# Reconstruct full CPU time of the frame in us
|
||||||
timestamp += self.encoder.firsttimestamp
|
timestamp += self.encoder.firsttimestamp
|
||||||
# Convert to datetime
|
# Convert to datetime
|
||||||
frame_timestamp = datetime.fromtimestamp(self.cpu_dt + timestamp / 1e6)
|
frame_timestamp = datetime.fromtimestamp(cpu_dt + timestamp / 1e6)
|
||||||
self.stream.add_frame(frame, frame_timestamp)
|
self.stream.add_frame(frame, frame_timestamp)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue