Live Streaming in Raspberry Pi :Step by step guide

 

Live Streaming in Raspberry Pi


Hardware Requirements:

  • Raspberry pi model 4
  • Micro SD card (min 32GB)
  • USB webcam (720p or high)
  • Power adapter with type-c cable.

Software Requirements:

  • Latest raspbian software 
  • Balena etcher or Raspberry pi imager
  • Pi Motion Library



 

Installing Motion Library


STEP 1:

  • $ sudo apt-get update
  • $ sudo apt-get upgrade
  • $ sudo apt-get install motion
  • $ sudo raspi-config 

( Enable camera)

(reboot)



STEP 2:

  • $ sudo modprobe bcm2835-v4l2

( command to add video driver module)

  • $ sudo nano /etc/motion/motion.conf

(open the motion configuration file)

  • daemon on (Make daemon on from off)
  • stream_localhost off (set stream_localhost to off from on)
  • stream_maxrate 90 (set above 90)
  • framerate 50 (set above 70 for smooth fps)
  • width 640 (set according to the requirement)
  • height 480 (set according to the requirement)

( ctrl + X to exit and enter “Y” to save)

 

 

 

STEP 3:

  • sudo nano /etc/default/motion (open daemon file)
  • Start_motion_daemon = yes (set to yes)

( ctrl + X to exit and enter “Y” to save)

  • sudo service motion start ( to start the motion service)
  • Now the camera stream is hosted in the localhost in port 8080
  •  ( edit motion.conf file to change the port if required)
  • Get the IP address of the pi by “ifconfig” command.
  • Open the browser and enter IP along with the port.
  •  (eg: http://192.168.11.123:8081 )
  • You will get the live stream in the browser. 

Useful commands:

  • sudo service motion status    
  •                          ( Checking whether motion is running or not)
  • sudo service motion start ( starting the motion service)
  • sudo service motion stop ( terminating the motion service)
  • sudo service motion restart (restarting the motion service)

 

 

FAQ’s

  1. How to get streaming of multiple cameras connected to the
    same device?

Ans: Specify different port numbers in the motion configuration file under  

stream_port = port number (sudo nano /etc/motion/motion.conf) 

eg. 8080,8081,8082)

  1. How to check the list of connected USB devices and cameras ?

Ans: open the terminal and type “lsusb” to get the list of connected 

USB devices in Linux.

  1. How to stream the live video within and outside the network?

Ans: use ngrok service for video tunneling. ( https://ngrok.com/