Skip to content

Instantly share code, notes, and snippets.

@MartinHarding
Last active January 6, 2019 23:29
Show Gist options
  • Save MartinHarding/b3c31cf93ed581f6be2519f9957c3f7c to your computer and use it in GitHub Desktop.
Save MartinHarding/b3c31cf93ed581f6be2519f9957c3f7c to your computer and use it in GitHub Desktop.
Quickly setup a basic video stream from a Raspberry Pi and Pi Camera module
#/bin/bash
# Sets up Miguel Grinberg's excellent Flask video streaming example to automatically start on boot using the PiCamera
# Run script without downloading (must be logged into Raspberry Pi):
# curl -s https://gist.githubusercontent.com/martinharding/b3c31cf93ed581f6be2519f9957c3f7c/raw/picamera-streamer.sh -o picamera-streamer.sh && chmod +x picamera-streamer.sh && ./picamera-streamer.sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# First install!
if ! [ -d $DIR/flask-video-streaming ]; then
# Update packages
sudo apt-get update
sudo apt-get upgrade -y
# Install flask video streaming app
sudo apt-get install -y python3-pip git
git clone https://github.com/miguelgrinberg/flask-video-streaming.git $DIR/flask-video-streaming
cd $DIR/flask-video-streaming
pip3 install -r requirements.txt
pip3 install picamera
# Run server script on boot
echo "[Unit]
Description=Stream PiCamera to web
After=multi-user.target
[Service]
ExecStart=/bin/bash $DIR/picamera_streamer.sh
User=${whoami}
Group=${whoami}
Type=simple
[Install]
WantedBy=multi-user.target
" > $DIR/video-stream.service
sudo mv $DIR/video-stream.service /lib/systemd/system/video-stream.service
sudo chmod 644 /lib/systemd/system/video-stream.service
sudo systemctl daemon-reload
sudo systemctl enable video-stream.service
# Enable camera
sudo raspi-config nonint do_camera 1
echo "Please reboot (you can use the command 'sudo reboot now' to do this remotely)"
else
# sudo systemctl status video-stream.service
CAMERA=pi python3 $DIR/flask-video-streaming/app.py >> log.txt 2>&1 &
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment