Serviio 0.5.2 DLNA server on Synology NAS

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. Some of the more main-stream servers like Windows Media Player just brute-force everything to MPEG2 video and MP3 audio, which degrades quality and wastes power. Though some servers like Mezzmo are better and will play Matroska files, even they tend to transcode all audio to AC-3 regardless of source type. As a Java app Serviio will run on anything that has a JVM, and the media tool it relies on is the open source and therefore highly portable FFmpeg. All these design priorities make Serviio an ideal choice to run on a NAS device since, when paired with a renderer with good format support like a Sony Bluray Player, the NAS will barely ever be transcoding.

I was about to buy a new large external hard disk, but once I realised that Serviio could probably run on a NAS I started looking at one of these instead. Synology seemed to offer a lot of value and seemed to have the sort of user-community enjoyed by my old Linksys NSLU2, which I promptly sold on eBay for almost what I had paid for it in 2007. I considered the value DS110j model but I decided to go for the more expensive DS111 on the basis that the double CPU speed and RAM would probably be a wise move.

This guide outlines how to get Serviio 0.5.2 running on the Marvell Kirkwood ARM CPUs found in most of the 2011 product line-up, but Synology devices also exist with Freescale PowerPC and Intel Atom processors. The key problem is finding a Java virtual machine, but FFmpeg also needs compiling from source. This is because although there is an FFmpeg binary bundled with DSM 3.0, it’s too old and lacks support for features critical to Serviio. This guide could be used for other CPU architectures, but the compilation options for FFmpeg need adapting.

Connect to your NAS’s IP address using SSH. Use the root account (same password as admin). I suggest that you perform the mod at the bottom of this post to enable colour directory listings and a more descriptive shell prompt which should reduce the chance of accidentally being in the wrong directory.

We need to install the development tools. Type:

ipkg install optware-devel

It will halt and complain that package wget-ssl clashes with wget. Continue with:

Update – It seems that there is a serious problem with running ipkg on a clean install of DSM 3.1. This guide was written before it was released, and though I have since upgraded my Synology I haven’t encountered that issue, but there have been many comments about it. User mayk on the Synology forum seems to have the solution here. Use the extra wget verbosity switch to find out the exact package URL for the following two packages, then manually download them with wget and install:

Next we need to install Lame MP3 encoder, providing libmp3lame which FFmpeg will be compiled to depend on, and the Nano text editor (much easier to use than vi):

ipkg install lame
ipkg install nano

JamVM is a JVM that gets mentioned a lot in connection with NAS systems, but it’s only Java 1.5, and Serviio needs version 1.6. Download the Java SE Embedded Runtime from Oracle, selecting the ARM v5 Linux version (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 may have changed since DSM 3.1 was released.

You will need to sign up to receive the download link by email. It’s free to use for non-commercial self-educational 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:

Synology’s Linux build has no localisation 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:

In the DSM Control Panel got to Web Services > Web Applications tab > Enable Web Station.
Install AcidumIrae’s PHP web UI for Serviio. You will need to have enabled Web Station for the directory /volume1/web to exist.

You should already be able to browse to http://your_NAS_IP/serviio and see the user interface, though it will complain with a big red X that Serviio is not running.

FFmpeg depends on the libbz2 and zlib libraries, and although both are installed along with the optware-devel package, FFmpeg will only look for them in /lib rather than in their actual location in /opt/lib. Copies of the existing symbolic links will be fine:

cp /opt/lib/libbz2.so.1.0 /lib
cp /opt/lib/libz.so.1 /lib

Compile the patched version 26303 of FFmpeg from the Serviio download page. Running cat /proc/cpuinfo it is clear that the DS111 is an ARM 5TE platform so I enabled those specific optimizations:

Notice that the ./configure command is line wrapped – it’s all one command. The make command takes approximately 25 minutes on the 1.6GHz CPU and will show many warnings during compilation, but this is expected.

Update – Thanks to bakman for pointing out that for Intel Atom CPUs you will need to install the assembler YASM and also use the following ./configure parameters:

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 icon in the top right to copy):

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:

mv /volume1/@tmp/S99serviio.sh /opt/etc/init.d

Shutdown the NAS and restart.

Update – previously I had used the directory /usr/syno/etc/rc.d, but this is destroyed when the DSM software is updated. /usr/local/etc/rc.d is the official Synology location for 3rd party daemon init scripts but I found that it doesn’t work, so I used /opt/etc/init.d instead which also survives a DSM upgrade. I just tested this by upgrading to DSM 3.1-1605 and Serviio remained intact. I only had to copy the sym links for the libraries FFmpeg needs (“cp /opt/lib/libbz2.so.1.0 /lib” and “cp /opt/lib/libz.so.1 /lib”).

The file loaded into nano will look like this, and you need to edit the IP address to match the IP of your Synology (either put your syno on a static IP, or set a reservation in your broadband router’s DHCP server options).

I can’t find a way to avoid manually specifying the IP address like this – relative paths can’t be used because the Synology runs two different webservers: the DSM one on port 5000 without PHP, and the PHP-enabled Web Station one on port 80.

Log out of DSM and log back in. You will see the Serviio icon in the pull down menu in the top left, which you can drag to the desktop if you prefer:

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.

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. Note that the Add Local… button will fail because the web service user does not have access to the root of the filesystem (probably a good thing security-wise). Use Add Path… instead and express the paths as I have done in the first screenshot above. Be sure that the serviio user has been granted read privileges over the folders you add (User Control Panel in DSM).

Update – If you really want to use the Ajax file browser UI, then go to DSM Control Panel > Web Services > PHP Settings tab > open_basedir and append /volume1: to the start of that list. Then on the Web Applications tab, disable Web Station, Ok, enable Web Station. Go back to your SSH session and run:

nano /volume1/web/serviio/afb/config.php

Change the value of $path from / to /volume1/public (or the top level shared folder where your media resides). You’ll notice however that when you use Add local button in the Serviio Library tab it’s very buggy. It will only list a maximum of 5 child folders from each node.

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 delete a couple of libraries which had been copied to /lib:

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 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.

Thank you for the instruction however im not that pro in this kind of things and maybe you can help me out via mail or something?
I really want to work serviio on my ds211 because I bought a ps3 for streaming but noticed that synology has no dlna programs that I can install normally.

Make sure you do all the archive extraction on the Syno, not in Windows, or you’ll end up with damaged file permissions. In Linux a file needs to have the execute permission for it to be executable. That’s what chmod +x does. When unTARed on the Syno all this will be fixed automatically.

Hmm, I have tried removing java and then downloading it again directly to the syno (DS107+). which java gives the correct path. It just seems as if the java is not executable. The permissions in the bin-library are
-rwxr-xr-x 1 10 dovecot 58545 Apr 14 14:43 java
-rwxr-xr-x 1 10 dovecot 58568 Apr 14 14:43 keytool

Yours is CPU architecture 5TEJ and mine is 5TE. I thought that would be ok, but I’ve looked up the definition of ARM 5TEJ and apparently it’s a feature called Jazelle. It’s a technology to allow the processor to execute Java bytecode directly:http://en.wikipedia.org/wiki/ARM_architecture#Jazelle

I would guess that’s likely to be in conflict with Java Embedded. My recommendation would be to ask on the Synology Forums.

I was actually testing it on my DS107+ before installing Serviio on the DS209, which is my main NAS. I followed the instructions again and there was no problems in installing and running Serviio on DS209. Excellent! Now I just have to figure out how to play my AVI-files.

The Bravia 5500 series can’t play AVI natively (I have one) so your Syno is trying to transcode to mpeg2video which it can’t manage in realtime. It’s only really got the power to remux containers like mkv and transcode audio. Can you use a different renderer? Games console, or Bluray player perhaps?

How in the world can we uninstall? I setup everything, though the setup simply didn’t have enough power for the use I wanted out of it. I have tried resetting many times to no avail. I accidentally removed a few of the original directories, so make remove is not an option. I want to go back to a clean slate, without all of the packages from this tutorial. Thank you!

I did that to no avail, even cleaned my drives. Serviio still exists in the menu, which I could edit out by backtracking. However, ffmpeg and other depends still exist on the system that I would like to remove. The original directories do not exist though, so I cannot make remove. I want a way to “truly” reset the device back to scratch and cannot seem to do it via the rear button or default settings reset.

As I understand it most of the modifications live in /opt which is actually on your hard drive. Those that don’t should be reset when you re-apply DSM. So you could maybe try removing the disks and destroying their partition tables, then putting them back in.

I have the ds211 and trying to stream to my ps3.
Tried to follow your guide via a XP machine because I couldn’t find Putty for MAC.
Also this is not really my thing and already on the first line it didn’t work for me. I have enable SSH, installed Putty, logged on the synology and after that ipkg is not a good command.

PuTTY is not necessary on Mac OS as it includes an ssh client in the OS. Open Utilities -> Terminal and type:ssh root@x.x.x.x

where x.x.x.x is the IP of your NAS. As for the bootstrapper – clearly you didn’t read the guide properly, it’s all there (search for “Read this Synology wiki document about modifying your NAS carefully and install the bootstrap for your model”)

I think though that if you missed those things I’d probably recommend that you avoid trying to do this without the help of someone near to you that knows a bit more about Linux. Though a few people have offered me money to install Serviio for them remotely, I’m afraid it’s not something I’m interested in doing.

I think I am the lazy one then ;) but indeed maybe it is better to ask someone with more linux experience to help me out. I will try this weekend to follow step by step and if I get problems I reply on this posts.

Hi all! Many thanks to Patters for putting up this amazing guide! I have been running Serviio on a pc for a while now and was looking forward to get it running on my PPC based DS210+ but unfortunately it looks like I’m stuck until jamvm supports 1.6.

Any worthy alternatives I might be able to give a shot in the meanwhile?

Btw, as others have mentioned earlier I wasn’t able to copy the contents of S99serviio.sh either. Manually editing did the trick though.

Hello,
Thanks for this very detailed tuto , i have still not finished as i am stuck as i am not sure to know the correct version of Java SE Embedded Runtime i need to use for my 411+ (intel atom)
Is anyone can drive me ?

hmm, extenue, i can tell you that stram to Bravia will not work well, it will stutter (transcoding on the fly to MPEG2) However Xbox (no transcoding) will be fine. I havent tried subbing because im lacking some Mplayer skills, so please tell me your findings

I dont suppose you could show me how to make the ffmpeg install work with the –enable-shared in place? Everytime I change it fails to install properly. I must admit I dont want Servilio, I am only trying to install ffmpeg-php on my synology ds411j nas for a website and when I attempt to compile ffmpeg-php it tells me I need to compile ffmpeg with “–enable-shared” first…

Thanks for the excellent guide.
I have finally installed Serviio on Sunology DS411slim and i can see it on my PS3 and TV.
The issue is, i don’t see my media from the NAS. in the serviio i have configured the path as /volume3/music
/volume3/video
/volume4/photo.
I can only see some on the music files but no video and photos. some music files are also missing. I have given all access to serviio user and even made it a admin. still no luck. thumbnails are off. i have read through the serviio forum but couldn’t find any solution.

I did change the user to serviio for /opt/serviio and i have also seen the serviio log. not much i can conclude from the log. what i did notice is that now i have the videos for only ine folder but other folders are missing. Music and photos folders are still blank.

I there a way i can erase the library or database and then build it again? my conclusion is that since i changed the setting too many times, the library does exists and if i’m correct in interpretting the log, i did notice some of the music and photos being added to the library. os if i erase the library and database then i might succeed in rebuilding the folders. any suggestions on the process to rebuild the library?

All works fine in my ds210j since the web configuration step .
When i try to load defaults folders i get an error (cannot put repository).
All folders that serviio use are with 777 permission for test pourpose.
On serviio forum i found that maybe it’s the java version that it’s not so good.
So, maybe i’ts cause serviio acatually it’s not compatible with the version i found on java web site that is ejre-7-fcs-b147-linux-arm-sflt-headless-27_jun_2011.tar .
Can you send or load to a hosting site (Megaupload similar) your ejre-1_6_0_21-fcs-b09-linux-arm-sflt-eabi-headless-27_sep_2010.tar.gz .

Excellent guide. First time i’ve touched linux (or any nix based OS really) and you provided enough details to get me through with limited issues along the way. Now have serviio installed on my DS211+, thanks!

I wanted to check one point with you. Once I got this running I noticed that the CPU usage was consistently high, 85-90% even once library updating etc. was complete and the box should have been idle. Checking the log confirmed Serviio was not doing very much. I notice that several people also reported the same issue. This is not thumbnail related as I definitely have that switched off and there is no ffmpeg process running. the process consuming the CPU is Java.

What I have narrowed this down to is the setting for the “Keep library automatically updated” check box. When it is ticked the CPU is high, as soon as I remove the checkbox the CPU drops to a few % as expected, checking it again CPU jumps up again etc. You did not seem to have this issue so I would like to know how you have that value set? If you do have it set, then I would like to try and work out whar is different about my install that might be causing this. Other than that all works as expected.

Thanks for the feedback – I tried to write the guide to be workable for non-Linux familiar people, and hopefully you’ll have taken away some concepts which will be useful to know in future!
As for the library updating I set mine to only update at 720 minute intervals. I’ll add that to the guide. I’ve written a revised one ready for when Serviio 0.6 is released (it’s beta only at the moment).

thx. a lot. i have spent a lot of time for my DS209. At last, the Java-Version 1.7 was the problem :)
now i have taken the following version.
ejre-1_6_0_25-fcs-b06-linux-arm-sflt-eabi-headless-14_apr_2011.tar.gz
So, iam a totally linux newbie. so i dont`t understand what can i do with the servio-console.sh?
when i add folders, what is the right one?

Ok i have tested servillo 0.52 on my DS210j …
It works! But is sucks!
The video/audio are played on my Sony Bravia but they are laggy as hell .
FFmpeg takes all my cpu to transcode…
Bad luck, and lack of money when i choose a J version -.- next time i’ll take a + version ç_ç
Anyway thanks for your howto and for your support :)

Thanks for the feedback. Bravia TVs (2009, and 2011 until someone figures out native AVI playback) aren’t ideal renderers. Rather than replacing your NAS though, you could always consider a Sony Bluray player. Similar money, and then you have bluray playback too.

Can you postit down here?
I’m not good at all in scriting :P
Maybe Patters can use it to do a howto including integration in Synology and the startup of the script during the post download .
This will be useful to those who have this problem and have an old version or low Mhz processor like me .

-what does my played support?
-can my diskstation stream without transcoding on the fly.
– do i mind more power consumption

ah well, i dont want to spend too much time on this, so you can tweak these scripts to what you like. At this moment i will have 2 versions of the movie when transcoded: the originals and the transcoded.

you will need 2 scriptfiles, mine are /volume1/scripts/findmovies.sh and /volume1/scripts/convert.sh. You can run the ‘findmovies.sh’ when you finish dowloading something, or run a crontab for it (use ‘vi /etc/crontab’ ) to schedule it to run like every hour or so. sidenote: when a file is already converted, it will no be overwritten by FFMPEG by default

Thanks heaps for the guide Patters.. Spent a couple of hours running through it today on a DS1511+ and it works perfectly. I’ve changed the Serviio profile for PS3 a little to force some transcoding to see what the performance is like, and so far the 1.8GHz Atom seems to be capable of doing the job, I’ve had no issues at all, and the CPU sits on about 30-60%. Pretty cool little device. I spose time will tell whether or not it’ll cope with the full HD stuff..

It’s not nearly as good as Serviio. I’m close to releasing a .spk package for Serviio 0.6 (when it comes out of beta) so if you’re daunted by the process, hang back a little. Should be within a couple of weeks.

I was wondering about quality of the built in DLNA server. I am thinking about purchasing the NAS. The package would be great to enhance its capabilities. I have a netbook with Atom CPU 330 1.6 GHz. Wonder how it compares to DS111’s CPU?

Did you allow the Serviio user read access to your video share (in the Users control panel in DSM)? To troubleshoot, perhaps try to add some media that’s in the public share (which all users can access).

Serviio has read/write permissions on the video share. I don’t seem to have a ‘public share’ so I created a new share called ‘public’ and gave serviio read/write access. No success. I also used a dlna client on my pc but this one also does not see any files. So the tv client is not the problem.

Is it possible to query the derby database? Is there a client installed on the nas? Do you know the port and database name? If its an embedded database, do you know the jdbc string? Would it be possible to turn on debug logging or database logging in serviio?
Any other ideas?

The only thing that doesn’t work is the left click on the serviio icon in the DSM.
If I enter the url of the serviio config it or if I press the icon with a right click and press “open in new window” it works.

Any ideas how to fix it?

Thanks again Patters for this great tutorial. My serviio is running fine for three months now.

thank you Patters for this excellent guide. I applied it successfully on a DS210j with DSM 3.2 (started on 3.1, got a system partition crash, restarted on brand new 3.2)
couple of things that put me back a little:
* the wget thing : I also had to get open-ssl manually
* I assumed java 7 would be good to go, found only in the comments that it was not. Would you make a note about that in the main text ? btw, I tried your package but with no success (modified the scripts to point to correct directories on my box, the package said it installed successfully but did nothing really).
* same as Eric, on DSM 3.2 the DSM integration doesn’t work : nothing happens when clicking the icon.

I’m seeing lots of stuff on my NAS from my Sony Bravia that I didn’t before, so I’m happy… just hopping everything will be ok performance-wise.

After I stopped and deleted the libraries the DSM didn’t work, so i tried to restart my DS 110j.
But it just beeped once an the status LED was flashing orange. The DSM wasn’t running and the Synology Assistant didn’t find my device.
So i pressed the reset button 4secs until the beep and again until the second beep.
After that the Synology Assistant did find the DS again and i could reinstall the DSM.
I lost all my settings but none of my data.

gcc is unable to create an executable file.
If gcc is a cross-compiler, use the –enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from SVN. If the latest version fails, report the problem to theffmpeg-user@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “config.log” produced by configure as this will help
solving the problem.
Teglgaardsvej> make
Makefile:234: /d/java/workspace/ffmpeg/tests/fate.mak: No such file or directory
Makefile:235: /d/java/workspace/ffmpeg/tests/fate2.mak: No such file or directory
Makefile:237: /d/java/workspace/ffmpeg/tests/fate/aac.mak: No such file or directory
Makefile:238: /d/java/workspace/ffmpeg/tests/fate/als.mak: No such file or directory
Makefile:239: /d/java/workspace/ffmpeg/tests/fate/fft.mak: No such file or directory
Makefile:240: /d/java/workspace/ffmpeg/tests/fate/h264.mak: No such file or directory
Makefile:241: /d/java/workspace/ffmpeg/tests/fate/mp3.mak: No such file or directory
Makefile:242: /d/java/workspace/ffmpeg/tests/fate/vorbis.mak: No such file or directory
Makefile:243: /d/java/workspace/ffmpeg/tests/fate/vp8.mak: No such file or directory
make: *** No rule to make target `/d/java/workspace/ffmpeg/tests/fate/vp8.mak’. Stop.