Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Server Essentials

You're reading from  Raspberry Pi Server Essentials

Product type Book
Published in Feb 2014
Publisher
ISBN-13 9781783284696
Pages 116 pages
Edition 1st Edition
Languages
Author (1):
Piotr J Kula Piotr J Kula
Profile icon Piotr J Kula

Chapter 8. Streaming Live HD Video

In this chapter, we are going to use the official HD camera module designed by the Raspberry Pi Foundation. Unfortunately, at the time of writing, there was no Video4Linux driver for this camera device and alternatives had to be used.

We will also be learning how to compile a custom version of the nginx-rtmp-module. It is an add-on created by Roman Arutyunyan, and it is capable of retransmitting RTMP video. It can also be used like a media center to list stored video files, play them on demand, or capture live streams from other sites or cameras and record or rebroadcast them.

Before starting with this chapter, you should have the camera module installed and enabled as described in the instruction that was included with the module.

Streaming with GStreamer


At the time of writing, GStreamer from the OMX project is the only encoder that supports hardware encoding and decoding on the Pi. It supports the extra licensed encoders, and you can activate them by reading Chapter 3, Configuring Extra Features. GStreamer works really well for transmitting streams of video between Linux and Mac OS X. This does not work on Windows as GStreamer is not supported on Windows. Streaming live video to the VLC player or HLS format is not supported properly using GStreamer.

We can add a repository and install the latest version of GStreamer from there. We need to add this line into /etc/apt/sources.list:

deb http://vontaene.de/raspbian-updates/ . main

Then, we update the aptitude and install the packages we need:

# apt-get update
# apt-get install gstreamer1.0

Streaming with FFmpeg


Arch Linux uses the latest branch of FFmpeg, but on Raspbian, we have to compile FFmpeg manually. This can take up to 6 hours, but it has the best compatibility for streaming directly from the camera module.

When you type in the last line, it will configure, compile, and install FFmpeg in one go. Let it run and do not close the terminal window; however, just come back from time to time to make sure there were no errors. If something goes wrong, you can rerun the command, and it will go much faster as it tries to pick up from where it stopped.

# cd /usr/src
# git clone git://source.ffmpeg.org/ffmpeg.git
# cd ffmpeg
# ./configure && make && make install

Raspivid


It is best to use the latest version of Raspivid. Let's download and compile the latest version that is supported by the userland repository. This normally takes about 20 minutes to compile and install everything we need.

# sudo apt-get install git-core gcc build-essential cmake

# cd /tmp
# sudo mkdir code
# cd code
# git clone git://github.com/raspberrypi/userland.git

# cd userland
# sudo sed -i 's/if (DEFINED CMAKE_TOOLCHAIN_FILE)/if (NOT DEFINED #
  CMAKE_TOOLCHAIN_FILE)/g' makefiles/cmake/arm-linux.cmake

# sudo mkdir build
# cd build
# sudo cmake -DCMAKE_BUILD_TYPE=Release ..
# sudo make

# sudo make install

After you install all the newest userland binaries, including raspivid and raspistill, on the Pi, Raspivid should now support the usage of –t 0 and possibly some other features.

Compiling nginx-rtmp


Now, we need to compile nginx-rtmp. The following process will install nginx into the default locations. If you already have nginx configured, you will need to change some of the configuration settings or skip the installation process completely. We will install nginx from the repository just to make sure all the dependencies are installed. Afterwards, we will only remove nginx.

# sudo apt-get -y install nginx
# sudo apt-get -y remove nginx
# sudo apt-get clean

Then, we can download the latest version of the nginx-rtmp module and Version 1.4.1 of nginx. Later versions should be fine, but this version is verified to compile on the Pi and is stable with this module.

# cd /usr/scr  
## clone the latest version of rtmp module for nginx
# sudo git clone git://github.com/arut/nginx-rtmp-module.git

##download nginx source tested with- 1.4.1
# sudo wget http://nginx.org/download/nginx-1.4.1.tar.gz
# sudo tar -xzvf nginx-1.4.1.tar.gz

We need to install some building dependencies...

Watching a video


There are many different ways to transport the video, but there is one problem that many people have, which is the SPS/PPS information that only gets sent at the beginning of the stream. There is a solution that works with FFmpeg that is hosted at https://github.com/AndyA/psips. Follow the instructions on the site to compile the filter.

RTMP streams

We will use an open source media framework to stream the flash content directly in a browser that supports flash plugins. Download the framework and extract it in the HTML directory.

# cd /var/www/html
# Wget http://sourceforge.net/projects/smp.adobe/files/latest/
  download?source=files	
# unzip download?source=files	
# sudo mv for\ Flash\ Player\ 10.1 osmf

In the HTML directory, create an HTML file called flash.html and copy this basic markup into it:

<!DOCTYPE html>
<html>
  <head>
    <script src=osmf/lib/swfobject.js></script>
    <script src=osmf/lib/ParsedQueryString.js></script>...

Summary


At the time of writing, it still seems very difficult to stream video. In this chapter, we learned how to stream video in various formats to various platforms, installing and using GStreamer, compiling and using FFmpeg, compiling a custom version of nginx-rtmp, and streaming using RTMP FLV and MPEGTS UDP.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Server Essentials
Published in: Feb 2014 Publisher: ISBN-13: 9781783284696
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}