Skip to content

Question about possible Raspberry Pi Picamera2 integration #4

Answered by janakj
askpatrickw asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Patrick,

Unfortunately, I don't have any practical experience with picamera2. I am assuming you want to implement a streaming MJPEG server. The key step is to define a Python function to yield frames, for example:

def picamera2_reader():
    while True:
        frame = ... # do something to get a frame from picamera2
        yield frame

The yielded value is binary JPEG data, i.e., one frame. The type of the value must be either bytes or memoryview. The py-mjpeg library prepends the necessary HTTP headers and writes the binary data to the socket as payload. The Flask server will call the picamera2_reader() function repeatedly until the client closes the connection, or until the function…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by janakj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants