The Raspberry Pi is a credit-card sized $35 computer that can be used to accomplish many tasks similar to what a desktop PC can do. This includes spreadsheets, word-processing, games, and even…live video broadcasting! By connecting a powered USB Hub and webcam to your Raspberry Pi, you can broadcast live video to an unlimited audience for free. I’ll show you how this is possible.
Please be patient and read through the entire tutorial before attempting.
What You NeedCredit: Wikipedia.org
Getting started requires a few peripherals. To start up your Raspberry Pi and do initial configuration, you will need an HDMI cable, USB keyboard, and USB mouse. In addition:
  • A Raspberry Pi Model B running Debian or “Rasbian”
  • A powered USB hub
  • A Debian-supported webcam (Logitech HD C series) – I use the Logitech HD V-U0016 HD C510




Recommendations
  • Use the raspberry pi “headless”. Do not run the desktop version of Rasbian on your Pi (xwindows). It uses an excess amount of RAM and precious CPU power that you need to reserve for your live video compression and streaming. Instead, use the command line interface or access via Secure Shell from another computer. (optional)
  • Assign a static local IP to the Raspberry Pi. (Configuration can be found in: /etc/network/interfaces). This is useful when accessing the Pi remotely. (optional)
  • Don’t use a Raspberry Pi enclosure that limits heat transfer and airflow.
Preparation
Update your software repository to the latest version by running the following commands:
sudo apt-get update
sudo apt-get upgrade
Plug in your devices.  Webcam –> Powered USB Hub –> Raspberry Pi
Install Screen (optional):
apt-get install screen
Restart your Pi device:
reboot


Installation
To transcode and broadcast the video, you will need to use a Linux application called AVConv (similar to FFmpeg). It is a command line program for transcoding multimedia files using the Libav Multimedia Framework. FFmpeg will give you the same result, but I personally prefer AVConv for ease-of-use.
To Install AVConv, run the following command:
sudo apt-get install avconv
Find a Broadcasting Platform:
To broadcast live streaming video to the Internet, you will need to create an account with Ustream, Justin.tv, or similar. After creating an account, it’s important you find the “Stream Key” or “Stream URL”.
Find the Stream URL and Key in Ustream:
  • Login to Ustream.tv
  • Open your “Dashboard”
  • Click “Remote”
  • Copy the “RTMP URL”. You will need this once you begin broadcasting, in the next step of this tutorial.
Here is an example of the final URL:
rtmp://2.773.fme.ustream.tv/ustreamVideo/77775432
Find the Stream URL and Key in Justin.TV:
  • Login to Justin.tv
  • Go to the “Other” Broadcasting page:http://www.justin.tv/broadcast/adv_other
  • Press “Show” beside “Stream Key”
  • Save this Key! You will need it in the next step.
  • Paste your “Stream Key” in immediately after this URL:  rtmp://live.justin.tv/app/
    • Note: The Default RTMP server is hosted in San Francisco. On the Justin.TV forum, you can find the RTMP address URLs for a server that is closer to you. (optional)
Here is an example of the final URL using the default URL:
rtmp://live.justin.tv/app/live_3987439857_QQsAmPlEVeStREamkeYgN6a93
Save these URLs for the next step!
Broadcast Configuration
Once you have everything set up, command-line access to the Raspberry Pi, and your Justin.tv/Ustream Stream Key URL, you’re ready to initiate the broadcast! This is the fun part!
From this point forward, you only have to input TWO commands.
  • Open a new screen session:
    screen
  • Enter the AVConv command with ALL of the parameters attached.
Basic command:
Enter this single command inside the screen session to start broadcasting! Yes, it’s that easy!
avconv -f video4linux2 -s 640×360 -r 10 -b 350k -i /dev/video0 -f flv rtmp://live.justin.tv/app/live_ReplaceThisWithYourURL
In the above example,
  • -s defines the broadcasting resolution. (Widescreen = 640×360)
  • -r defines the maximum frame-rate
  • -b defines the maximum bitrate (k= Kbps)
  • -i defines the location of your USB webcam. In most cases, if you only have one USB video device plugged in, use the /dev/video0 phrase.
  • -f defines the type of video stream and location. In this example it’s FLV transcoding (Flash video) to an RTMP server at Justin.tv
  • Don’t forget to replace the rtmp:// URL with your own Stream Key URL from the “Find a Broadcasting Platform” step.

An advanced example: (Warning: for experienced users only)
avconv -f video4linux2 -s 640×360 -r 10 -b 350k -i /dev/video0 -vf drawtext=”fontfile=/usr/share/fonts/truetype/freefont/FreeSansBold.ttf:text=’some text here ‘:fontsize=16:fontcolor=blue:x=2:y=360″ -acodec copy -metadata title=”24×7 Pi Cam” -f flv rtmp://live.justin.tv/app/live_81777DontStealMyKey6777
The above example is what I use on my “Eric’s Pets” live stream. You may notice a big difference from the original AVConv command. The -vf drawtextcommand allows you to define a font (download to your /freefont/ folder). Once a font is defined, you can add formatted text such as a “watermark” in the bottom left. The “-metadata title” allows me to tell Justin.TV what the broadcast page title should be. It can even get more advanced than this!
Please be very patient with AVConv and Raspbian. It takes time to perfect the stream quality. (My settings may not work for your camera or setup).
AVConv is very similar to FFmpeg in this sense. You can add many different features to your live video broadcast by simply putting new parameters in your initial command. You can learn more about these by reading AVConv/FFmpeg documentation.
AVConv will provide information while streaming, similar to the following string. If you see this, the stream should be broadcasting correctly.
Eric's Live Bunny Cam via Raspberry Pi
Eric’s Live Bunny Cam via Raspberry Pi
   Stream #0:0 -> #0:0 (rawvideo -> flv)
frame=215  fps=8   q=15.5   size=1001kB   time=29.20  bitrate=281.0kbits/s  dup=0   drop=3   
At any time, you can stop the stream by typing Ctrl-C, and exit the screen session by typing “exit”. To close the screen session but leave AVConv running, type Ctrl-A-D. To enter a screen session that’s already running, type “screen -r”.
Still hungry? Learn more at http://libav.org/avconv.html