Skip to content
/ pi_h264 Public
forked from devalexqt/pi_h264

Live streaming from Raspberry Pi using H.264 (tweaked for FRC)

Notifications You must be signed in to change notification settings

Ernie3/pi_h264

 
 

Repository files navigation

Live streaming from Raspberry Pi using H.264

Note: This has only been tested on Raspbian Stretch.

Prerequisites

  1. Node.js
  2. FFmpeg v3.3 or greater (FYI, this has only been tested with v3.3.9)
  3. a USB Camera

Help Installing Node.js v14 on the Pi

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v

Help Installing FFMPEG v3.3 on the Pi

# Add deb-multimedia
sudo sed -i '$a deb http://www.deb-multimedia.org stretch main non-free' /etc/apt/sources.list
wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2016.8.1_all.deb
sudo dpkg -i deb-multimedia-keyring_2016.8.1_all.deb
rm deb-multimedia-keyring_2016.8.1_all.deb
sudo apt-get update

sudo apt-get install -y ffmpeg # run this if you don't have ffmpeg installed 
sudo apt-get install --only-upgrade -y ffmpeg # run this if you already have ffmpeg installed

ffmpeg -version

Installing pi_h264

git clone https://github.com/Ernie3/pi_h264.git
cd pi_h264
npm install
npm start

Open http://your-raspberry-pi's-ip:5800 to view the stream.

Configuration

See config.json.

Controlling Camera Settings

The stream viewer offers a panel to control the camera's settings. However, to utilize this capability, you must have the v4l2-ctl-rest-api installed and running on the Pi. Edit the Camera ID in www/index.html to match the camera you're using (0 for /dev/video0 for instance).

Setting up pi_h264 to Run on Boot

./service_manager.sh argument

install - installs pi_h264 service and enables start on boot
start - starts pi_h264 via systemctl (service must be installed)
stop - stops pi_h264 via systemctl (service must be installed)
enable - enables pi_h264 to start on boot (service must be installed)
disable - disables pi_h264 from starting on boot (service must be installed)
uninstall - completely removes pi_h264 service from systemctl

How to use by-path (by USB port)

Template

Top Left USB | Top Right USB
----------------------------
Bot Left USB | Bot Right USB

For Raspberry Pi Model B+

/dev/v4l/by-path/platform-3f980000.usb-usb-0:1.1.2:1.0-video-index0 | /dev/v4l/by-path/platform-3f980000.usb-usb-0:1.3:1.0-video-index0
-----------------------------------------------------------------------------------------------------
/dev/v4l/by-path/platform-3f980000.usb-usb-0:1.1.3:1.0-video-index0 | /dev/v4l/by-path/platform-3f980000.usb-usb-0:1.2:1.0-video-index0

Technical Description

The client (web browser) uses broadway (h264 software decoder) to decode NAL h264 packets and rendering the decoded frames to the html canvas. For receiving NAL h264 baseline packets from the server (Raspberry Pi), the client uses a websocket using socket.io. On the server, it uses the specified USB camera to get NAL baseline h264 packets from ffmpeg and sends it over the websocket to the client.

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.6%
  • HTML 13.0%
  • Shell 4.4%