Skip to content

Allow the timestamp for a frame to be supplied to the MJPEGStream.#387

Open
julianstirling wants to merge 2 commits into
mainfrom
mjpeg-timestamp
Open

Allow the timestamp for a frame to be supplied to the MJPEGStream.#387
julianstirling wants to merge 2 commits into
mainfrom
mjpeg-timestamp

Conversation

@julianstirling

Copy link
Copy Markdown
Contributor

Cameras can report their capture timestamp. This allows add_frame to accept the timestamp (and fallback to datetime.now()) if no timestamp is supplied.

This allows for more accurate timestamps for the frame which is useful if the frametime needs to be known relative to anothe event.

Cameras can report their capture timestamp. This allows add_frame
to accept the timestamp (and fallback to datetime.now()) if no
timestamp is supplied.

This allows for more accurate timestamps for the frame which is
useful if the frametime needs to be known relative to anothe event.
Comment thread src/labthings_fastapi/outputs/mjpeg_stream.py Outdated
Comment thread src/labthings_fastapi/outputs/mjpeg_stream.py Outdated
Comment thread src/labthings_fastapi/outputs/mjpeg_stream.py Outdated
Co-authored-by: Beth <167304066+bprobert97@users.noreply.github.com>
Co-authored-by: Julian Stirling <julian@julianstirling.co.uk>
@barecheck

barecheck Bot commented Jul 11, 2026

Copy link
Copy Markdown

Barecheck - Code coverage report

Total: 97.31%

Your code coverage diff: 0.00% ▴

Uncovered files and lines
FileLines
src/labthings_fastapi/outputs/mjpeg_stream.py197, 199, 202, 205, 233-235, 244-246, 266, 270-271, 308, 336, 412, 448

@bprobert97 bprobert97 requested a review from rwb27 July 14, 2026 20:10
@bprobert97

Copy link
Copy Markdown
Contributor

Want review from @rwb27 before merging

@rwb27 rwb27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, and something I've intended to add since realising that the camera timestamp is passed through the pi camera's encoder.

return MJPEGStreamResponse(self.frame_async_generator())

def add_frame(self, frame: bytes) -> None:
def add_frame(self, frame: bytes, timestamp: Optional[datetime] = None) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have favoured datetime | None but let's not worry about it until there's a linter rule to enforce consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants