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

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

Setup Pip (Python Package Index)

We use Pip to manage all python packages, so to setup Pip just follow this For Ubuntu or other linux i recommend follow this doc:

curl -o
sudo python

Websocket client library

autobahn-python is good library we will use for Websocket Client in this project 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


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', 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:

More by Toan Nguyen Dinh

Topics of interest

More Related Stories