Publish or capture VDO.Ninja streams with Python (Raspberry Pi, Linux, Mac, Windows WSL)
Publish or capture VDO.Ninja streams with Python (Raspberry Pi, Linux, Mac, Windows WSL)
Turn your Raspberry Pi, Nvidia Jetson, Orange Pi, Windows PC, Mac, Linux box, or nearly any Python-compatible system into a ninja-cam with hardware-acceleration enabled! This lets you publish live streaming video and audio directly to your web browser or OBS instance using VDO.Ninja. Achieve very low streaming latency over the Internet or a LAN; all for free.
New to Raspberry Pi? Use the short Quick start. It can set up a camera sender or unattended TV receiver without choosing codecs or writing a service file.
It also has the ability to record remote VDO.Ninja streams to disk (no transcode step), record multiple room participants simultaneously, broadcast a low-latency video stream to multiple viewers (with a built-in SFU), and because it works with VDO.Ninja, you get access to its ecosystem and related features. There are other cool things available, such as AV1 support, NDI output, OpenCV output, WHIP, HLS recording, fdsink output, and V4L2 sink output for virtual cameras.
Table of Contents
record.py
The core concepts and code used in this project can be reused for other projects; most Linux systems, and a large variety of embedded systems; potentially even smartphones. There's a focus of supporting Raspberry Pis and Nvidia Jetson systems, which includes offering pre-built images and install scripts. Other Linux system users should still be able to use the code, but setup support will be limited.
Youtube video demoing: https://youtu.be/J0qqXxHNU_c
I also have another longer YouTube video here, which focuses on setting up the Raspberry_ninja for IRL-streaming.**** Recent updates to Raspberry Ninja have added improved error correction and video redundency, along with automated dynamic bitrate controls for congestion management. This has greatly improved stream reliabilty, reducing frame loss, and limiting buffer sizes. That said, having more than 5-megabites of upload bandwidth and having a solid connection is recommend if intending to use the default settings.
For the easiest installation experience, use our universal installer that works across all platforms.
For a quick, basic installation that only installs dependencies:
curl -sSL https://raw.githubusercontent.com/steveseguin/raspberry_ninja/main/install.sh | bashNote: This method runs in non-interactive mode and will:
~/raspberry_ninja if not foundAfter installation, you'll need to:
cd ~/raspberry_ninja
python3 publish.py --helpFor the complete setup experience with configuration and auto-start options:
Option 1: If you haven't cloned the repository yet:
wget https://raw.githubusercontent.com/steveseguin/raspberry_ninja/main/install.sh
chmod +x install.sh
./install.shThe installer will clone the repository for you if needed.
Option 2: If you've already cloned the repository:
cd raspberry_ninja
./install.shThe interactive installer will:
Tip: You can also force non-interactive mode with the downloaded script:
./install.sh --non-interactive
# or
./install.sh -ySee below for platform-specific install options if you prefer manual installation.
See the raspberry_pi sub-folder for instructions on installing and setting up a Raspberry Pi. Jump there now
Raspberry Pi performance depends on the board, OS, camera stack, GStreamer build, and media device. Pi 3/4 hardware encoding, Pi 5 software encoding, USB capture, and CSI camera paths are not interchangeable. Start with the platform compatibility guide, then test the actual source and encoder at conservative settings before increasing resolution or frame rate.
Please see the installers/nvidia_jetson folder for details on installation. Jump there now
If you are using one of the pre-built Jetson images, you usually only need the lightweight helper script:
cd ~/raspberry_ninja/installers/nvidia_jetson
./quick_update.shOnly use installer.sh when building a new image from scratch; it performs
heavy package clean-up and distro upgrades that are unnecessary on top of the
ready-made images.
Nvidia Jetsons work well with USB-connected cameras and have a selection of compatible CSI-cameras well. You may need to buy WiFi adapter if it is not included.
You can deploy Raspberry.Ninja to a desktop pretty quickly in most cases, without compiling anything. An installer is available for recent Ubuntu releases. Jump there now
For other distros, see below for requirements
You'll want to install Gstreamer 1.16 or newer; emphasis on the newer. You'll need to ensure libnice, srtp, sctp, and webrtcbin are part of that install, along with any media codecs you intend to use.
Python3 is also required, along with websockets. If you have PIP installed, pip3 install websockets can get you going there.
You can actually run Raspberry Ninja on a Windows PC via the WSL virtual machine interface. It's really quick and simple, except getting camera/hardware support going is tricky.
Still, it might be useful if you want to pull a stream from a remote Raspberry.Ninja system, recording the stream to disk or using it for local machine learning.
See the WSL install guide here: Jump there now
It is possible to install Gstreamer for Windows natively, but due to the difficultly in that all, I'm not supporting it officially at present. The main challenge is cairo fails to compile, so that needs to be fixed first.
Raspberry.Ninja can even run on a Mac! Although it's not as streamlined a process as it could be, I'd say the difficulty is 4/10.
See the macOS install notes here: Jump there now
Many modern versions of Linux distributions, such as Ubuntu 22, support Raspberry.Ninja with minimal installation effort.
The basic install script for Ubuntu-like systems is as below:
…Package managers with old versions of Gstreamers, or with no hardware acceleration or limited codec support, may be limited in what Raspberry.Ninja can offer. For the most up-to-date and comprehensive feature set, compiling Gstreamer from scratch may be still needed.
If wanting to use AV1 streaming, you'll need to install gst-plugins-rs as well (av1parse and av1pay are needed), plus whatever AV1 encoder you wish to use.
Major updates sometimes will require that the latest Rasbperry Pi or Jetson image be installed on your device, but most updates are minor and only require the publish.py file to be updated. If you've just installed the latest device image, you will still want to update before going further, as the image is not updated with every new code release.
You can normally update by logging into your device, either via SSH, or via mouse/keyboard with the terminal app open.
cd ~
cd raspberry_ninja
git pullThat's it.
If you run into issues due making changes to the code, you can either git stash your changes first, or you can just delete the raspberry_ninja folder and clone it again.
ie:
cd ~
rm raspberry_ninja -r
git clone https://githuNo open issues yet, or sync has not completed.