MJPEG stream test (using Flask) - MAKLab/Moons-of-MAKLab GitHub Wiki

This test is based onthis blog entry, and ultimately turned out really well. As a result I think we should try and build something similar, perhaps without Flask, and if that fails we can always fall back to this.

Installation instructions

  1. We need git, Flask, pip (to get Flask) and the raspberry pi camera drivers if we don't already have them:

    sudo apt-get update

    sudo apt-get install git python-pip python-picamera

    sudo pip install flask

  2. Configure your Pi to work with the camera, if you've not already done so. Run sudo raspi-config and choose in the menu to enable the camera module. Restart the Pi when prompted;

  3. Get the example code:

    git clone https://github.com/miguelgrinberg/flask-video-streaming.git

  4. Modify app.py to use the Pi camera module instead of the example images. Comment out line 5 and uncomment line 8:

    from camera_pi import Camera

  5. Modify camera_pi.py to give us a bigger image that is the correct orientation. Change lines 31 - 33 to the following:

    camera.resolution = (640,480)
    

camera.hflip = False camera.vflip = False 6. Run the example: python app.py

  1. If you are working on your Pi, open a browser at 127.0.0.1:5000, otherwise browse to your Pi's IP address, port 5000.

Notes

  • This seems to work really well over both my internal network (wired) and also over 3G from my mobile. However, I was using a Raspberry Pi 3.
  • It is limited to a single connection at a time, and this connection is only closed if it is shut down by the browser. So killing the example with Ctrl+C doesn't stop the camera or stream, and trying to run the script again fails.
⚠️ **GitHub.com Fallback** ⚠️