Build Python App for Raspberry Pi Live Streaming video from Camera to Server
Setup and create app for RaspberryPi 3, pi Zero w stream video from camera to the server use Python Language.
See this post
I recommend use Pycharm really cool for you and for me. Just donwload community version it’s free https://www.jetbrains.com/pycharm/download
When we deploy the app to Raspberry Pi we don’t have to install Python because it enabled by default MacOs & on Raspberry Pi devices. (Pi 3, Pi Zero W…) Download and install Python here https://www.python.org/downloads/
We use Pip to manage all python packages, so to setup Pip just follow this https://pip.pypa.io/en/latest/installing/ For Ubuntu or other linux i recommend follow this doc: https://packaging.python.org/guides/installing-using-linux-tools/#installing-pip-setuptools-wheel-with-linux-package-managers
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
autobahn-python is good library we will use for Websocket Client in this project https://github.com/crossbario/autobahn-python so our RaspberryPi will connect to websocket server as client. and we may control it to capture video/picture or stop any time. we can check it status is connected to internet or offline.
pip install autobahn[twisted]
On MacOs if you are getting an error after running that command use following command
pip install autobahn[twisted] --user
autobahn,twisted,subprocess
Sample code use subprocess
cmd = 'ffmpeg -re -i /Users/toan/Tutorials/stream/video.mkv -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://localhost/live/tabvn'subprocess.call(cmd, shell=True)
OR use Popen
cmd = 'ffmpeg -re -i /Users/toan/Tutorials/stream/video.mkv -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://localhost/live/tabvn'streaming_process = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE)
Watch Video: https://www.youtube.com/watch?v=cV8uwjV4kaE