Live Video Stream with RTMP NGINX FFMPEG AVCONV on Raspberry Pi 2 with a WebCAM

20141206_214144

In this tutorial a Raspberry Pi would be configured to transmit live video stream using NGINx, RTMP module, FFMPEG, AVCONV. The tutorial assume

Summary of technology stack:

  • Hardware: Raspberry Pi 2 with Raspbian Jessie
  • Video Hardware : WebCam that works with Raspberry. This tutorial is using Logitech WebCam Pro 9000
  • Media Server:   Use NGINX with RTMP module as media server.
  • Video Source: Capture webcam using ffmpeg and transmit the feed to rtmp server
  • Video Software : AVCONC a.k.a. FFMPEG

Install RTMP NGINX

Install Nginx on raspberry pi according to this wonderful post

Logon to Raspberry Pi. This tutorial is using Putty from a Windows box to log in to Raspberry. Execute the following command on command console to in preparation for Nginx building.

$ sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

Download latest version of Nginx. As of this writing 1.9.6 is the latest. Execute the following comand to download.

$ wget http://nginx.org/download/nginx-1.9.6.tar.gz 

Download nginx rtmp module

$ wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

Unpack both nginx and rtmp module to same directory.

$ tar -zxvf nginx-1.9.5.tar.gz

$ unzip master.zip

Change directory to nginx folder.

$ cd nginx-1.9.5

Now we build nginx executing the following.

$ ./configure –with-http_ssl_module –add-module=../nginx-rtmp-module-master

$ make

$ sudo make install

run nginx

$ sudo /usr/local/nginx/sbin/nginx

Test using a browser pointing to Raspberry Pi’s ip address.

Configuring nginx to use RTMP

Configuring NGINX to use RTMP

Open your config file, located by default at /usr/local/nginx/conf/nginx.conf and add the following at the very end of the file:

rtmp {
	server {
		listen 1935;
		application live {
			live on;
			meta copy;
		}
	}
}

 

You can start stop nginx using the following commands.

$ sudo /usr/local/nginx/sbin/nginx -s stop

$ sudo /usr/local/nginx/sbin/nginx

Capture Webcam Video with FFMPEG AVCONV

Now we need to capture video from our webcam and transmit to Nginx’s rtmp module which in turn will stream it to an Video player that are able to display RTMP stream.

For video capture we would use FFMPEG. Raspberry Pi by default comes with install module called AVCONV which is a fork of FFMPEG. If you like to use FFMPEG on Raspberry Pi Raspbian you would have to compile it. For simplicity we would use AVCONV in this tutorial.

Install aconv

$ sudo apt-get install libavcodec-extra

$ sudo apt-get install libav-tools (for avconv)

Now we will need to find webcam id so that we can use the id in our ffmpeg script. Check for usbcam with video4linux2 utility v4l2-ctl to find out device id (i.e. /dev/video0)

$ v4l2-ctl –list-devices

Start streaming

A basic streaming parameters are shown bellow. The following command should transmit a RTMP video steram to nginx’s rtmp module. Make sure your NGINx is running.

$ avconv -f video4linux2 -r 25 -s 640×480 -i /dev/video0 -f flv rtmp://localhost/live/

Test using VLC

Use VLC from your Windows box to test. Use VLC’s “Open Network Stream” with

rtmp://<your raspberry pi’s IP>/live

(i.e. rtmp://192.168.11.111/live)

You should be able to view live stream from your web cam now.

7 Comments

  1. Hitesh April 12, 2016 Reply
    • 13ike July 5, 2016 Reply
      • 13ike July 5, 2016 Reply
  2. ivaylo July 23, 2016 Reply
  3. o September 30, 2016 Reply
  4. Mark October 12, 2016 Reply
  5. Anna October 12, 2016 Reply

Add a Comment

Your email address will not be published. Required fields are marked *