In the previous post, we saw how to setup nginx web server with RTMP plugin. We will now install ffmpeg and use it to publish our own streams to the nginx RTMP url which can then be accessed via HTTP by any other client. We will compile libx264 and then ffmpeg. Compiling in Raspberry Pi itself will take a long time due to hardware limitations. As an alternative, ffmpeg can be compiled by emulating Pi in your desktop computer or by cross-compiling.

If you decide to compile ffmpeg in Pi itself, the following steps might help you.

Compile and install libx264 first.

sudo bash
cd /usr/src/
mkdir libx264
cd libx264
git clone git://git.videolan.org/x264.git
cd x264
./configure --enable-static --enable-shared
make
make install
ldconfig

If you get a message complaining that the yasm installed is old, you can update it as below:

git clone git://github.com/yasm/yasm.git
cd yasm
./autogen.sh
./configure
make
make install

Now compile and install ffmpeg.

cd /usr/src/
mkdir ffmpeg
cd ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-gpl --enable-libx264 --enable-librtmp
make
make install
ldconfig

Now you should be able to repackage RTMP streams to HTTP streams using ffmpeg. Lets take an example using an RTMP url that looks as below:

rtmp://somehost:1940/base2 playpath=data.stream token=Vu4KaBzaxa swfUrl=http://www.somewebsite.com/wp-content/uploads/jw-player-plugin-for-wordpress/player/player.swf pageUrl=http://www.somewebsite.in/live-tv/

This stream can be repackaged using ffmpeg as shown below:

ffmpeg -i "rtmp://somehost:1940/base2 playpath=data.stream token=Vu4KaBzaxa swfUrl=http://www.somewebsite.com/wp-content/uploads/jw-player-plugin-for-wordpress/player/player.swf pageUrl=http://www.somewebsite.in/live-tv/" -c:a copy -c:v copy -preset slow -f flv rtmp://localhost:12345/hls/mystream

As you can see, the codecs are copied, and not encoded again. The repackaged stream will be published to the nginx RTMP url, and can be accessed via below url using any client, for example VLC Player.

http://localhost/hls/mystream.m3u8