How to install and optimize subsonic on a Qnap NAS Server

Tutorials, tips and tricks.

Moderator: moderators

How to install and optimize subsonic on a Qnap NAS Server

Postby Morkeleb » Sun Apr 24, 2011 11:38 pm

Hello.

I've put a lot of work in installing and optimizing subsonic on a Qnap NAS linux based System. This is especially targeted at the Atom processor based models, but it should probably also work on others (but this guide is not tailored to those). My model is the Qnap TS 459 Pro which has a dual core Atom processor.
I have done this on one having a firmware version 3.4.0

By default a Qnap NAS system does not come with java and tomcat. You have to install those first.

1) Installing the basic software
* Log into your Qnap Adminstration web interface and to to Application Servers->QPKG Plugins and click on "GET QPKG". A window with a list of available packages should open.

* Select "Java Runtime Environment" and download that zip file (at the time of writing: http://eu1.qnap.com/Storage/QPKG/X86/JRE_6_X86.zip)

* Select "Tomcat" and download the zip file (at the time of writing: http://eu1.qnap.com/Storage/QPKG/X86/To ... 20_x86.zip)

* Select "Optware IPKG" and download optware (at the time of writing for intel systems: http://eu1.qnap.com/Storage/QPKG/X86/Op ... 63_x86.zip).

* Click on tab "INSTALLATION" in the main window (where you clicked GET QPKG before) and click the button to browse for a file an select the downloaded java zip file. Click INSTALL.

* You may need to reboot the NAS, not sure though. Now do the same with the downloaded tomcat zip file (brows it and click INSTALL).

* Enable tomcat by clicking on QPKG INSTALLED and then Tomcat. On the opening window click the button ENABLE.

* Install Optware: Install this package the same way as the others in the INSTALLATION tab. This allows you to install additonal linux software packages on your Qnap system. You will need it to install a usable command line text editor and transcoding software.

* Reboot your Qnap NAS.

* Go to the QPKG Plugins page again, click Tomcat and click the link beside "Web Page".

2) Configuring Tomcat and installing Subsonic
* Before installing Subsonic you should configure tomcat manager users. Do so by modifying the tomcat-users.xml file that is found on your Qnap system now. It is advisable to log in to your Qnap using ssh (i recommend Putty under windows) with your admin user. It should be located in /share/MD0_DATA/.qpkg/Tomcat/tomcat/conf/tomcat-users.xml
I find it most convenient to installing the nano console editor by typing "ipkg install nano". You need the Optware package installed for this. Also, if it does not find the command ipkg then you have to apply some fixes to the paths. See section 3) for that
Type nano <file-path> to edit the file you wish, in this case the full path to tomcat-uses.xml.
For me I have the following roles and users configured there:
Code: Select all
  <role rolename="tomcat"/>
  <role rolename="manager"/>
  <user username="tomcat" password="<password for user tomcat>" roles="tomcat"/>
  <user username="admin" password="<password for user manager>" roles="manager"/>

(to save exit nano and save the file type ctrl-X and then Y)

* On the opened Apache Tomcat web page click on "Tomcat Manager". You will have to log in with a user you configured in your tomcat-users.xml file.

* Download the latest subsonic war release (go to http://www.subsonic.org/pages/download.jsp and click download at the "WAR version (all platforms)".

* On the Tomcat Manager page scroll down, select the war file in "select WAR file to upload" and click Deploy.

* Subsonic should not be installed and be listed in the "Applications" list. Just click the link /subsonic.

If all worked well you have now installed subsonic.

However, there is a problem on Qnap Systems. After rebooting your Qnap NAS all your subsonic settings will be gone.
This is because subsonic settings are by default stored in a place that are cleaned up on reboot.
You have to move the location to they remain permanent:

* You need to be logged in via ssh to your Qnap NAS again.

* Subsonic is installed in /var/subsonic. Copy that to /share/MD0_DATA/subsonic (/share/MD0_DATA is the location of your harddrive-array were you store all your data). To do this type cp -r /var/subsonic /share/MD0_DATA/subsonic.

* Now remove the original subsonic data by typing rm -rf /var/subsonic.

* Since subsonic will still look for the data in /var/subsonic create a symbolic link from your real new subsonic data to the one where subsonic looks by typing ln -s /share/MD0_DATA/subsonic /var/subsonic

* However, even this symbolic link will be removed upon restart. So you must instruct the system to create it once tomcat starts up if it is not there yet. The startup of tomcat is controlled with the file tomcat.sh. Open it with nano: nano /etc/init.d/tomcat.sh

* Search for the lines
case "$1" in
start)
and add the following below
Code: Select all
### Create Subsonic link in /var
        if [ ! -e /var/subsonic ]; then
                ln -s /share/MD0_DATA/subsonic /var/subsonic
        fi
### End of Subconic link creation

* Save the file (type ctrl+X and then Y to save)

* If you have problems staring up subsonic from the tomcat manager page this may be because of the owner of subsonic. In such a case (I myself cannot remember having it), execute this command:

chown -R tomcat /share/MD0_DATA/subsonic /var/subsonic

This tip came from cxc4u, thanx for this!

3) fixing opt paths (optional, when required)
Some Qnap systems have a bug that the /opt folder is not added to the path. Here is how to modify the optware startup accordingly:

* Open Optware.sh (nano /etc/init.d/Optware.sh)

* Search for the line (you can use ctrl-W for that)
# adding Ipkg apps into system path ...
and replace it with the code below until before the lines
;;
stop)
Code: Select all
        # adding Ipkg apps into system path ...
        /bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
        # Bug fix for following: put IPKG first, per http://forum.qnap.com/viewtopic.php?f=124&t=15663
        # was [ $? -ne 0 ] && /bin/echo "export PATH=$PATH":/opt/bin:/opt/sbin >> /etc/profile
        [ $? -ne 0 ] && /bin/echo "export PATH=/opt/bin:/opt/sbin:\$PATH" >> /etc/profile

        # Added by Lukas Oesterreicher to enable finding any /opt libraries
        /bin/echo "/opt/lib" >> /etc/ld.so.conf
        /bin/echo "/opt/local/lib" >> /etc/ld.so.conf
        # uncomment line below only if you have libc-dev installed and need the libraries
        #/bin/echo "/opt/i686-unknown-linux-gnu/lib" >> /etc/ld.so.conf
        /sbin/ldconfig

        # Patch per http://wiki.qnap.com/wiki/Install_Optware_IPKG
        /bin/echo "Run Optware/ipkg /opt/etc/init.d/*"
        source /etc/profile
        # Start all init scripts in /opt/etc/init.d
        # executing them in numerical order.
        #
        for i in /opt/etc/init.d/S??* ;do
            # Ignore dangling symlinks (if any).
            #[ ! -f "$i" ] && continue

            case "$i" in
                *.sh)
                    # Source shell script for speed.
                    (
                        trap - INT QUIT TSTP
                        set start
                        . $i
                    )
                ;;
                *)
                    # No sh extension, so fork subprocess.
                    $i start
                ;;
            esac
        done
        # End patch


Plase note that this code is not perfect. Currently for instance it appends to /etc/ld.so.conf creating duplicate lines with each reboot or restart of the service. You are free to suggest corrected code!

* Save the changes (ctrl-X and then Y)

* The changes only become effective either after restarting optware (/etc/init.d/Optware.sh restart) or restarting the whole NAS and loggin in with ssh again.

Now subsonic should be set up and data should be maintained.

This is the end of the basic guide. The next post will contain advanced setup so transcoding is supported and improved video streaming over the standard recommended ffmpe, using a modified build of mplayer2 that also supports encoding.

A basic instruction (that misses some details but on which I based my efforts on) can be found here: http://forum.subsonic.org/forum/viewtopic.php?t=1851

Hope this helped you get Subsonic running.
Last edited by Morkeleb on Wed Jun 15, 2011 8:43 pm, edited 7 times in total.
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

installing transcoding support for subsonic

Postby Morkeleb » Sun Apr 24, 2011 11:51 pm

Note: These intstructions may not cover everything 100% since i had to write some from memory.
I also recently added more details and the section on compiling a current version of perl with threads which is required.

This post covers:
* Installing basic requirements to transcode and stream (ffmpeg and lame). This is needed to transcode audio files to different bitrates and stream videos.

* Getting advances streaming to work. This is only needed if you are not satisfied with the video quality or the CPU power of your NAS does not suffice for better video encoding. For instance with ffmpeg it is not possible to stream 720p h264 videos in real time. With the advanced mplayer2 solution this will be possible if you have a dual-core Atom NAS (or better).

1) Installing lame:
* install lame with the command "ipkg install lame"
* if it does not exist yet, creat the transcode directory where all transcoding applications of subsonic are found: mkdir /var/subsonic/transcode
* link to lame so subsonic finds it: ln -s /opt/bin/lame /var/subsonic/transcode/lame

2) Installing ffmpeg
* Install ffmpeg: "ipkg install ffmpeg"
* link to it: ln -s /opt/bin/ffmpeg /var/subsonic/transcode/ffmpeg

3) getting, compiling and configuring mplayer2.
Basic info: Why this modified mplayer2 and not just use ffmpeg or mplayer/mencoder?
Well, ffmpeg has a feature you need: encode to flash video (or mp4), but ffmpeg lacks really good multi-threaded video decoding (it never worked for me, even with the pthreads option enabled), which you will need to be able to decode 720p h264 files in real time.
On the other hand, mencoder does support proper fast multithreaded decoding, but cannot output to flv (or mp4) properly. I tried and it either dos not work or causes mencoder to crash.

mplayer2 with encoding extension added can do both!
Since this is somthing thing that is not official yet, you cannot get pre-built binarys yet, so you have to get the sources and compile it.

Basics on mplayer2: http://www.mplayer2.org/ (in short: mplayer2 is a new improved version of mplayer which allows playing and converting of media files. mplayer2 is not yet very common, but with encoding support provided by divVerent it is a much better option compared to ffmpeg)

* Prepare your system for compiling:
First you have to install all the packages needed so you can compile, all of which are available as packages. Here is a list of the commands I used (I got the basics here but extended them: http://forum.qnap.com/viewtopic.php?f=177&t=32731):
Code: Select all
ipkg install make bash svn automake autoconf mktemp grep bzip2 yasm coreutils glib libtool libcurl libgsm libogg libtheora libvorbis libmatroska libmpeg2 perl ncurses pkgconfig freetype fontconfig tar optware-devel nano


Note, you may want/nedd to execute "rm /bin/mktemp" temporarily after this

also, if you want aac audio decoding, do this:
ipkg install faad2
(you can get the sources and compile the latest version if you want, alternatively: http://www.audiocoding.com/downloads.html)

* get, compile and install pre-requisites for mplayer2
Since mplayer2 (and for that matter also ffmpeg and mplayer) depend on libraries that do the decoding and encoding, we need to compile some of the important ones ourselves, since either packages are not available or outdated.

you will want x264 (for h.264 avc video encofding), faac (aac audio encoding) and if you want, xvid for mpeg-4 encoding.
We will do all the downloading and then compiling in /opt/etc:

You may want to tell the comiler to optimize compilation :

Code: Select all
export CFLAGS="-O3 -march=i686 -mtune=i686"
export CXXFLAGS="${CFLAGS}"


x264:
------
I did not manage to get the current version to work.
It will crash some time into the encoding process (depending on source).
This is not an issue of x264 itself, but of the available gcc compiler being
outdated and buggy.
I found that one of the latest snapsots of x264 that work correctly is
the first of 2011. So:

Code: Select all
cd /opt/etc/
wget http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20110101-2245.tar.bz2
tar -xvf x264-snapshot-20110101-2245.tar.bz2
cd x264-snapshot-20110101-2245
./configure --prefix=/opt
make
make install


Please note to always add --prefix=/opt for configuring, since that is where you want to have all your software installed instead of the default location.

faac (if you want to comile faad2, that looks almost identical):
-----

Code: Select all
cd /opt/etc/
wget http://switch.dl.sourceforge.net/sourceforge/faac/faac-1.28.tar.gz
tar -xvf faac-1.28.tar.gz
cd /opt/etc/faac-1.28
./configure --prefix=/opt
make
make install


optional: xvid
---------------
Code: Select all
cd /opt/etc/
wget http://downloads.xvid.org/downloads/xvidcore-1.2.2.tar.gz
tar -xvf xvidcore-1.2.2.tar.gz
cd /opt/etc/xvidcore/build/generic/
./configure --prefix=/opt
make
make install


Please note that the latest version of xvid is currently 1.3.1, however for that to compile (actually configure, i think) correctly, you will need some updated software.
I'm not sure which anymore, but possibly gawk or perl, or maybe sed.
If you want the latest version, replace the version in the code above, and first try with
ipkg install gawk
ipkg install sed

It may be that xvid 1.3.1 also needs a current perl, I am not sure.

* Compile a current version of perl that supports threads
Unfortunately some components of mplayer2 require a current version of perl that supports threading,
which is not the case with the version of perl that can be installed using ipgk.

Here the steps to compile and install perl:
Code: Select all
# download sources
cd /opt/etc/
wget http://www.cpan.org/src/5.0/perl-5.12.3.tar.gz
tar -xvf perl-5.12.3.tar.gz
cd /opt/etc/perl-5.12.3

# perl searches for errno.h only at a few predefined places where we do not have it.
# Fix this by replacing these lines
   my $linux_errno_h = -e '/usr/include/errno.h' ?
       '/usr/include/errno.h' : '/usr/local/include/errno.h';
with this:
   my $linux_errno_h = -e '/usr/include/errno.h' ?
       '/usr/include/errno.h' : -e '/usr/local/include/errno.h' ? '/usr/local/include/errno.h' : '/opt/include/errno.h';
in file ext/Errno/Errno_pm.PL in the perl sources directory

# configure perl: (-de: not to enter each question manually, -Dcc=gcc: to tell we use the gcc compiler, prefix that we want to intall to opt, and -Dusethreads that thread support is to be addedd)
./Configure -de -Dcc=gcc -Dprefix=/opt -Dusethreads

# compile and install:
make
make install


* get "git"
Git is a version control system. Mplayer2 sources are available through git.
You need the git client to check out the sources.
Normally it should be enough to install git with

ipkg install git

However while I did my second install (after loosing some data because of accidentally deleting it),
git was not avaailable in the ipkg repository, so I had to compile git myself, using these commands:

Code: Select all
# prerequisites
ipkg install tcl python libcurl-dev openssl openssl-dev sed gawk

ln -s /opt/bin/perl /usr/bin/perl
ln -s /opt/bin/python /usr/bin/python

# get sources
cd /opt/etc/
wget http://kernel.org/pub/software/scm/git/git-1.7.5.tar.bz2
cd /opt/etc/git-1.7.5

# configure, compile and install
./configure --prefix=/opt
make
make install


* get, compile and install mplayer2
Now we got all the prerequisites, we go on to the main point, mplayer2 enhanced with divVerent's encoding features: https://github.com/divVerent/mplayer/wi ... au-vo-lavc

If you have trouble along the way, log in to IRC server irc.freenode.net and join channel #mplayer2. I recommend the MIRC client for that.
Also, some more information on my own problems and progress is documented here:
http://forum.qnap.com/viewtopic.php?f=4 ... 41#p192041

Now, for mplayer2:
Code: Select all
git clone git://git.mplayer2.org/mplayer2-build.git
cd mplayer2-build
./init


Then you will want to configure the features with which you want mplayer2 and ffmpeg (which is used by mplayer2) compiled.
Just add the line "--prefix=/opt) to mplayer_options (use nano).

And I recommend those for ffmpeg_options (no --prefix=/opt here because it shall be installed locally only):
Code: Select all
--enable-static
--disable-shared
--enable-pthreads
--enable-nonfree
--enable-libmp3lame
--enable-libx264
--enable-libfaac
--enable-libxvid
--enable-libvorbis
--enable-libtheora
--enable-decoder=aac

(do not add --enable-libx264 if you did not compile xvid before)

then continue with getting divVerents encoding modifications and start the compile and finally install:
Code: Select all
cd mplayer
git remote add -f divVerent git://github.com/divVerent/mplayer.git
git checkout -t -b divVerent/mplayer-uau-vo-lavc divVerent/divVerent/mplayer-uau-vo-lavc
cd ..
make
make install


If you only want to compile or re-compile portions of mplayer2, there a list of commands for each component:
Note: if leave out --prefix=/opt of the ffmpeg configuration unless you want to install this ffmpeg in your system.
Code: Select all
mkdir ffmpeg_build
cd ffmpeg_build
../ffmpeg-mt/configure --prefix=/opt --enable-gpl --disable-debug --enable-pthreads --disable-shared --enable-static --enable-postproc --enable-nonfree --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-libfaac --enable-decoder=aac
make
make install
cd ..

cd libass
./autogen.sh --prefix=/opt
make
make install
cd ..

cd mplayer
./configure --prefix=/opt
make
make install


* configure use of mplayer2
Now, I hope you did not run into troubles with compilation anywhere. If you did, please report this to me, so I can ajust this documentation so it instructs accordingly so all runs well).

Now that we have mplayer2, we can almost start using it.

I have spend many hours tweaking settings for mplayer2, so it gets the best quality at certain bitrates and is still fast enough.
You can take a short-cut here and use my shell script:

Code: Select all
#!/bin/sh

# $1=offset in seconds
# $2=source file
# $3 bitrate in kbit/s
# $4 width in pixels (optional, currently ignored and derived from height and aspect ratio)
# $5 hight in pixels (optional, currently ignored and derived from bitrate)
# $6 output: if provided output file name, if not provided output is sdtout
offset=$1; source=$2; bitrate=$3; width=$4; height=$5; output=$6;

VIDEO_METADATA=$(/var/subsonic/transcode/mplayer -vo null -ao null -frames 0 -identify "$source" 2>/dev/null | /opt/bin/sed -ne '/^ID_/ { s/[]()|&;<>`'"'"'\\!$" []/\\&/g;p }')

VIDEO_FPS=$(echo "$VIDEO_METADATA" | /opt/bin/sed -n 's/^ID_VIDEO_FPS=//p' | /opt/bin/sed 's/\.//g')
VIDEO_WIDTH=$(echo "$VIDEO_METADATA" | /opt/bin/sed -n 's/^ID_VIDEO_WIDTH=//p')
VIDEO_HEIGHT=$(echo "$VIDEO_METADATA" | /opt/bin/sed -n 's/^ID_VIDEO_HEIGHT=//p')

#echo VIDEO_FPS=$VIDEO_FPS
#echo VIDEO_WIDTH=$VIDEO_WIDTH
#echo VIDEO_WIDTH=$VIDEO_WIDTH

if [ $VIDEO_HEIGHT -gt 480 ]; then
  FASTDECODING="-lavdopts threads=4:fast:skiploopfilter=all"
else
  FASTDECODING="-lavdopts threads=4:fast"
fi

if [ $VIDEO_FPS -ge 100000 ]; then
  FPS_OPTION="-ofps 24000/1001";
else
  FPS_OPTION="-oautofps";
fi

SRATE=44100

if [ $bitrate -le 200 ]; then
  MAXRATE=100k; CRF=23; AUDIORATE=64k; VERT_RES=160; SRATE=22050
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@fast; else SPEEED=@slow; fi
elif [ $bitrate -le 300 ]; then
  MAXRATE=300k; CRF=22; AUDIORATE=64k; VERT_RES=192; SRATE=22050
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@faster; else SPEEED=@medium; fi
elif [ $bitrate -le 400 ]; then
  MAXRATE=400k; CRF=22; AUDIORATE=80k; VERT_RES=240;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@superfast; else SPEEED=@faster; fi
elif [ $bitrate -le 500 ]; then
  MAXRATE=500k; CRF=22; AUDIORATE=96k; VERT_RES=288;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@superfast; else SPEEED=@faster; fi
elif [ $bitrate -le 700 ]; then
  MAXRATE=700k; CRF=22; AUDIORATE=96k; VERT_RES=320;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@superfast; else SPEEED=@faster; fi
elif [ $bitrate -le 1000 ]; then
  MAXRATE=1000k; CRF=21; AUDIORATE=112k; VERT_RES=384;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@ultrafast; else SPEEED=@veryfast; fi
elif [ $bitrate -le 1200 ]; then
  MAXRATE=1200k; CRF=21; AUDIORATE=128k; VERT_RES=408;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@ultrafast; else SPEEED=@superfast; fi
elif [ $bitrate -le 1500 ]; then
  MAXRATE=1500k; CRF=21; AUDIORATE=144k; VERT_RES=432; FASTDECODE=@fastdecode,;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@ultrafast; else SPEEED=@superfast; fi
elif [ $bitrate -le 2000 ]; then
  MAXRATE=2000k; CRF=21; AUDIORATE=160k; VERT_RES=448; FASTDECODE=@fastdecode,;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@ultrafast; else SPEEED=@superfast; fi
else
  MAXRATE=3000k; CRF=20; AUDIORATE=160k; VERT_RES=448; FASTDECODE=@fastdecode,;
  if [ $VIDEO_HEIGHT -gt 480 ]; then SPEEED=@ultrafast; else SPEEED=@superfast; fi
fi

ASPECT=$(($VIDEO_WIDTH / $(($VIDEO_HEIGHT / 10))))

if [ $ASPECT -lt 15 ]; then
  HOR_RES=$(($(($VERT_RES * 15)) / 10))
  SCALE="-aspect $HOR_RES/$VERT_RES -vf scale=$HOR_RES:$VERT_RES"
elif [ $ASPECT -gt 18 ]; then
  HOR_RES=$(($(($VERT_RES * 18)) / 10))
  SCALE="-aspect $HOR_RES/$VERT_RES -vf scale=$HOR_RES:$VERT_RES"
else
  SCALE="-vf scale=-2:$VERT_RES"
fi

INPUT_OPTIONS="$FASTDECODING -af volnorm -channels 2 -srate $SRATE"
AUDIO_ENCODING="-oac aac -oacopts b=$AUDIORATE"
VIDEO_ENCODING="-ovc libx264 -ovcopts $SPEEED,@film,${FASTDECODE}@baseline,level=30,threads=4,maxrate=$MAXRATE,bufsize=10000k,rc_init_occupancy=9800k,crf=$CRF"
#VIDEO_ENCODING="-ovc flv -ovcopts b=${bitrate}k"
OUTPUT_OPTIONS="$SCALE -sws 0 $FPS_OPTION -of flv"

# if we did not want different loggin options depending on streaming or not, we may be able to use use -o "${6-/dev/fd/3}"
if [ -z "$output" ]; then
echo "/opt/bin/mplayer -ss $offset \"$source\" $INPUT_OPTIONS $AUDIO_ENCODING $VIDEO_ENCODING $OUTPUT_OPTIONS -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log" >>/var/subsonic/transcode/logs.log
/opt/bin/mplayer -ss $offset "$source" $INPUT_OPTIONS $AUDIO_ENCODING $VIDEO_ENCODING $OUTPUT_OPTIONS -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log
else
echo "/opt/bin/mplayer -ss $offset \"$source\" $INPUT_OPTIONS $AUDIO_ENCODING $VIDEO_ENCODING $OUTPUT_OPTIONS -o \"$output\""
/opt/bin/mplayer -ss $offset "$source" $INPUT_OPTIONS $AUDIO_ENCODING $VIDEO_ENCODING $OUTPUT_OPTIONS -o "$output"
fi


Create a file /var/subsonic/transcode/streamflv and put the above code into it.
then make it executable with chmod 775 /var/subsonic/transcode/streamflv

You may want to test it first on command line. Try a command like this:
/var/subsonic/transcode/streamflv 0 <your source file> 1000 - - <your destination file.flv>

The first parameter is the offset into the video in seconds where to start encoding, the second the source file (provide double-quotes around it if the file name has spaces), the third paramter is the bitrate (will ajust encoding details in steps: 200, 300, 400, 500, 700, 1000, 1200, 1500, 2000 and above). The forth and fifth option are height and width, but those are ignored in this script currently and unless you need to provide the 6th parameter you can leave them out). The 6th parameter is the optional output file.

It should transcode and show you log output on the transcoding process. When you call it without the last parameter like you will do in subsonic, it will output the encoded video to standard out so subsonic can stream it on to the flash player.

If it works, you can configure the transcoding settings of subsonic:
Anywhere where it is about video encoding (where "Convert to" is "flv") you replace the existing content of "Step 1" with "streamflv %o %s %b %w %h".

Now, if streaming does not work, try restarting tomcat like this:
/etc/init.d/tomcat.sh restart

If it still does not work, first check the conents of
/var/subsonic/transcode/logs.log
and then
/var/subsonic/transcode/errors.log

For hints on what went wrong.

Please provide feedback if the instructions worked for you!
I wrote part of this right from the head and may have forgotten details.

Cheers!
Last edited by Morkeleb on Wed Jun 15, 2011 8:05 pm, edited 4 times in total.
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Postby cxc4u » Mon Apr 25, 2011 6:28 pm

Thx for posting Morkeleb! I just got a TS-459pro+ and had to go through the old instructions the hard way. This should be the authoritative source going forward for QNAP x86-based NAS'es!
cxc4u
 
Posts: 6
Joined: Mon Apr 25, 2011 6:26 pm
Location: United States

Postby Morkeleb » Tue Apr 26, 2011 8:58 pm

thanx!
i hope a few others find it helpful, since i put all this work into it!
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Postby Morkeleb » Tue Apr 26, 2011 9:10 pm

Btw.

The android client is usable, but has quite a few issues I think:

http://forum.subsonic.org/forum/viewtop ... 4878#24878

Hopefully that is being worked on!
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Postby kimwatson » Tue May 03, 2011 11:50 am

Just wanted to thank you for the awesome effort on this. Cheers matey. It helped out a lot.
kimwatson
 
Posts: 1
Joined: Tue May 03, 2011 11:42 am

Postby 3R3 » Tue May 03, 2011 6:39 pm

I added your thread to the unofficial Compatibility list for Subsonic on a NAS
Thx for the great guide, cant test it though.

regards,
3R3
User avatar
3R3
 
Posts: 332
Joined: Mon May 04, 2009 2:09 pm
Location: Germany

Postby GARGANCHUAN » Fri Jun 10, 2011 12:37 am

Hey Morkeleb,

Thanks for putting this together! I followed the instructions as best as I could, but there seems to be a problem when I make the mplayer build. Here are the last bunch of lines:

Code: Select all

...

make[1]: Leaving directory `/share/HDA_DATA/.qpkg/Optware/etc/mplayer2-build/ffmpeg_build'
script/libass-config
Running autoreconf...
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I m4 --output=aclocal.m4t
This Perl not built to support threads
Compilation failed in require at /opt/share/automake-1.11/Automake/ChannelDefs.pm line 23.
BEGIN failed--compilation aborted at /opt/share/automake-1.11/Automake/ChannelDefs.pm line 26.
Compilation failed in require at /opt/share/automake-1.11/Automake/Configure_ac.pm line 26.
BEGIN failed--compilation aborted at /opt/share/automake-1.11/Automake/Configure_ac.pm line 26.
Compilation failed in require at /opt/bin/aclocal line 39.
BEGIN failed--compilation aborted at /opt/bin/aclocal line 39.
autoreconf: aclocal failed with exit status: 255
Running configure...
./autogen.sh: line 5: ./configure: No such file or directory
make: *** [libass-config] Error 127
[/opt/etc/mplayer2-build] #


Is this a perl problem? I'm not sure how to compile a newer build for the QNAP. Got any pointers?

Much thanks,
Justin
GARGANCHUAN
 
Posts: 2
Joined: Thu Aug 19, 2010 11:17 pm

Postby Morkeleb » Wed Jun 15, 2011 7:15 pm

Yes, it is indeed a perl problem.
I found out you really need to compile a newer version of perl that supports threading for mplayer to proplerly compile.

I have updated the instructions to include this.
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Postby Morkeleb » Wed Jun 15, 2011 8:37 pm

Hello again all.

I have now got some more advanced stuff:
- Transcoding audio to other formats, such as ogg or mp4.
- Boost audio volume so you can hear silent parts better. This is especially helpful when the audio is rather silent to begin with or if you are listening in noisy environment

Please note:
- I have not tested ogg and mp4 properly (I actually dont understand how you can choose in subsonic to which format to transcode to, Also aac may not work, I am just providing some scripts here).
- The audio quality of the standard free aac encoder is rather bad, and may be even worse than lame. I recommend to use a better aac encoder, such as that of nero

Requirements
* For good AAC, get the nero aac coder from here: http://www.nero.com/eng/downloads-nerod ... -codec.php
* For ogg encoding: http://www.xiph.org/downloads/
* To allow boosing the volume: "sox" a tool to apply a wide veriety of effects on audio: http://sox.sourceforge.net/

Installing compiling, etc
* The main component you will additionally need is sox.

Get the sources from here: http://sourceforge.net/projects/sox/files/sox/14.3.2/ and download sox-14.3.2.tar.bz2.
Just download it to /opt/etc again and untar it, then cd into the
sox-14.3.2 directory.

Configuration of sox requires gawk and sed, and those need to be both recent. In my case sed was old and part of an old busybox. To fix this I had to link to a recent version of sed (if there is no sed at /opt/bin/sed then try installing it with ipkg install sed):

Code: Select all
#optional:
rm /bin/sed
ln -s /share/MD0_DATA/.qpkg/Optware/bin/sed /bin/sed

# configure sox - static building won't work, so we need to disable it
./configure --prefix=/opt --disable-static

# compile and install
make
make install


* Optionally compile ogg
Get get the vorbis tools sources from http://downloads.xiph.org/releases/vorb ... 4.0.tar.gz

And then the typical configuring, compiling and installing:
./configure --prefix=/opt
make
make install

* Optionally download nero aac
When downloading nero aac you should get a file such as NeroAACCodec-1.5.1.zip
Just copy neroAacEnc (and possibly neroAacTag if you want to add metadata, but I did not find how this may be used in a streaming way) in the linux directory of the zip file to /var/subsonic/transcode and make it executable

The actual scripts I wrote
I have three scripts, one per format. I actually still use the mp3 one...:

streammp3:
Code: Select all
#!/bin/sh

source=$1; bitrate=$2; track=$3; artist=$4; album=$5; output=$6;
# parameters from subsonic: source: %s bitrate: %b track: %t artist: %a album: %l

# get bitrate of source so the output bitrate is not larger
AUDIO_BITRATE=$(/opt/bin/ffprobe "$source" 2>&1 | /opt/bin/grep 'bitrate: ' | /opt/bin/sed -n 's/.* bitrate: //p' | /opt/bin/sed -n 's/ .*$//p')

if [ $AUDIO_BITRATE ] && [ $bitrate -gt $AUDIO_BITRATE ]; then
bitrate=$AUDIO_BITRATE
fi

if [ -z "$output" ]; then
/opt/bin/mplayer "$source" -ao pcm -of wav -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/sox --temp /var/subsonic/transcode/temp -t wav --ignore-length - -t wav /dev/fd/3 compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/lame -b $bitrate --tt "$track" --ta "$artist" --tl "$album" -S --resample 44.1 - /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log
else
/opt/bin/mplayer "$source" -ao pcm -of wav -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/sox --temp /var/subsonic/transcode/temp -t wav --ignore-length - -t wav /dev/fd/3 compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/lame -b $bitrate --tt "$track" --ta "$artist" --tl "$album" -S --resample 44.1 - "$output"
fi


streamogg:
Code: Select all
#!/bin/sh

source=$1; bitrate=$2; track=$3; artist=$4; album=$5; output=$6;
# parameters from subsonic: source: %s bitrate: %b track: %t artist: %a album: %l

# get bitrate of source so the output bitrate is not larger
AUDIO_BITRATE=$(/opt/bin/ffprobe "$source" 2>&1 | /opt/bin/grep 'bitrate: ' | /opt/bin/sed -n 's/.* bitrate: //p' | /opt/bin/sed -n 's/ .*$//p')

if [ $AUDIO_BITRATE ] && [ $bitrate -gt $AUDIO_BITRATE ]; then
bitrate=$AUDIO_BITRATE
fi

if [ -z "$output" ]; then
/opt/bin/mplayer "$source" -ao pcm -of wav -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/sox --temp /var/subsonic/transcode/temp -t wav --ignore-length - -t wav /dev/fd/3 compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/oggenc --raw --bitrate ${bitrate} --title "$track" --artist "$artist" --album "$album" - -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log
else
/opt/bin/mplayer "$source" -ao pcm -of wav -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/sox --temp /var/subsonic/transcode/temp -t wav --ignore-length - -t wav /dev/fd/3 compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/oggenc --raw --bitrate ${bitrate} --title "$track" --artist "$artist" --album "$album" - -o "$output"
fi


streamaac:
Code: Select all
#!/bin/sh

source=$1; bitrate=$2; track=$3; artist=$4; album=$5; output=$6;
# parameters from subsonic: source: %s bitrate: %b track: %t artist: %a album: %l

# get bitrate of source so the output bitrate is not larger
AUDIO_BITRATE=$(/opt/bin/ffprobe "$source" 2>&1 | /opt/bin/grep 'bitrate: ' | /opt/bin/sed -n 's/.* bitrate: //p' | /opt/bin/sed -n 's/ .*$//p')

if [ $AUDIO_BITRATE ] && [ $bitrate -gt $AUDIO_BITRATE ]; then
bitrate=$AUDIO_BITRATE
fi

if [ -z "$output" ]; then
/opt/bin/mplayer "$source" -ao pcm -of wav -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/sox --temp /var/subsonic/transcode/temp -t wav --ignore-length - -t wav /dev/fd/3 compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/neroAacEnc -cbr ${bitrate}000 -ignorelength -if - -of /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log
else
/opt/bin/mplayer "$source" -ao pcm -of wav -o /dev/fd/3 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/sox --temp /var/subsonic/transcode/temp -t wav --ignore-length - -t wav /dev/fd/3 compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 3>&1 1>>/var/subsonic/transcode/logs.log 2>>/var/subsonic/transcode/errors.log|/opt/bin/neroAacEnc -cbr ${bitrate}000 -ignorelength -if - -of "$output"
fi


Save those inside /var/subsonic/transcode and make them executable (chmod 755 streammp3).

[b]Using the scriots[b]
To actually use the scripts you must call them from subsonic transcoding settting page.
Fill this in for mp3 streaming in the Step 1 field:

streammp3 %s %b %t %a %l

And empty out Step 2 (and Step 3).

You may want to check the logs again to make sure everything works correctly!

Again, please provide feedback if you used this guide. Ddid everything work, were there any problems? In the latter case, please provide them so I can help and update the instructions...
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Problem compiling ffmpeg

Postby subsolar » Mon Aug 15, 2011 12:08 am

Seems the current ffmpeg from mplayer2 requires a newer version of x264:
Code: Select all
[/opt/etc/mplayer2-build] # make
script/ffmpeg-config
ERROR: libx264 version must be >= 0.115.

What to do now? :oops:
subsolar
 
Posts: 3
Joined: Sun Aug 14, 2011 11:57 pm

Re: How to install and optimize subsonic on a Qnap NAS Serve

Postby quicky » Wed Aug 17, 2011 3:57 pm

Hi Morkeleb,

thanks for the awesome tutorial. I followed it step by step and even though I don't have a clue about linux / apache / java or tomcat I made it without any issues!!!

I would like to optimize the finally situation a bit and even if it's not related to Subsonic directly you might know my problems the best and might have a solution which I'll be able to follow.

I now have Subsonic running under the following URL: http://mysite.dyndnsprovider.com:7080/subsonic

When I give someone access to this URL they could easily jump to the Tomcat root which I wouldn't want so I guess I could simply upload a .htaccess file. However I would like to get something like

http://subsonic.dyndnsprovider.com/

or at least

http://subsonic.mysite.dyndnsprovider.com

I guess for the first solution I would need to register another subdomain at a dyndns-provider, but I would still need to guide it to a special direction. The second solution would (if something like that is possible at all) would work with my existing dyndns entry but I would still need to setup some virtual host.

I went through all the VirtualHost HowTos but I couldn't get it working. Any idea?

Another question is: Would a SSL Tomcat be something that is easily be possible? I ask since the default QNAP webserver simply has a Checkbox to use SSL.

Thanks for your feedback on that.

Best regards

quicky
quicky
 
Posts: 6
Joined: Wed Aug 17, 2011 3:38 pm

Re: Problem compiling ffmpeg

Postby Morkeleb » Mon Aug 22, 2011 1:02 pm

subsolar wrote:Seems the current ffmpeg from mplayer2 requires a newer version of x264:
Code: Select all
[/opt/etc/mplayer2-build] # make
script/ffmpeg-config
ERROR: libx264 version must be >= 0.115.

What to do now? :oops:


I'm afraid I can only suggest to use an older version of mplayer2.
Another option would be to ask in the developer irc channel of mplayer2
(#mplayer2 on irc.freenode.net)
divVerent is the main developer and he should be around from time to time.
Ask him for advice.

I tried to compile the latest version of x264 (i think i mentioned this already).
Compiling itself works, however apparently due to an outdated version of gcc,
the resulting build is not ok and it will cause x264 to crash.

Others in an x264 channel could not reproduce the error, but that was because
they had a proper gcc version - they say 4.2 is buggy and should be avoided.

I tried to compile gcc but it has many dependancies and I just did not manage it.
Maybe you have more success.

Sorry I can give a solution...
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Re: How to install and optimize subsonic on a Qnap NAS Serve

Postby Morkeleb » Mon Aug 22, 2011 2:58 pm

Hi there quicky.

There are several ways to achieve this. Some methods to consider:
- 1) Port forwarding of your router (if your nas is not directly publicly accessible,
you must make a port of your NAS available, and you can change the port number
for instance from 7080 to 80).
- 2) A simple html page on your root tomcat (in /share/MD0_DATA/.qpkg/Tomcat/tomcat/webapps/ROOT/)
that automatically loads the final one.
This is ofcourse not a very nice solution, since in the end the original URL will be displayed in the browser,
and it might not work with the android application.
- 3) Making subsonic the root application (and moving the current root to something like admin).
- 4) Changing the port of the tomcat server

I think the best ist to start with 3):

- stop tomcat with "/etc/init.d/tomcat.sh stop"
- go to /share/MD0_DATA/.qpkg/Tomcat/tomcat/webapps
- rename ROOT to something like admin ("mv ROOT admin")
- rename subsonic.war to ROOT.war and delete the subsonic directory
("mv subsonic.war ROOT.war", "rm -rf subsonic")
- start tomcat with "/etc/init.d/tomcat.sh start"

Subsonic should now be accessible as http://mysite.dyndnsprovider.com:7080/
The old start page that was accessible on that url before is now accessible as
http://mysite.dyndnsprovider.com:7080/admin/

If you have a router that does port forwarding I would now suggest to do that
as mentioned in 1), basically expossing the tomcat of your NAS on the router on a different port.

If this is not an option try option 4)

To be able to use port 80 you must make QNAP not use it anymore.
For some reason it seemes to use it even if you stay with the default 8080 for
System Administration and have "Web Server" under "Network Services" disabled.
To fix this i had to change the port of the Web Server to something else (i used 81)
and enable it.

Then change the port tomcat shall use to 80 by editing /share/MD0_DATA/.qpkg/Tomcat/tomcat/conf/server.xml:
- stop tomcat (see above)
- edit server.xml, search for "7080" (you should find something like <Connector port="7080") and replace it with "80".
- start tomcat again (see above)

If subsonic is now not accessible as http://mysite.dyndnsprovider.com/ check out the tomcat log file:
in /share/MD0_DATA/.qpkg/Tomcat/tomcat/logs look for a file starting with catalina that has the oldest date
and loot into it, for instance:
"cat /share/MD0_DATA/.qpkg/Tomcat/tomcat/logs/catalina.2011-08-22.log"

Hope this is enough to help you.
I cannot give you advice on dyndns, you are on your own with that and maybe creating a some subdomain, but my instructions before should be enough to access your subsonic server as http://<your-internal-qnap-ip>/.

Morkeleb
Morkeleb
 
Posts: 19
Joined: Wed Mar 02, 2011 9:35 pm

Re: How to install and optimize subsonic on a Qnap NAS Serve

Postby quicky » Mon Aug 22, 2011 8:39 pm

Thanks alot! I'll get it done now!

Cheers!

quicky
quicky
 
Posts: 6
Joined: Wed Aug 17, 2011 3:38 pm

Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 10 guests