Update – I have released a Synology package for Serviio 0.6
Serviio is an excellent free Java DLNA media server by Petr Nejedly which focuses on minimizing the amount of unnecessary media transcoding, and maximizing the use of renderer devices’ supported features. Version 0.6 adds support for streaming content from online RSS feeds. Since the installation process has changed a lot, I decided to create a new post rather than edit the old one. The guide is accurate for Synology DSM 3.2 beta, and the one tricky section with wget-ssl also applies for DSM 3.1. Older DSM versions may vary.
In the Synology DSM go to Control Panel > Terminal > enable SSH.
Read this Synology wiki document about modifying your NAS carefully and install the bootstrap for your model. If you have previously been messing around with your unit and want to set it back to defaults, you can run the bootstrap again. It will prompt you to delete a couple of folders and reboot, whereupon you can start afresh.
Download the PuTTY SSH client if you’re using Windows – other operating systems will already allow you to SSH from the terminal. Give the session a name, set the remote character set to UTF-8 as shown and save it before you connect (to save time in future). This will ensure that all characters display properly. The Mac OS SSH client defaults to UTF-8.
Connect to your NAS’s IP address using SSH. Use the root account (same password as admin). For Mac OS for instance, use ssh root@x.x.x.x. I suggest enabling a more descriptive shell prompt which should reduce the chance of accidentally being in the wrong directory:
sed -i -r 's/(^PS1=.*$)/#\1\n\1/' ~/.profile sed -i -e 's/^PS1=.*$/PS1=\"\\w\\\$ \"/g' ~/.profile source ~/.profile
sed (stream editor) is a powerful tool which uses regular expressions. The first command opens the file ~./profile searches for the line beginning with PS1= and duplicates it, commenting out the first copy (so the change can be undone). Then second command sets the value PS1=”\w\$ “ which changes the prompt to be the current directory followed by dollar sign and space characters.
To install the development tools. Type:
ipkg update ipkg install optware-devel
It will halt and complain that package wget-ssl clashes with wget. Continue with:
cp /opt/bin/wget /opt/bin/wget-old ipkg remove wget cp /opt/bin/wget-old /opt/bin/wget ipkg install libidn ipkg install optware-devel
This time it will finish successfully.
Next we need to install Lame MP3 encoder, providing libmp3lame which will be compiled into FFmpeg, and the Nano text editor (much easier to use than vi), and fix up some other issues (thanks to Nicolas Jolet for these):
ipkg install lame ipkg install nano #-----coreutils ls has no colour output by default mv /opt/bin/ls /opt/bin/ls.bak ln -sf /bin/ls /opt/bin/ls #-----coreutils uptime is broken mv /opt/bin/uptime /opt/bin/uptime.bak ln -sf /usr/bin/uptime /opt/bin/uptime
Download Java SE for Embedded 7 from Oracle, selecting the Linux build for the appropriate CPU. The ARM v5 version is required for the Marvell Kirkwood CPU Synology Products. Note that there is a PowerPC e500v2 version – the CPU core in Synology products which use the Freescale mpc85x3). Unfortunately for PowerPC Synology owners, this depends on a higher version of glibc than the Synology DSM provides for this architecture. Until JamVM supports Java 1.6, or Synology update to glibc 2.4 you won’t be able to follow this guide on PowerPC models. This situation may have changed since DSM 3.2 beta was released.
You will need to sign up to receive the Java download link by email. It’s free to use for non-commercial evaluation use. Use your computer to save it into the top level shared folder of your NAS, which will probably be /volume1/public on the NAS filesystem. Then:
cd /volume1/public mv ejre-7-fcs-b147-linux-arm-sflt-headless-27_jun_2011.tar.gz /volume1/@tmp cd /volume1/@tmp tar xvzf ejre-7-fcs-b147-linux-arm-sflt-headless-27_jun_2011.tar.gz mv ejre1.7.0 /opt/local/java
Synology’s Linux build has no localization support built in, though it does use UTF-8 character encoding for the filesystem. That’s no problem for storage, however the Java VM inherits the locale setting of the host OS. Since this is undefined, Serviio and all other Java software will default to US-ASCII which is a big problem if you have filenames with non-US characters. The solution is to obtain the missing files to add locale support from the Synology toolchain, which is distributed under the GPL. Many thanks to IWarez at the Subsonic forum for this fix, though it took me a good while to realise the required files are indeed included in the ARM toolchain:
#-----for ARM CPU cd /volume1/@tmp wget http://sourceforge.net/projects/dsgpl/files/DSM%203.1%20Tool%20Chains/Marvell%2088F628x%20Linux%202.6.32/gcc421_glibc25_88f628x.tgz tar xvfz gcc421_glibc25_88f628x.tgz cd arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/usr/bin cp locale /opt/bin cp localedef /opt/bin cp -R arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/usr/share/i18n /usr/share #-----keep another copy safe in case DSM is reinstalled later cp -R arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/usr/share/i18n /opt/share mkdir /usr/lib/locale localedef -c -f UTF-8 -i en_US en_US.utf8 #-----for Intel CPU cd /volume1/@tmp wget http://sourceforge.net/projects/dsgpl/files/DSM%203.1%20Tool%20Chains/Intel%20x86%20Linux%202.6.32/gcc420_glibc236_pineview.tgz tar xvfz gcc420_glibc236_pineview.tgz cd i686-linux-gnu/i686-linux-gnu/bin cp locale /opt/bin cp localedef /opt/bin cp -R i686-linux-gnu/i686-linux-gnu/share/i18n /usr/share #-----keep another copy safe in case DSM is reinstalled later cp -R i686-linux-gnu/i686-linux-gnu/share/i18n /opt/share mkdir /usr/lib/locale localedef -c -f UTF-8 -i en_US en_US.utf8
Now use nano to edit some configuration files (Ctrl-o saves, and Ctrl-x exits).
First edit the profile for all bash shell users:
nano /opt/etc/profile
Make the changes shown in bold:
#
# Bash initialization script
#PS1=”[\u@\h \W]$ ”
PATH=/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/local/java/bin
LD_LIBRARY_PATH=/opt/lib:${LD_LIBRARY_PATH}
JAVA_HOME=/opt/local/java
LANG=en_US.utf8export PS1 PATH LD_LIBRARY_PATH JAVA_HOME LANG
Save and exit. Next edit the profile for all ash shell users (root):
nano /etc/profile
Add the changes shown in bold:
#/etc/profile: system-wide .profile file for ash.
PATH=”$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/syno/bin:/usr/syno/sbin:/usr/local/bin:/usr/local/sbin
PATH=”$PATH:/opt/local/java/bin”
JAVA_HOME=/opt/local/java
LANG=en_US.utf8
export JAVA_HOME LANG
umask 022
Save and exit. Now install Serviio 0.6:
cd /volume1/@tmp wget http://download.serviio.org/releases/serviio-0.6-linux.tar.gz tar xvzf serviio-0.6-linux.tar.gz mv serviio-0.6 /opt/local/serviio
Next, compile librtmp which FFmpeg will use to retrieve Adobe Flash streaming video, the libssl static libraries (which librtmp depends on), libz and libbz2 static libraries for FFmpeg.
#-----libz static lib (ipkg only provides shared) wget http://zlib.net/zlib-1.2.5.tar.gz tar xvfz zlib-1.2.5.tar.gz cd zlib-1.2.5 ./configure --prefix=/opt --static make make install
At this point ou will see the error “cp: missing destination file operand after `/opt/lib'” because the libz.so shared library wasn’t compiled and the install script tries to copy it nonetheless. libz.a which we need was built ok, so ignore and continue.
cd .. #-----libbz2 static lib (ipkg only provides shared) wget http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz tar xvfz bzip2-1.0.6.tar.gz cd bzip2-1.0.6 make make install PREFIX=/opt cd .. #-----libssl & libcrypto static libs (ipkg only provides shared) ipkg install openssl-dev wget http://www.openssl.org/source/openssl-0.9.8p.tar.gz tar xvfz openssl-0.9.8p.tar.gz cd openssl-0.9.8p ./config --prefix=/opt no-shared make cp libssl.a /opt/lib cp libcrypto.a /opt/lib #-----librtmp won't compile without these pkgconfig definitions cp libssl.pc /opt/lib/pkgconfig cp libcrypto.pc /opt/lib/pkgconfig cd .. #-----librtmp depends on libpthreads but the optware copy seems to be broken #-----http://forum.synology.com/enu/viewtopic.php?f=90&t=30132 mkdir /opt/arm-none-linux-gnueabi/lib_disabled mv /opt/arm-none-linux-gnueabi/lib/libpthread* /opt/arm-none-linux-gnueabi/lib_disabled cp /lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/ cd /opt/arm-none-linux-gnueabi/lib/ ln -s libpthread.so.0 libpthread.so ln -s libpthread.so.0 libpthread-2.5.so cd /volume1/@tmp wget http://download.serviio.org/opensource/rtmpdump-c58cfb3e9208c6e6bc1aa18f1b1d650d799084e5.tar.gz tar xvfz rtmpdump-c58cfb3e9208c6e6bc1aa18f1b1d650d799084e5.tar.gz cd rtmpdump #-----move all static libs to a separate folder to force compiler to use them #-----http://www.gossamer-threads.com/lists/apache/dev/265052 mkdir /volume1/@tmp/lib cp /opt/lib/*.a /volume1/@tmp/lib #-----fix Makefile (won't compile without libdl linked) #-----http://forum.luahub.com/index.php?topic=2390.0 sed -i.bak -e '/^LIB_OPENSSL\=/s/lcrypto/lcrypto \-ldl/' Makefile make SYS=posix prefix=/opt INC=-I/opt/include XLDFLAGS=-L/volume1/@tmp/lib SHARED= make install prefix=/opt SHARED= cd .. #-----gather all static libs again ready for FFmpeg compile cp /opt/lib/*.a /volume1/@tmp/lib #-----remove unsupported URL line from /opt/lib/pkgconfig/librtmp.pc #-----pkg-config --exists --print-errors librtmp sed -i -e '/^URL/d' /opt/lib/pkgconfig/librtmp.pc #-----FFmpeg 0.8.2 (slightly newer than the one at Serviio.org) cd /volume1/@tmp wget http://dl.dropbox.com/u/1188556/ffmpeg-HEAD-05a2673.tar.gz tar xvfz ffmpeg-HEAD-05a2673.tar.gz cd ffmpeg-HEAD-05a2673 #-----for ARM CPU ./configure --arch=arm --enable-armv5te --prefix=/opt --extra-cflags='-I/opt/include' --extra-ldflags='-L/volume1/@tmp/lib' --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-pthreads --enable-libmp3lame --enable-librtmp --extra-version=Serviio #-----for Intel CPU ipkg install yasm ./configure --arch=x86_64 --enable-ssse3 --prefix=/opt --extra-cflags='-I/opt/include' --extra-ldflags='-L/volume1/@tmp/lib' --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-pthreads --enable-libmp3lame --enable-librtmp --extra-version=Serviio #-----for PowerPC CPU ./configure --arch=powerpc --disable-altivec --prefix=/opt --extra-cflags='-I/opt/include' --extra-ldflags='-L/volume1/@tmp/lib' --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-pthreads --enable-libmp3lame --enable-librtmp --extra-version=Serviio make make install
Notice that the ./configure command is line wrapped – it’s all one command. The make command takes approximately 25 minutes and will show many warnings during compilation, but this is expected.
Try running ffmpeg and check the compile time to make sure the newly compiled one is running. You should see this but with your compilation date and time:
ffmpeg version 0.8.2.git-05a2673-Serviio, Copyright (c) 2000-2011 the FFmpeg developers
built on Aug 22 2011 09:57:40 with gcc 4.2.3
configuration: –arch=arm –enable-armv5te –prefix=/opt –extra-cflags=-I/opt/include –extra-ldflags=’-L/volume1/@tmp/lib’ –enable-static –disable-shared –disable-ffplay –disable-ffserver –enable-pthreads –enable-libmp3lame –enable-librtmp –extra-version=Serviio
libavutil 51. 13. 0 / 51. 13. 0
libavcodec 53. 11. 0 / 53. 11. 0
libavformat 53. 9. 0 / 53. 9. 0
libavdevice 53. 3. 0 / 53. 3. 0
libavfilter 2. 34. 1 / 2. 34. 1
libswscale 2. 0. 0 / 2. 0. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…Use -h to get full help or, even better, run ‘man ffmpeg’
In the DSM User Control Panel create a new user called serviio and set a password. Give that user access to the paths that contain the media you want to serve. Click the User Home button and enable the User Home Service. Go back to your SSH session and type:
nano /etc/passwd
Be very careful editing this file. A wrong move here could trash your system. Notice that the serviio user has a shell of /sbin/nologin. Change this to /bin/sh like the admin user has. Nano may try to line wrap this line as you type if you added an long account description. If it does, delete the carriage return before the line break and pull it back onto one line. Save and exit.
Now we’ll create the Serviio daemon start and stop script:
nano /volume1/@tmp/S99serviio.sh
Paste in the following text (mouseover and use the view source button to copy):
#!/bin/sh User=serviio case "$1" in stop) echo "Stop Serviio..." su -l $User -c "/opt/local/serviio/bin/serviio.sh -stop" > /dev/null 2>&1 & ;; start) # start Serviio in background mode su -l $User -c "/opt/local/serviio/bin/serviio.sh" > /dev/null 2>&1 & echo "Start Serviio..." ;; restart) $0 stop sleep 1 $0 start ;; *) echo "usage: $0 { start | stop | restart}" >&2 exit 1 ;; esac
Now make it executable and set the serviio user to be the owner of the Serviio folder (so it can create the media database, and log files):
chmod +x /volume1/@tmp/S99serviio.sh chown -R serviio /opt/local/serviio
Test the script manually by running:
/volume1/@tmp/S99serviio.sh start ps
The running process list should show the serviio user running the Serviio launcher shell script and the JVM like so:
5132 root 16988 S /usr/syno/sbin/nmbd -D 5134 admin 34804 S postgres: admin photo [local] idle 5187 root 21080 S /usr/syno/sbin/smbd -D 5189 root 21080 S /usr/syno/sbin/smbd -D 5205 root 7216 S /usr/syno/sbin/cnid_metad -l log_error 5207 root 13808 S /usr/syno/sbin/afpd -g guest -c 256 -n DS111 AFPServ 5253 root 9208 S N /usr/syno/sbin/synomkflvd 5317 root 4112 S /usr/syno/sbin/sshd 5332 root 6932 S /usr/syno/apache/bin/httpd -f /usr/syno/apache/conf/ 5344 root 7068 S /usr/syno/apache/bin/httpd -f /usr/syno/apache/conf/ 5345 root 7068 S /usr/syno/apache/bin/httpd -f /usr/syno/apache/conf/ 5369 root 6928 S /usr/syno/apache/bin/httpd 5383 nobody 6928 S /usr/syno/apache/bin/httpd 5384 nobody 6928 S /usr/syno/apache/bin/httpd 5385 nobody 6928 S /usr/syno/apache/bin/httpd 5436 root 2408 S avahi-daemon: running [DS111.local] 5460 root 11928 S sshd: root@pts/0 5466 root 5452 S -ash 5582 root 0 SW [flush-8:0] 5602 serviio 2988 S -sh -c /opt/local/serviio/bin/serviio.sh 5605 serviio 2988 S /bin/sh /opt/local/serviio/bin/serviio.sh 5610 serviio 498m S /opt/local/java/bin/java -Xmx384M -Djava.net.preferI 5623 root 5452 R ps
Stop the daemon with:
/volume1/@tmp/S99serviio.sh stop
Check the web UI or the process list again and make sure it did indeed stop. If it’s all ok, we need to move the daemon launcher script so it starts automatically on boot (it will survive a DSM upgrade):
mv /volume1/@tmp/S99serviio.sh /opt/etc/init.d
Shutdown the NAS and restart, checking that Serviio starts by itself.
From now on you can start and stop Serviio manually using this same script (say if you were experimenting with changes to profiles.xml for instance):
/opt/etc/init.d/S99serviio.sh stop /opt/etc/init.d/S99serviio.sh start
Remote console
AcidumIrae’s PHP Web UI is only for Serviio up to version 0.5.2 at present, and at the time of writing the Java Restful Web UI by kairoh does not yet integrate with Serviio 0.6. The only option for now is to use the proper Serviio Console from another computer. Since 0.6 there is no longer a requirement to change anything at the server end, so you just need to pass the parameter -Dserviio.remoteHost=x.x.x.x to the Serviio Console to indicate the IP of your Serviio server. This is covered in the Serviio FAQ. There’s quite a lag for it to start up (at least on Windows), but eventually you see the familiar icon.
Serviio settings
Navigate to the Transcoding tab. Set the transcoded files location to /volume1/@tmp. Failure to do this will result in temporary files being written to /tmp which will fill up the partition it’s on the moment you remux a 4GB movie, which would prevent you from logging into the NAS. If your Synology has an Intel CPU set the number of transcoding threads to 2. The dual cores should take advantage of FFmpeg’s pthreads support for a decent performance boost.
I recommend de-selecting Generate thumbnails for local videos in the Metadata tab. Note that you have to click Save on each tab or any change will not take effect. As you’ll see if you have a DLNA renderer that supports thumbnails, Serviio retrieves good ones from the online databases it checks so they’re not really needed. Often FFmpeg will get stuck trying to generate a thumbnail for a video and will lock the CPU at 100% for long periods of time. This issue was raised in this Serviio forum thread.
You can use the Library tab to add the media folders you want to share. Use Add Path not Add Local (we’re using a remote console remember) and express the paths in Linux syntax, e.g. /volume1/public/videos. Be sure that the serviio user has been granted read privileges over the folders you add (User Control Panel in DSM).
Performance
The Synology seems perfectly able to transcode DTS audio in a hi-def Matroska file down to 2 channel AC3 in MPEG-TS while copying the H.264 stream. The CPU use leaps up to 100% but I guess that’s because it’s running ahead transcoding down to the end of the file (and is CPU-bound).
If I play something that’s only remuxing the container and copying both audio and video streams then the CPU stays at around 40% (because it’s I/O-bound) then 5 minutes into a film it falls away to pretty much idle – I guess it has finished remuxing to the temporary file.
Memory use even while running Serviio is around 20% at idle, 30% during a remux with audio transcode, though I have noticed that with a larger library this creeps up to around 70%. I have a 2011 product so it has 256MB of RAM. This seems to indicate that the value line of products (with the j suffix) like the DS211j should run Serviio on their 128MB. They have a 1.2GHz CPU though versus 1.6GHz on mine (and the DS110j is only 800MHz), so it would need testing by someone.
All in all it would seem that the Synology products are very capable Serviio appliances!
Uninstalling
Log in as root and stop Serviio, then in the DSM User Control Panel delete the user called serviio. Undo the changes that you made to /opt/etc/profile and /etc/profile (the LANG, JAVA_HOME and java path modifications marked in bold earlier in the guide).
Finally, re-download the bootstrap for your model of NAS and run it again. It will tell you to delete a few folders and restart. This will completely trash all optware ipkg packages (i.e. everything in /opt) and undo everything else you did in this guide without affecting your data partitions. If you had any other ipkg packages installed since installing Serviio, these would also be lost.