A Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV that was origionally established as a tiny and affordable computer for kids.
The Raspberry Pi has thousands of different uses, one of which is streaming directly to Ustream. You can use your Pi as a security or nature camera. This could be a good alternative to an IP camera. This will only support video streaming, NOT audio.
To do this, you will need:
- Raspberry Pi (B+)
- Raspberry Pi camera module (learn how to connect camera module here)
- Micro USB charger
- Micro SD card
- Micro SD card adapter
- Edimax EW-781 Wifi Dongle
- HDMI cord
- Ethernet cord
- Monitor with HDMI input
Installation and camera set up
First, you will want to install NOOBS, which is the Raspberry Pi operating system. You can download NOOBS here. Once you download NOOBS, you will want to copy it to your micro SD card. Once you've done this, insert the micro SD into your Pi.
Plug in your keyboard, mouse, monitor, ethernet cord and finally your power cable. Your Pi should boot, and a window will appear with a list of different operating systems you can install. Check the box next to Raspbian and click on Install. This will run through the installation process. Once the installation process has completed, the Pi configuration menu (raspi-config) will load.
Now you want to enable the camera module. To do this, select "Enable Camera". In order to use the Raspberry Pi camera module, you must enable it here. Select the option and proceed to
Enable. This will make sure at least 128MB of RAM is dedicated to the GPU. You can exit this menu by using Tab on your keyboard to move to
The default login for Raspbian is username
pi with the password
raspberry.Note you will not see any writing appear when you type the password. This is a security feature in Linux.
For more information about how to run commands using the Raspberry Pi, please see the following link here.
Setting up Wifi
There are various Wifi products you can use with the Pi, but I recommend the Edimax. First, make sure the Edimax is connected to your Pi. Also, make sure you have connected your ethernet cord to your Pi with an active
After booting and logging-in you want to make sure the Raspberry Pi found your new wireless adapter. To look at your Pi's peripherals, run the following command:
Towards the end of the lines, you should see something like this:
[ 3.282651] usb 1-1.2: new high-speed USB device number 4 using dwc_otg [ 3.394810] usb 1-1.2: New USB device found, idVendor=7392, idProduct=7811 [ 3.407489] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 3.420530] usb 1-1.2: Product: 802.11n WLAN Adapter
This means that the operating system recognized the USB WiFi Adapter using one of the built-in drivers (you can return to the terminal by pressing “q”). All that is left is to configure your WiFi connection.
On the Raspberry Pi (and on Linux in general) you configure your network settings in the file “/etc/network/interfaces”. You can edit this file using the following command:
sudo nano /etc/network/interfaces
This will open up the file in an editor called nano, which is a simple text editor. To configure your specific wireless network, you want to change this file to look like the following:
auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 auto wlan0 iface wlan0 inet dhcp wpa-ssid "Your Network SSID" wpa-psk "Your Password"
You will need to put your own SSID and password in the appropriate places. After you make the changes, press Ctrl O to Save and Ctrl X to exit.
Everything is now configured. Now you will have to reload the network interfaces (Warning: if you are connected using a remote connection it will disconnect now). To do this, run the following command:
sudo service networking reload
You can now check the status of your Wifi connection by running the following command:
The results should look something like this:
wlan0 Link encap:Ethernet HWaddr 80:1f:02:aa:12:58 inet addr:192.168.1.8 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:154 errors:0 dropped:173 overruns:0 frame:0 TX packets:65 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:32399 (31.6 KiB) TX bytes:13036 (12.7 KiB)
If you see a valid IP address under “inet addr” you can now disconnect the network cable- you are connected!
Installing FFmpeg streaming services
First, you will need to install FFmpeg on the Raspberry Pi which will continually stream video data from the camera board to the web.
NOTE: This process will take about 2 hours
Enter the following commands to download, compile and install FFmpeg:
cd /usr/src sudo mkdir ffmpeg sudo chown pi:users ffmpeg git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg cd ffmpeg
The next command will take a while to run. After inserting the following command, please be patient!
Once you see the command prompt reappear, type the following command:
Finally, insert the last command:
sudo make install
Ustream RTMP URL and Stream Key
You will now need to fetch the RTMP URL and Stream Key from the specific channel you would like to broadcast from. For instructions on how to find your RTMP URL and Stream Key, please see the following article here: How to find RTMP URL and Stream Key.
Now, we will create a small shell script with a loop. On the Raspberry Pi enter the following command:
Now copy and paste the following code:
#!/bin/bash RTMP_URL=<rtmpurl> STREAM_KEY=<streamkey> while : do raspivid -n -vf -hf -t 0 -w 960 -h 540 -fps 25 -b 500000 -o - | ffmpeg -i - -vcodec copy -an -metadata title="Streaming from raspberry pi camera" -f flv $RTMP_URL/$STREAM_KEY sleep 2 done
Now replace and with the corresponding values from your own Ustream channel. Do NOT include the brackets at the beginning and end of the RTMP URL and Stream Key.
Press Ctrl + O then Enter to save and Ctrl + X to quit. Enter the following comand to make the shell script executable:
chmod +x ~/ustream
Now anytime you want to begin streaming, use the following command:
When you want to shut the stream down, type Ctrl +C.