/
simplestream

Zeisberg GmbH

simplestream

simplestream is showcasing the streaming of video frames from the camera to a host via http multipart/x-mixed-replace stream.

From the cloned project folder (see Getting started):

Open a browser on the host computer that is connected to Merlin’s access point and navigate to http://192.168.50.1:55553/stream

screenshot_browser.jpg

The browser will show the live video stream from the camera. Controls for focus, IR-LEDs as well as image processing (cropping, mirroring, …) will be added in other examples. Please find below a brief introduction to this examples code.

Packages used

Apart from standard library packages, we’ve used

func main ()

main()

  • line 62 opens the device /dev/video0 which is closed when the app terminates.

  • line 69 reads the pixel format of the device and stores width and height globally. See Components of interest for details on the sensor. Note the difference between the image width (720) and the number of bytes per line (736) for this sensor. Each line is padded with two empty bytes and we have to work with the actual data size of 736 x 540 pixels. The sensor is set to deliver 8 Bit values per pixel by default, so each byte in gthe frame represents one pixel.

  • line 80 starts the cam

  • line 86 stores the channel fro reading frames from the video device in a global variable

  • line 90 adds func frameSrv() as handler for the http endpoint /stream to the default http multiplexer

  • line 91 starts listening on port 55553 for incoming resource requests. It will start a new frameSrv-Handler as go routine for each incoming request.

func frameSrv(w http.ResponseWriter, r *http.Request)

frameSrv is a http handler that serves requests for the resource /stream on Merlins port 55553.

It first creates a HTTP multipart/x-mixed-replace keep-alive stream and sets it’s content type to image/jpeg. Each camera frame is sent as jpeg to the http.ResponseWriter of this connection.

  • line 40 create a buffer an image struct used to convert the frame to jpeg.

  • line 43 is a loop that waits for a new frame from the video device. Each frame is received right into the buffer of previously created image.

    • line 44 creates a new partWriter for the multipartWriter

    • line 55 encodes the image as jpeg into the partWriter

 

Connection details

 

image-20241227-181614.png

 

Related content

GET / PUT cameraexposure
GET / PUT cameraexposure
More like this
GET / PUT frenzel_state
GET / PUT frenzel_state
More like this
GET frenzel_video
GET frenzel_video
More like this

Gutenbergstrasse 39 * 72555 Metzingen

Achtung: Ausgedruckte gelenkte Dokumente sind nicht gültig!
Die gültige Fassung ist in Confluence abrufbar.