Compiling flvstreamer for use on Unslung Linux
Posted by sticklyman on September 14 2009 14:11:10
This tutorial explains how to compile flvstreamer for use on Unslung Linux. I assume that you already have Unslung Linux installed on your NSLU2 & that you have unslung onto one of the two hard drives.

If you do not wish to compile yourself, you can download a pre-compiled version [url=http://saschabischoff.co.uk/infusions/pro_download_panel/download.php?did=1]here[/url].

[u]Requirements:[/u]

If you meet these requirements, please proceed to the next page.


Package Installation

In order to compile flvstreamer, you will first need to install certain packages. These include the GCC compiler and the required libraries for flvstreamer.

The first step is to ensure you have the latest package listings.

[code]ipkg update[/code]
Next, we need to install the C compiler, make and the C++ Standard Library.
[code]ipkg install crosstool-native
ipkg install make
ipkg install libstdc++[/code]
Another useful package is the coreutils package which provides many (yes, you guessed it) core utilities. These include functions such as env, which is used to check/modify your environment variables. This is very useful when trying to determine why a certain program just will not run.
[code]ipkg install coreutils[/code]
In order to get flvstreamer to compile and run correctly on Unslung, we need to modify the makefile. If you, like me, get totally confused by the vi text editor, you will want to use a more user friendly alternative. This is where nano shines. It has a very user friendly interface - for a console text editor at least.
[code]ipkg install nano[/code]
Now that all of these packages are installed, we need to download the flvstreamer source code, as is described on the next page.

[u]Downloading The flvstreamer Source Code[/u]
There are two ways to download the source code for flvstreamer. One is to directly download a compressed copy of the code via HTML. The other is to download the latest code from the SVN repository. I shall describe how to download the HTML version as it is the simplest way.
First, you need to browse to [url=http://mirrors.zerg.biz/nongnu/flvstreamer/source/]http://mirrors.zerg.biz/nongnu/flvstreamer/source/[/url] (on your computer, not the slug). Here you have a list of compressed source code images. You want to copy the URL of the latest *.tar.gz file. Make sure that you do not get the URL of the *.tar.gz.sig as this is just a signature file. The latest file at the time of writing is [url=http://mirrors.zerg.biz/nongnu/flvstreamer/source/flvstreamer-1.8k.tar.gz]flvstreamer-1.8k.tar.gz[/url].
Now, on your NSLU2, you need to change the directory to the one where you want to download flvstreamer to. In my case, I want to download flvstreamer to /root.
[code]cd /root[/code]
Next, you need to enter "wget" followed by a space and then the full URL of the compressed source code file.
[i]Hint: When using PuTTY, you can copy text and then right click in the PuTTY window to paste that text in. For example, you can right click the URL of the source code file in your browser, select Copy URL and then right click in the putty window to paste it in. This should make the process much quicker & error free.
In my case:[/i]
[code]wget http://mirrors.zerg.biz/nongnu/flvstreamer/source/flvstreamer-1.8k.tar.gz[/code]
This will download the file to the root directory. The file will have the same name as the one in the URL. You can verify that the file is there by entering "ls". This lists the contents of the current directory. You should see a file with a name similar to flvstreamer-1.8k.tar.gz.
Next we need to uncompress this file. To do this we need to enter "tar xzf" followed by a space and then the file name. To save time you can enter the first few letters of the file name, and then press TAB. This should auto-complete the file name, provided there are no similarly named files in the same directory.
[code]tar xzf flvstreamer-1.8k.tar.gz[/code]
This should have created a directory called "flvstreamer". We now need to change to this directory.
[code]cd flvstreamer[/code]
The next step is to modify the makefile.

[u]Modifying The Makefile[/u]
As all Linux distributions are different, they all require slightly different makefiles. In this case, the compilers have the standard names. However, the MakefileARM makefile assumes that your compilers have architecture specific names (eg. arm-linux-gcc). Therefore we need to modify this.
Also, we need to tell the compiler where it can find the C++ library we downloaded earlier. This can also be done in the makefile.
I am providing my makefile but I can only guarantee that it works for version 1.8k. Please download it from [url=http://www.saschabischoff.co.uk/infusions/pro_download_panel/download.php?did=2]here[/url].
First, we need to open the makefile using nano.
[code]nano MakefileARM[/code]
This will bring up a window that looks similar to the following:



At the top, you have the title bar which displays the version of nano being used, as well as the name of the file you are currently editing. Below that, the contents of the file is displayed. At the very bottom of the screen you have a list of the commands which you can use.
Commands can be run by pressing the CTRL button and the letter shown before the command. For example, to WriteOut (save) you press CTRL and O. This will bring up a prompt asking for the file name you wish to save as. Pressing enter at this stage will save the file under that name.
The green square that can be seen is the cursor. This can be moved around the screen in just the same way that you can move the cursor is almost any other text processing application; using the arrow keys.
Right, back to editing the makefile. Move the cursor to the right (using the arrow keys) and then delete "arm-linux-". Then delete "arm-linux-" on the two lines below that. Your screen should then look like this:



Then we just need to make one more change to the makefile. We need to tell the compiler where it can find the C++ library. To do this, go down to the line that says "LDFLAGS=" and change it to "LDFLAGS=-Wl,-rpath=/opt/lib". Your screen should now look like this:



And your modified makefile should look like this:
[quote]CC=gcc
CXX=g++
LD=ld

CFLAGS=-Wall -D_FILE_OFFSET_BITS=64
CXXFLAGS=-Wall -D_FILE_OFFSET_BITS=64
LDFLAGS=-Wall -D_FILE_OFFSET_BITS=64

CXXFLAGS=
LDFLAGS=-Wl,-rpath=/opt/lib

all: flvstreamer

clean:
rm -f *.o

streams: bytes.o log.o rtmp.o AMFObject.o rtmppacket.o streams.o parseurl.o handshake.o
$(CXX) $(LDFLAGS) $(ARMFLAGS) $^ -o $@_arm -lpthread

flvstreamer: bytes.o log.o rtmp.o AMFObject.o rtmppacket.o flvstreamer.o parseurl.o handshake.o
$(CXX) $(LDFLAGS) $(ARMFLAGS) $^ -o $@_arm

bytes.o: bytes.cpp bytes.h Makefile
log.o: log.cpp log.h Makefile
rtmp.o: rtmp.cpp rtmp.h log.h AMFObject.h Makefile
AMFObject.o: AMFObject.cpp AMFObject.h log.h rtmp.h Makefile
rtmppacket.o: rtmppacket.cpp rtmppacket.h log.h Makefile
flvstreamer.o: flvstreamer.cpp rtmp.h log.h AMFObject.h Makefile
parseurl.o: parseurl.cpp parseurl.h log.h Makefile
streams.o: streams.cpp log.h Makefile
handshake.o: handshake.cpp log.h Makefile[/quote]
Now, press CTRL and O and then press Enter. This will save the file under the same file name. Now, exit nano by pressing CTRL and X. Next, we compile flvstreamer.

[u]Compiling[/u]
We are now ready to compile flvstreamer. To do this, enter:
[code]make -f MakefileARM flvstreamer[/code]
This will start the compiler and will, once it is finished, create a file called flvstreamer_arm.
This file should now work and we can test for library errors by entering:
[code]./flvstreamer_arm[/code]
If the output is similar to the following, you do not have any library errors.
[quote]FLVStreamer v1.8k
(c) 2009 Andrej Stepanchuk, The Flvstreamer Team, license: GPL
ERROR: You must specify a hostname (--host) or url (-r "rtmp://host[:port]/playpath") containing a hostname[/quote]
Otherwise, if your output looks like the following, you have a problem with the C++ library. Please check you installed the package as instructed to earlier.
[quote]./flvstreamer_arm: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory[/quote]
Now, we need to test flvstreamer. This is best done using the get_iplayer Perl script and is described on the next page.

[u]Testing flvstreamer[/u]
Now that you have compiled flvstreamer, you will want to test it. To test it using get_iplayer you will need to download and configure it.
First, go to the directory where you wish to download get_iplayer to. In my case, this will be /root/get_iplayer. As the get_iplayer directory does not exist, I shall create it.
[code]cd /root
mkdir get_iplayer
cd get_iplayer[/code]
Now we need to download get_iplayer and make it executable. We will also run it once to allow it to create the directories & files it needs to operate.
[code]wget http://linuxcentre.net/get_iplayer/get_iplayer
chmod 755 get_iplayer
./get_iplayer[/code]
Next, we need to tell get_iplayer where it can find the flvstreamer binary we just compiled. In my case, this was /root/flvstreamer/flvstreamer_arm.
[code]./get_iplayer --prefs-add --flvstreamer=/root/flvstreamer/flvstreamer_arm[/code]
Provided you entered the command correctly, you should get an output similar to:
[quote]INFO: Options file /root/.get_iplayer/options updated[/quote]
At this stage, it is also useful to set the default output directory. If you want the videos you download to be accessible from the Samba share, you need to create an output folder in your /public directory. I shall call this folder "iPlayerDownloads".
[code]cd /public
mkdir iPlayerDownloads
chmod 0777 iPlayerDownloads[/code]
Once you have created your output folder, you want to return to where get_iplayer is located and set your output folder.
[code]cd /root/get_iplayer
./get_iplayer --prefs-add --output='/public/iPlayerDownloads'[/code]
Now, there is one more thing left to do before we attempt and download a programme. We want to make sure that users are able to access the downloaded files. If you do not do this you will have to change the permissions of each file as you download it.
[code]./get_iplayer --prefs-add --command='chmod 0777 '[/code]
Now we are ready to try and download a programme. Say you wanted to download a programme called "Click" (yes, this does exist - it is a programme about the latest technology) and you wanted to download it in FLV format. The best way to start is to search for all programmes which contain the word "Click" in their titles.
[code]./get_iplayer "click"[/code]
This will return something similar to the following:
[quote]# ./get_iplayer "click"
get_iplayer v2.34, Copyright (C) 2009 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.

Matches:
146: Click - 12/09/2009, BBC News 24, Factual,News,Science & Nature,TV, default,

INFO: 1 Matching Programmes
[/quote]
You can now download the programme using the index value shown before the title above. I know that this programme is available in flashvhigh format (this can be seen using the --info parameter), I can force the download to be in that format. Entering the following it will download the programme.
[code]./get_iplayer --get 146 --vmode=flashvhigh[/code]
The result of this should be:
[quote]get_iplayer v2.34, Copyright (C) 2009 Phil Lewis
This program comes with ABSOLUTELY NO WARRANTY; for details use --warranty.
This is free software, and you are welcome to redistribute it under certain
conditions; use --conditions for details.

Matches:
146: Click - 12/09/2009, BBC News 24, Factual,News,Science & Nature,TV, default,

INFO: 1 Matching Programmes
INFO: Checking existence of default version
INFO: flashvhigh1,flashvhigh2 modes will be tried for version default
INFO: Trying flashvhigh1 mode to record tv: Click - 12/09/2009

WARNING: ffmpeg does not exist - not converting flv file
INFO: File name prefix = Click_-_12_09_2009_b00mvl50_default
FLVStreamer v1.8k
(c) 2009 Andrej Stepanchuk, The Flvstreamer Team, license: GPL
Connecting ...
Starting download at: 0.000 kB
Metadata:
duration 1426.43
moovposition 32
width 832
height 468
videocodecid avc1
audiocodecid mp4a
avcprofile 77
avclevel 30
aacaot 2
videoframerate 0
audiosamplerate 48000
audiochannels 2
trackinfo:
length 35660000
timescale 25000
language eng
sampledescription:
sampletype avc1
length 68468736
timescale 48000
language eng
sampledescription:
sampletype mp4a
5527.372 kB / 52.60 sec (2.9%)[/quote]
If you leave this to complete, the file should appear in your selected download directory. For full documentation for get_iplayer, please visit the [url=http://linuxcentre.net/getiplayer/]get_iplayer website[/url].

Thank you for using my tutorial. Feel free to leave any comments.