dropcap-dns325-subsonic

Subsonic is a really efficient music streaming server that allows you to share your complete music collection to any internet connected device like laptop, mobile phone or tablet. It can handle on-the-fly transcoding for devices connected to low speed networks like 3G or even Edge networks. You can get a good overview of the possibilities of Subsonic from the project site http://www.subsonic.org/.

Even if Subsonic is very efficient, it is not that easy to install on a device like DNS-325, as it is running under Java (which is CPU and RAM hungry) and as it's supposed to be able to do real time transcoding (which is also very CPU intensive). The main limitation of DNS-325 for this purpose is that it offers a 1.2 GHz ARM processor, with only 256 Mb memory and no Floating Point Unit.

But, with the help of Oracle Java 7 SE Embedded for ARM devices, Shineenc fixed point mp3 encoder and Fraunhofer fdk-aac encoder, it is possible to setup a fully functionnal installation of Subsonic on the DNS-325, including realtime MP3 and AAC transcoding. Yes, realtime transcoding !

So, this article will explain how to do a complete installation of Subsonic music server on a DNS-325. It will deals with the following steps :

* Installation of Oracle Java 7 SE

* Installation & setup of Subsonic

* Setup of a realtime mp3 & aac transcoding chain using ffmpeg, shineenc & libfdk-aac library

* Apache 2 reverse proxy configuration for internet access

This setup has been tested on a mp3 music collection, but it may be applicable for any musical file types accepted by ffmpeg.

As usual, this guide supposes that your DNS-325 is running Fun plug 0.7, an installation procedure being available at DNS 325 - Extend your NAS possibilities with Fun_plug 0.7

Install Oracle Java 7

As Subsonic is running under Java we need to install a small footprint Java Runtime Environment.

Oracle is providing a heavily optimised JRE for ARM devices with Java SE Embedded. It run with as less as 32 Mb memory and doesn't need FPU. So it is perfectly tuned for DNS-325 specs.

You can download the Java SE Embedded 7 on ARMv5 Linux - Headless EABI, SoftFP, Little Endian from http://www.oracle.com/technetwork/java/embedded/downloads/javase/index.html

You need to fill-up a form. You receive an email with the download link.

Download the ejre-7...tar.gz packet to your DNS-325 root home directory.

To install it, run these commands :

# mkdir -p /ffp/opt
# cd /ffp/opt
# tar xfvz /ffp/home/root/ejre-7*.tar.gz
# mv ejre* java

Binaries of Java 7 JRE are now installed and available under /ffp/opt/java/bin.

Install & Configure Subsonic

To install Subsonic you need to :

  • Download the standalone tar.gz package
  • Create subsonic folder
  • Install the package

# wget http://freefr.dl.sourceforge.net/project/subsonic/subsonic/4.5/subsonic-4.5-standalone.tar.gz
# mkdir -p /ffp/opt/subsonic/transcode
# cd /ffp/opt/subsonic
# tar -zxf /ffp/home/root/subsonic-4.5-standalone.tar.gz

We now need to configure Subsonic to our DNS-325 environment, thru the /ffp/opt/subsonic/subsonic.sh file.

You specifically need to adjust the music folder according to the location of your mp3 files.

/ffp/opt/subsonic/subsonic.sh

...

SUBSONIC_HOME=/ffp/opt/subsonic
SUBSONIC_HOST=0.0.0.0
SUBSONIC_PORT=4040
SUBSONIC_HTTPS_PORT=0
SUBSONIC_CONTEXT_PATH=/subsonic
SUBSONIC_MAX_MEMORY=100
SUBSONIC_PIDFILE=/var/run/subsonic.pid
SUBSONIC_DEFAULT_MUSIC_FOLDER=/mnt/HD/HD_a2/music
SUBSONIC_DEFAULT_PODCAST_FOLDER=
SUBSONIC_DEFAULT_PLAYLIST_FOLDER=

...

It's now time to start Subsonic

# /ffp/start/subsonic.sh start

Subsonic Startup Script

For Subsonic to start at every boot, one startup script has to added under /ffp/start

This script /ffp/start/subsonic.sh will be in charge of starting the service at boot and stopping it at shutdown.

# mc -e /ffp/start/subsonic.sh
# chmod +x /ffp/start/subsonic.sh

/ffp/start/subsonic.sh

#!/ffp/bin/sh

# PROVIDE: subsonic
# REQUIRE: LOGIN

# set process PID
SRV_PID="/var/run/subsonic.pid"

. /ffp/etc/ffp.subr
name="subsonic"
start_cmd="subsonic_start"
stop_cmd="subsonic_stop"

subsonic_start()
  {
    # add java & optware (mpg123) to PATH
    export PATH=/ffp/opt/java/bin:/ffp/opt/optware/bin/:$PATH

    # start subsonic
    /ffp/opt/subsonic/subsonic.sh
  }

subsonic_stop()
  {
    # kill running instance from PID
    kill `cat $SRV_PID`

    # delete PID file
    rm $SRV_PID
  }

run_rc_command "$1"

If you reboot your DNS-325 or run the following command Subsonic should start :

# sh /ffp/start/subsonic.sh start

Subsonic daemon takes some time to start the web interface, so be a little bit patient.

After some time, you should be able to connect thru http://your.nas.ip.address:4040/subsonic

On the DNS-325, the Web interface display won't be as reactive as on a proper server, but it should be more than acceptable.

Realtime MP3 Transcoding

When streaming mp3 music to mobile devices like Android smartphone or unsmart iPhone, Subsonic needs to do some real time transcoding to lower bitrate mp3 stream.

On an ARM device like DNS-325 is a real challenge. In fact we are facing 2 main problems :

  • the CPU horse power is not that great
  • it lacks a Floating Point Unit which is heavily used in conversion process

Lame, which is the best and most widespread MP3 encoder, is massively using FPU calculation and as DNS-325 processor is not having FPU, floating point calculations are emulated.

Therefore, given the horse power of the CPU, Lame is typically encoding at 0,5x realtime. It's obviously not suitable for our purpose.

Then comes a little gem : Shine-fixed encoder. This encoder is a port of LAME, done by one of the lame developper, and it's main goal is to get a simple and efficient MP3 encoder, using only fixed point encoding.

That's exactly what is needed by our little DNS-325 ARM processor. Thanks to these choices, Shine-fixed is encoding at almost 4x realtime on the DNS-325 !

Shine-fixed encoding quality is not at the same level as LAME, but it is quite correct, even at 128 kbits.

FFMpeg & Shineenc

If you are not planning to do any type of compilation on your DNS-325, this option is the one for you ! It is using a pre-compiled shineenc binary, that I've compiled from git://github.com/savonet/shine.

One slight problem with shineenc is that it only takes RIFF WAV files as an input. So, we will need to use a first stage mp3 decoder to feed it.

To be able to feed any type of audio file, the best audio decoder will be ffmpeg. It is very robust, very fast as a decoder and is available from slacker declared repositories.

So lets start to install ffmpeg and shineenc pre-compiled binaries.

# wget http://bernaerts.dyndns.org/download/dns-325/shineenc
# mv ./shineenc /ffp/bin/shineenc
# chmod +x /ffp/bin/shineenc
# slacker -a memiks:ffmpeg

From the list, select package memiks:ffmpeg... .txz and click OK to install.

Make sure ffmpeg is having all dependencies installed by starting it once as command line.

# ffmpeg
ffmpeg version 0.10 Copyright (c) 2000-2012 the FFmpeg developers
built on Mar 29 2012 19:17:45 with gcc 4.6.2
configuration: --prefix=/ffp --enable-pic --enable-zlib --enable-swscale --enable-decoder=h264 --enable-decoder=mpeg1video --enable-decoder=mpeg2video --enable-decoder=mpeg4 --enable-decoder=msmpeg4v1 --enable-decoder=msmpeg4v2 --enable-decoder=msmpeg4v3 --enable-decoder=vp6f --enable-decoder=vp8 --enable-decoder=wmv1 --enable-decoder=wmv2 --enable-decoder=wmv3 --enable-decoder=rawvideo --enable-decoder=mjpeg --enable-decoder=mjpegb --enable-decoder=vc1 --enable-decoder=aac --enable-decoder=ac3 --enable-decoder=dca --enable-decoder=mp3 --enable-decoder=mp2 --enable-decoder=vorbis --enable-decoder=wmapro --enable-decoder=wmav1 --enable-decoder=flv --enable-decoder=wmav2 --enable-decoder=wmavoice --enable-decoder=pcm_dvd --enable-decoder=pcm_s16be --enable-decoder=pcm_s16le --enable-decoder=pcm_s24be --enable-decoder=pcm_s24le --enable-decoder=ass --enable-decoder=dvbsub --enable-decoder=dvdsub --enable-decoder=pgssub --enable-decoder=xsub --enable-parser=aac --enable-parser=ac3 --enable-parser=dca --enable- libavutil 51. 34.101 / 51. 34.101
libavcodec 53. 60.100 / 53. 60.100
libavformat 53. 31.100 / 53. 31.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 60.100 / 2. 60.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
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'

The transcoding tools are now installed.

When used to transcode files to WAV, ffmpeg is having a problem to create a proper RIFF header, acceptable by shineenc.

To be able to feed shineenc we need to create a script that will be used to generate a fully compliant WAV file. It will :

  • send a proper RIFF header
  • call ffmpeg to convert the file
  • remove the faulty header from ffmpeg resulting stream

# mc -e /ffp/opt/subsonic/transcode/convert2wav4shineenc
# chmod +x /ffp/opt/subsonic/transcode/convert2wav4shineenc

/ffp/opt/subsonic/transcode/convert2wav4shineenc

#!/ffp/bin/sh
#
# Convert a file to WAV format using ffmpeg
# Conversion is sent to STDOUT and forced to stereo, 16 bits and 44100 kHz
# RIFF header if corrected to feed shineenc
#   $1 = file path
#
# 05/10/2012 - V1.0 by Nicolas Bernaerts

# Set PATH
PATH=/ffp/sbin:/ffp/bin

# Definition of a proper RIFF header
RIFF_HEX="524946460000000057415645666D7420100000000100020044AC000010B102000400100064617461"

# Send proper header, converted to binary
echo $RIFF_HEX | xxd -r -p

# Convert input file with ffmpeg, skipping the first 44 bytes as they contain the faulty header
ffmpeg -i "$1" -f wav -acodec pcm_s16le -ac 2 -ar 44100 - | dd ibs=44 obs=512 skip=1

Finally, the transcoding script that will be called from subsonic has to be declared under /ffp/opt/subsonic/transcode/shine-transcode2mp3 :

# mc -e /ffp/opt/subsonic/transcode/shine-transcode2mp3
# chmod +x /ffp/opt/subsonic/transcode/shine-transcode2mp3

/ffp/opt/subsonic/transcode/shine-transcode2mp3

#!/ffp/bin/sh
#
# Subsonic mp3 transcoding script, using ffmpeg & shineenc
# $1 : bitrate in kbits (64, 128, ...)
# $2 : original file name
#
# 12/09/2012, V1.0 - Creation by N. Bernaerts
# 05/10/2012, V2.0 - Use ffmpeg instead of mpg123, as it is more robust and canfeed any audio file

# Set PATH
PATH=/ffp/sbin:/ffp/bin

# Convert input file to WAV with proper RIFF & feed it to shineenc
/ffp/opt/subsonic/transcode/convert2wav4shineenc "$2" | shineenc -b $1 - -

Everything is now ready.

You just need to connect to Subsonic administration interface and to declare the Transcode & Downsample commands as shine-transcode2mp3 %b %s

dns325-subsonic-shine-transcode-mp3

Transcoding has been tested on ogg, flac, aac & mp3 source audio files.

FFMpeg & Libshine Library

This solution is using the same shineenc encoder, but as a ffmpeg library.

As ffmpeg embedding shineenc library is not available from any repository, we have to compile it.

A complete compilation guide is available from DNS 325 - Funplug 0.7 : Compile latest lame, shineenc, fdk-aac, x264, ffmpeg & sox.

You should finally have a brand new ffmpeg binary including a very fast libshine encoder, transcoding at 4x realtime on your DNS-325.

The subsonic transcoding script has to be declared under /ffp/opt/subsonic/transcode/ffmpeg-transcode2mp3 :

# mc -e /ffp/opt/subsonic/transcode/ffmpeg-transcode2mp3
# chmod +x /ffp/opt/subsonic/transcode/ffmpeg-transcode2mp3

/ffp/opt/subsonic/transcode/ffmpeg-transcode2mp3

#!/ffp/bin/sh
#
# Subsonic mp3 transcoding script, using ffmpeg compiled with shine library
# $1 : bitrate in kbits (64, 128, ...)
# $2 : original file name
#
# 18/10/2012, V1.0 - Creation by N. Bernaerts
# 23/10/2012, V1.1 - Force stream mapping to avoid problem with mp3 source embedding art cover

# Set PATH
PATH=/ffp/sbin:/ffp/bin

# Convert input file to MP3
ffmpeg -i "$2" -f mp3 -acodec libshine -map 0:0 -b:a $1k -ac 2 -

You now need to connect to Subsonic administration interface and to declare the Transcode & Downsample commands as ffmpeg-transcode2mp3 %b %s

dns325-subsonic-ffmpeg-transcode-mp3

You can now use this mp3 transcoding chain for any subsonic client.

Realtime AAC Transcoding

This solution is using the very high quality Fraunhoser fdk-aac library, which has been open-sourced by Google early this year.

This encoder is highly optimised for ARM processors, using only fixed point conversion.

Quality wise, it's a real pleasure to listen to any type of music at bitrates as low as 128 kbits.

As FFMpeg including this library is not available from any repository, it should be compiled following the guide DNS 325 - Funplug 0.7 : Compile latest lame, shineenc, fdk-aac, x264, ffmpeg & sox.

You should finally have a brand new ffmpeg binary including a very fast fdk-aac encoder, transcoding at almost 4x realtime on your DNS-325.

The subsonic transcoding script has to be declared under /ffp/opt/subsonic/transcode/ffmpeg-transcode2aac :

# mc -e /ffp/opt/subsonic/transcode/ffmpeg-transcode2aac
# chmod +x /ffp/opt/subsonic/transcode/ffmpeg-transcode2aac

/ffp/opt/subsonic/transcode/ffmpeg-transcode2aac

#!/ffp/bin/sh
#
# Subsonic mp3 transcoding script, using ffmpeg compiled with fdk-aac library
# $1 : bitrate in kbits (64, 128, ...)
# $2 : original file name
#
# 18/10/2012, V1.0 - Creation by N. Bernaerts
# 23/10/2012, V1.1 - Force stream mapping to avoid problem with mp3 source embedding art cover

# Set PATH
PATH=/ffp/sbin:/ffp/bin

# Convert input file to AAC
ffmpeg -i "$2" -f adts -acodec libfdk_aac -map 0:0 -b:a $1k -ac 2 -

You now need to connect to Subsonic administration interface and to declare the Transcode command as ffmpeg-transcode2aac %b %s

dns325-subsonic-ffmpeg-transcode-aac

You can now use this high quality aac transcoding chain for your android subsonic client.

As AAC file format is not having a header with the file length, your subsonic client will have difficulty to play a file while it is downloading.
In fact, it will only play the length of the file received when the play started.
So to play a complete album without problem, it's better to wait for the first number to be fully downloaded before playing it.
It won't be a problem for following numbers, as they will be downloaded while playing the first one.

Apache 2 Reverse Proxy Configuration

In case your DNS-325 is not directly connected to internet, you may have an Apache 2 server as an Internet frontend.

If so, you can configure it as a reverse proxy to stream your DNS-325 Subsonic music.

If you are having this type of setup, Apache2 reverse proxy should look like this :

/etc/apache2/sites-enabled/mysite

<VirtualHost *:80>
  ServerAdmin ...
  ServerName  ...

  ProxyPass         /subsonic    http://your.nas.ip.address:4040/subsonic
  ProxyPassReverse  /subsonic    http://your.nas.ip.address:4040/subsonic

...
</VirtualHost>

 

You are now ready to stream some downsampled MP3 or AAC files to any device with a Subsonic client thru your 3G connexion straight from your DNS-325.

Enjoy !

Signature Genealogie

Cette base généalogique est gérée et maintenue à jour par This email address is being protected from spambots. You need JavaScript enabled to view it.
Merci d'avance pour toute correction, complément ou information nouvelle que vous pourriez lui fournir.