dans98 / pi-h264-to-browser

A Python application designed to stream hardware encoded h.264 from a Raspberry Pi directly to a browser.
Apache License 2.0
63 stars 18 forks source link

Create a version that works with Picamera2 #10

Closed woutersf closed 1 year ago

woutersf commented 1 year ago

I attempted to run this on my Raspberry pi 4 with Picamera2 and coultn't get it to work. the picamera2 docs only have a mjpeg server example and a seperate H264 quantiser example

Is there another branch/version of this repo where this works with picamera2 ?

I suspect the changes are something like the following however I don't speak python fluently.

To be added:

from picamera2 import Picamera2
from picamera2.encoders import H264Encoder
from picamera2.outputs import CircularOutput  # (or FileOutput?)

and then the camera references should be removed or replaced by picam2 where picam2 iis intialised and starts streaming.

Also in the try:

    picam2 = Picamera2()
    fps = 30
    dur = 5
    micro = int((1 / fps) * 1000000)
    vconfig = picam2.create_video_configuration()
    vconfig['controls']['FrameDurationLimits'] = (micro, micro)
    picam2.configure(vconfig)
    encoder = H264Encoder()
    output = CircularOutput(buffersize=int(fps * (dur + 0.2)), outputtofile=False)
    output.fileoutput = "file.h264"
    picam2.start_recording(encoder, output)
    application = tornado.web.Application(requestHandlers)
    application.listen(serverPort)
    streamBuffer.setLoop(loop)
    loop.start()

If anyone has any hints on getting this to work, I'm willing to give it some attempts but it's not familiar to me, I would need some guidance.