Installing Minidlna on QNAP NAS TS-419P II

日本語のページは こちら をご覧ください。 / Click here for Japanese version.

Recently I installed Minidlna ver.1.0.25 on my QNAP NAS TS-419P II (firmware 3.8.1 Build 20121205) from the source, so here is what I did.

Caution: This article is NOT meant to be a step-by-step guide; You need basic knowledge of Linux, building open-source project, and your QNAP NAS system. Also, please be noted that some part of this article are environment-specific. (For example, I use "/share/MD0_DATA/" to point out my RAID HDD volume on my NAS.)


What is Minidlna?

Minidlna is an open-source UPnP-AV media server developed for ReadyNAS, a Netgear product. Official project page is here: http://sourceforge.net/projects/minidlna/.

The description of the project says: "if you are looking for a NAS, please consider ReadyNAS first!" So, you should first consider buying a ReadyNAS, instead of installing Minidlna server on a QNAP NAS :-)

For building/installing Minidlna, you can find some useful information on the QNAP forum: http://forum.qnap.com/viewtopic.php?p=61719.


1. Install Optware IPKG

Optware IPKG can be installed from the Web Interface. Just clicked "Install":
Then I logged on to my NAS via SSH and ran "ipkg update".


2. Retrieve the source code

I've used version 1.0.25 (stable release). Downloaded minidlna_1.0.25_src.tar.gz from the project page (http://sourceforge.net/projects/minidlna/), copied it onto my QNAP, and extract it there.


3. Prepare the libraries

The file INSTALL says:
Prerequisites :

- libexif
- libjpeg
- libid3tag
- libFLAC
- libvorbis
- sqlite3
- libavformat (the ffmpeg libraries)
- libuuid
So I installed them using IPKG. From the SSH console, I ran:
# ipkg install libexif
# ipkg install libjpeg
# ipkg install libid3tag
# ipkg install flac
# ipkg install libvorbis
# ipkg install sqlite
# ipkg install ffmpeg
Note:
The package "sqlite" provides sqlite version 3, while the package "sqlite2" provides version 2. You can run "ipkg info sqlite" and "ipkg info sqlite2" to verify the versions.
I have NOT installed libuuid since it was already on my QNAP system.

I also installed "gcc" and "make" packages since these are needed to build the project.
# ipkg install gcc make


4. Modify Makefile and genconfig.sh

Minidlna project assumes that the header files are located under /usr/include. However, since I'm using Optware, these files are placed under /opt/include. So I have replaced all of "/usr/include" with "/opt/include" in Makefile and genconfig.sh.

Also, I added an extra line in the Makefile:
LDFLAGS += -L/opt/lib -Wl,-rpath,/opt/lib
This is because the library files are located under /opt/lib. Without this, the build succeeded, but I got an error message like:
  minidlna: error while loading shared libraries: libexif.so.12: cannot open shared object file: No such file or directory
when I ran the server.

Note:
Maybe I should chroot into /opt before starting the build to get rid of this error? (I have tried this but chroot didn't work.)


5. Give a build

To install the binary under /opt/sbin, I used "INSTALLPREFIX" described in the Makefile.
# INSTALLPREFIX=/opt make
# INSTALLPREFIX=/opt make install

Now see if it works:
# which minidlna
/opt/sbin/minidlna

# ldd /opt/sbin/minidlna
        libpthread.so.0 => /lib/libpthread.so.0 (0x40026000)
        libexif.so.12 => /opt/lib/libexif.so.12 (0x40046000)
        libjpeg.so.62 => /opt/lib/libjpeg.so.62 (0x4007f000)
        libsqlite3.so.0 => /opt/lib/libsqlite3.so.0 (0x400a8000)
        libavformat.so.52 => /opt/lib/libavformat.so.52 (0x4013c000)
        libavutil.so.49 => /opt/lib/libavutil.so.49 (0x401d8000)
        libavcodec.so.51 => /opt/lib/libavcodec.so.51 (0x401ef000)
        libid3tag.so.0 => /opt/lib/libid3tag.so.0 (0x406fc000)
        libFLAC.so.8 => /opt/lib/libFLAC.so.8 (0x40713000)
        libogg.so.0 => /opt/lib/libogg.so.0 (0x40765000)
        libvorbis.so.0 => /opt/lib/libvorbis.so.0 (0x40771000)
        libc.so.6 => /lib/libc.so.6 (0x407a5000)
        /lib/ld-linux.so.3 (0x40000000)
        libm.so.6 => /lib/libm.so.6 (0x408d9000)
        libdl.so.2 => /lib/libdl.so.2 (0x40989000)
        libz.so.1 => /opt/lib/libz.so.1 (0x40995000)

# minidlna -V
Version 1.0.25
Great! It's working.


6. Create the conf file

I'm about half way done. The server needs a conf file and I should create it. Fortunately minidlna_1.0.25_src.tar.gz provides a file called minidlna.conf, which is a template. Let's just modify it.

I copied the file onto the NAS, under /opt/etc/ (which is equivalent to /share/MD0_DATA/.qpkg/Optware/etc/).
Note: don't use /etc ! It is on a RAM disk, and any files placed in it will be GONE as you reboot the NAS!

My QNAP TS-419P II contains some sample photos and musics under /share/Multimedia/Samples/. I used these files as an example. I modified "media_dir=" as follows:
media_dir=P,/share/Multimedia/Samples
media_dir=A,/share/Multimedia/Samples

Then I also modified "db_dir=" and "log_dir=". By default, these directories point to /var/cache and /var/log. But since /var is also on the (small) RAM disk, I cannot put many files there (otherwise Minidlna stops working, saying "500 Internal Server Error". Ouch!)
So here are what I did:
db_dir=/share/MD0_DATA/.minidlna/cache
log_dir=/share/MD0_DATA/.minidlna/log

Finally I changed friendly_name to be "minidlna server on QNAP".
That's it! Here is my conf file.
# port for HTTP (descriptions, SOAP, media transfer) traffic
port=8200

# network interfaces to serve, comma delimited
#network_interface=eth0

# set this to the directory you want scanned.
# * if have multiple directories, you can have multiple media_dir= lines
# * if you want to restrict a media_dir to a specific content type, you
#   can prepend the type, followed by a comma, to the directory:
#   + "A" for audio  (eg. media_dir=A,/home/jmaggard/Music)
#   + "V" for video  (eg. media_dir=V,/home/jmaggard/Videos)
#   + "P" for images (eg. media_dir=P,/home/jmaggard/Pictures)
media_dir=P,/share/Multimedia/Samples
media_dir=A,/share/Multimedia/Samples

# set this if you want to customize the name that shows up on your clients
friendly_name=minidlna server on QNAP

# set this if you would like to specify the directory where you want MiniDLNA to store its database and album art cache
db_dir=/share/MD0_DATA/.minidlna/cache

# set this if you would like to specify the directory where you want MiniDLNA to store its log file
log_dir=/share/MD0_DATA/.minidlna/log

# set this to change the verbosity of the information that is logged
# each section can use a different level: off, fatal, error, warn, info, or debug
#log_level=general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn

# this should be a list of file names to check for when searching for album art
# note: names should be delimited with a forward slash ("/")
album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg

# set this to no to disable inotify monitoring to automatically discover new files
# note: the default is yes
inotify=yes

# set this to yes to enable support for streaming .jpg and .mp3 files to a TiVo supporting HMO
enable_tivo=no

# set this to strictly adhere to DLNA standards.
# * This will allow server-side downscaling of very large JPEG images,
#   which may hurt JPEG serving performance on (at least) Sony DLNA products.
strict_dlna=no

# default presentation url is http address on port 80
#presentation_url=http://www.mylan/index.php

# notify interval in seconds. default is 895 seconds.
notify_interval=900

# serial and model number the daemon will report to clients
# in its XML description
serial=12345678
model_number=1

# specify the path to the MiniSSDPd socket
#minissdpdsocket=/var/run/minissdpd.sock

# use different container as root of the tree
# possible values:
#   + "." - use standard container (this is the default)
#   + "B" - "Browse Directory"
#   + "M" - "Music"
#   + "V" - "Video"
#   + "P" - "Pictures"
# if you specify "B" and client device is audio-only then "Music/Folders" will be used as root
#root_container=.


7. Try the server

By default Minidlna runs as a daemon. But when debugging, I prefer running it in the foreground since it shows debug logs on the console. This can be achieved by adding "-d" option in the command line.

I created the directories before launching the server:
# mkdir /share/MD0_DATA/.minidlna
# mkdir /share/MD0_DATA/.minidlna/cache
# mkdir /share/MD0_DATA/.minidlna/log
and then I ran:
# minidlna -d -f /opt/etc/minidlna.conf
Note that I used "-f" option as well to specify the conf file. This is what I got:
# minidlna -d -f /opt/etc/minidlna.conf
[2013/02/23 02:38:40] minidlna.c:884: warn: Starting MiniDLNA version 1.0.25 [SQLite 3.7.14.1].
[2013/02/23 02:38:40] minidlna.c:907: warn: Creating new database...
[2013/02/23 02:38:40] scanner.c:731: warn: Scanning /share/MD0_DATA/Multimedia/Samples
[2013/02/23 02:38:40] minidlna.c:972: info: Enabled interface 192.168.1.10/255.255.255.0
[2013/02/23 02:38:40] minidlna.c:990: warn: HTTP listening on port 8200
[2013/02/23 02:38:40] minissdp.c:351: debug: Sending SSDP notifies
[2013/02/23 02:38:40] scanner.c:802: warn: Scanning /share/MD0_DATA/Multimedia/Samples finished (10 files)!
[2013/02/23 02:38:40] scanner.c:731: warn: Scanning /share/MD0_DATA/Multimedia/Samples
[2013/02/23 02:38:40] albumart.c:252: debug: Found new embedded album art in Sample Music 1.mp3
[2013/02/23 02:38:40] albumart.c:252: debug: Found new embedded album art in Sample Music 2.mp3
[2013/02/23 02:38:40] albumart.c:252: debug: Found new embedded album art in Sample Music 3.mp3
[2013/02/23 02:38:40] albumart.c:252: debug: Found new embedded album art in Sample Music 4.mp3
[2013/02/23 02:38:40] albumart.c:252: debug: Found new embedded album art in Sample Music 5.mp3
[2013/02/23 02:38:40] scanner.c:802: warn: Scanning /share/MD0_DATA/Multimedia/Samples finished (15 files)!
[2013/02/23 02:38:40] playlist.c:125: warn: Parsing playlists...
[2013/02/23 02:38:40] scanner.c:848: debug: Initial file scan completed
[2013/02/23 02:38:42] inotify.c:153: debug: Add watch to /share/MD0_DATA/Multimedia/Samples
[2013/02/23 02:38:42] inotify.c:153: debug: Add watch to /share/MD0_DATA/Multimedia/Samples
[2013/02/23 02:38:42] inotify.c:160: debug: Add watch to /share/MD0_DATA/Multimedia/Samples
[2013/02/23 02:38:42] inotify.c:160: debug: Add watch to /share/MD0_DATA/Multimedia/Samples

As you can see, the server creates a database file when launched for the first time. If you have many files, it will take some time.

Looks like the server is up and running. See if I can connect from a DLNA client software. I use Media Link Player Lite on my iPod Touch.

Yes I can see the server "minidlna server on QNAP"
... and I can see the files too!

It's working. Great! Just hit Ctrl-C to stop the server.


8. Let the server automatically start as the NAS boots up

The article:
http://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup
describes what I should do, but I needed some tweaks. (It may be because my NAS takes quite a long time to mount the RAID volumes.)

First, I mounted the "config ramblock" under /tmp/config/ and edited the file autorun.sh.
# mount -t ext2 /dev/mtdblock5 /tmp/config/
# vi /tmp/config/autorun.sh
#!/bin/sh

MOUNT_TIMEOUT_SEC=600
NUM=0

while [ ! -e /share/MD0_DATA/.qpkg/autorun ]
do
  sleep 1

  NUM=`expr $NUM + 1`
  if [ $NUM -ge $MOUNT_TIMEOUT_SEC ]
  then
    exit 1
  fi
done

/share/MD0_DATA/.qpkg/autorun/autorun.sh &

As you can see, my scripts wait for the directory "/share/MD0_DATA/.qpkg/autorun" to come up, and then runs /share/MD0_DATA/.qpkg/autorun/autorun.sh.

Note: I have added 10-minutes timeout here. Without this, the script will wait forever if /share/MD0_DATA/ isn't mounted for some reason, making the front panel saying "Starting Service Please Wait..." all the time. :-)

Now I unmounted /tmp/config/ and created the new file /share/MD0_DATA/.qpkg/autorun/autorun.sh:
# mkdir /share/MD0_DATA/.qpkg/autorun/
# vi /share/MD0_DATA/.qpkg/autorun/autorun.sh
#!/bin/sh

while [ ! -e /opt/sbin ]
do
  sleep 1
done
while [ ! -e /opt/etc ]
do
  sleep 1
done

# starting Minidlna server
/opt/sbin/minidlna -f /opt/etc/minidlna.conf &
Don't forget to add execute permission.
That's it! Now reboot the NAS and it should automatically starts up Minidlna server.


[Memo] Recreate the database

Add "-R" option in the command line to regenerate the database. Use "kill" command to stop the server process, then run:
# minidlna -R -f /opt/etc/minidlna.conf
... and have a coffee break.
Or maybe I can just delete the files under /share/MD0_DATA/.minidlna/cache and restart the server.
(I haven't verified this.)

コメントを投稿

2 コメント