Python WebSocket Client Connect to Node.js WebSocket Server µWebSocket
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.
Setup Server for Live Video Streaming
See this post
Tool for development Python
I recommend use Pycharm really cool for you and for me. Just donwload community version it’s free https://www.jetbrains.com/pycharm/download
Setup Python on Development Enviroment
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/
Setup Pip (Python Package Index)
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.pysudo python get-pip.py
Websocket client library
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
Python Libraries we will use
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)
Sample Python App for Websocket client
Watch Video: https://www.youtube.com/watch?v=cV8uwjV4kaE