Use us not ns for picamera timestamp and fix descriptor typing
This commit is contained in:
parent
f85361ae67
commit
7ba2c03f61
2 changed files with 17 additions and 6 deletions
|
|
@ -16,7 +16,7 @@ from abc import ABC, abstractmethod
|
|||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from types import TracebackType
|
||||
from typing import Any, Literal, Mapping, Optional, Self
|
||||
from typing import Any, Literal, Mapping, Optional, Self, Union, overload
|
||||
|
||||
import numpy as np
|
||||
import piexif
|
||||
|
|
@ -223,7 +223,7 @@ class MJPEGStreamWithTimestamp(lt.outputs.MJPEGStream):
|
|||
rather than take the time it is added into the ring buffer.
|
||||
"""
|
||||
|
||||
def add_frame(self, frame: bytes, timestamp: Optional[datetime]) -> None:
|
||||
def add_frame(self, frame: bytes, timestamp: Optional[datetime] = None) -> None:
|
||||
"""Add a JPEG to the MJPEG stream.
|
||||
|
||||
Modify the standard function to have an option to send in the capture time.
|
||||
|
|
@ -250,12 +250,23 @@ class MJPEGStreamWithTimestamp(lt.outputs.MJPEGStream):
|
|||
self.notify_new_frame, entry.index
|
||||
)
|
||||
|
||||
|
||||
class MJPEGStreamDescriptorWithTimestamp(lt.outputs.MJPEGStreamDescriptor):
|
||||
"""Subclass the Labthings descriptor to return our own class."""
|
||||
|
||||
@overload
|
||||
def __get__(self, obj: Literal[None], type: type | None = None) -> Self: ...
|
||||
|
||||
@overload
|
||||
def __get__(
|
||||
self, obj: Optional[lt.Thing], type: type[lt.Thing] | None = None # noqa: A002
|
||||
) -> MJPEGStreamWithTimestamp | Self:
|
||||
self, obj: lt.Thing, type: type | None = None
|
||||
) -> MJPEGStreamWithTimestamp: ...
|
||||
|
||||
def __get__(
|
||||
self,
|
||||
obj: Optional[lt.Thing],
|
||||
type: type[lt.Thing] | None = None, # noqa: A002
|
||||
) -> Union[MJPEGStreamWithTimestamp | Self]:
|
||||
"""Return our own MJPEG Stream with timestamp."""
|
||||
if obj is None:
|
||||
return self
|
||||
|
|
|
|||
|
|
@ -101,10 +101,10 @@ class PicameraStreamOutput(Output):
|
|||
if timestamp is None or self.encoder.firsttimestamp is None:
|
||||
frame_timestamp = None
|
||||
else:
|
||||
# Reconstruct full CPU time of the frame in ns
|
||||
# Reconstruct full CPU time of the frame in us
|
||||
timestamp += self.encoder.firsttimestamp
|
||||
# Convert to datetime
|
||||
frame_timestamp = datetime.fromtimestamp(self.cpu_dt + timestamp / 1e9)
|
||||
frame_timestamp = datetime.fromtimestamp(self.cpu_dt + timestamp / 1e6)
|
||||
self.stream.add_frame(frame, frame_timestamp)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue