Added frame iterator explanation comment

This commit is contained in:
Joel Collins 2020-11-16 10:14:54 +00:00
parent f51d4ff200
commit 90ccd0bc4e

View file

@ -565,15 +565,20 @@ class PiCameraStreamer(BaseCamera):
# While the iterator is not closed # While the iterator is not closed
try: try:
while True: while True:
# reset stream for next frame # Reset the stream for the next frame
self.stream.seek(0) self.stream.seek(0)
self.stream.truncate() self.stream.truncate()
# to stream, read the new frame # Sleep for the approximate camera framerate
time.sleep(1 / self.camera.framerate * 0.1) time.sleep(1 / self.camera.framerate * 0.1)
# yield the result to be read # Get the latest frame data from the stream
frame = self.stream.getvalue() frame = self.stream.getvalue()
# ensure the size of package is right # This loop iterates faster than the PiCamera will collect
# frames. On iterations between frames, the buffer will be
# empty (because we truncated it earlier). In these cases
# we just pass and loop again until a frame is actually present.
# This also means that the size of FrameStream is always 1 frame,
# since we truncate it here before a new frame can be appended.
if len(frame) == 0: if len(frame) == 0:
pass pass
else: else: