Friday, July 22, 2011

MiniDLNA upnp-av media sharing on DD-WRT

This is how to get UPNP sharing working from your router using MiniDLNA. I also got sharing working via UShare, but will write this with MiniDLNA because ushare is less compatible and no longer in development. This is a pretty straight forward and simple process if you're familiar with working in the DDWRT environment. The guide is derived from my install using a Buffalo WZR-HP-G300NH running Buffalo's official DDWRT distribution, svn 14889, but can be used for other builds.

Edit: Buffalo's official build mentioned above does not work with inotify. This module in the program allows scanning of watched folders without completely re-building the database.

First off, you need to have a useable IPKG or OPKG installed to automatically retrieve and install MiniDLNA and it's dependencies. The Software Installation tutorial is required to use this application.

MiniDLNA installation and configuration:
  1. Install MiniDLNA with the comand:
    opkg install minidlna

    This will install the MiniDLNA server and any missing dependencies. Wait for it to fully complete.

  2. Edit MiniDLNA's configuration to fit your set-up/needs.
    You can use ssh or telnet to do this manually from shell using vi/nano, or you can edit the file using an SCP client. Just make sure not to use Windows Notepad!

    MiniDLNA's configuration file is located at /opt/etc/minidnla.conf

    The network_interface needs to be changed to the appropriate one, br0. If you want more than one interface serving files you need to run multiple instances of minidlna with the interface set manually in the command call, or multiple config files. Uncomment the network interface line by deleting the # in front and change 'eth0' to 'br0', so the finished line reads:

    network_interface=br0


    Set your media share directories. As the config file states, these are separated by multiple media_dir lines, and content is defined by a preceding A, V, or P. Keep in mind that Linux is a case-sensitive OS, so your directories MUST match your file structure exactly, or the files will not be found. My finished share section looks like:

    media_dir=V,/mnt/share/Videos
    media_dir=P,/mnt/share/Pictures
    media_dir=A,/mnt/share/Music


    **Important** a bug exists in the scanner used in minidlna. Enter any music libraries last, because they can cause the movies scanner to freeze.

    Set your friendly name to whatever you want your network to see it as. I use the the generic 'Media Server.
    "

    friendly_name=Media Server


    If you have a large library and want your library database kept between program runs, you MUST change this setting. If you aren't hosting many files, or don't mind it rebuilding every reboot, you can leave this the same.

    Create a directory on your mount for the library db, error log, and the art cache. If you do this, create an isolated directory, because running the rebuild command deletes everything in the configured directory in Minidlna 1.0.18 and earlier. I put mine on ./mnt/tmp/minidlna.


    db_dir=/mnt/tmp/minidlna


    Set inotify to watch for new files to be added to the library. Inotify searches for new files every 60 seconds. Keep this on, or turn it off, you're choice. (no=off yes=on
    ) Older versions of DD-WRT, including the stable official Buffalo release, don't support inotify and cannot use this feature. It is generally available in svn ~15000 and higher.

    inotify=yes


    Enabling Tivo support and strict dlna is by user preference. Although, strict dlna will make the server (aka your router) scale jpeg images, and may impact performance, so I leave it off (and I don't have a Tivo either).


    enable_tivo:no
    strict_dlna:no

    This is important: You MUST CHANGE the presentation url or your devices will not see the server. Set it to your router's IP address with 8200 port, ignoring the page url. DDWRT default would be:

    presentation_url=http://192.168.1.1:8200/

    Set the notification interval, serial, and model numbers to whatever you please. The notification interval of 900s is frequent enough, so don't worry about changing it.

    In the end, my final minidlna.conf file looks like:
    port=8200
    network_interface=br0

    media_dir=A,/mnt/share/Musicmedia_dir=V,/mnt/share/Videos
    media_dir=P,/mnt/share/Pictures
    friendly_name=Media Server

    db_dir=/mnt/tmp/minidlna

    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

    inotify=yes

    enable_tivo=no

    strict_dlna=no
    presentation_url=http://192.168.1.1:8200/

    notify_interval=900

    serial=12345678

    model_number=1

  3. Library Detection Issues:
    MiniDLNA requires pre-built media libraries to scan media for library population. The version located in the OpenWRT repo is stripped down to save space on the router. We have plenty of space, so custom libraries with all formats are required.

    1. Download the libraries from here.

    2. Transfer the extracted files to your router in whatever way you prefer. They need to be placed in the ./opt/usr/lib/ folder. Replace the files that are already located in the folder when/if prompted.

    3. Create the symbolic links for the program to recognize the libraries.

    cd /opt/usr/lib

    ln -sf libvorbisfile.so.3.3.2 libvorbisfile.so.3
    ln -sf libpthread-0.9.30.1.so libpthread.so.0
    ln -sf libavformat.so.52.31.0 libavformat.so.52
    ln -sf libresolv-0.9.30.1.so libresolv.so.0
    ln -sf libuClibc-0.9.30.1.so libc.so.0
    ln -sf libavdevice.so.52.1.0 libavdevice.so.52
    ln -sf libavcodec.so.52.20.1 libavcodec.so.52
    ln -sf ld-uClibc-0.9.30.1.so ld-uClibc.so.0
    ln -sf libcrypt-0.9.30.1.so libcrypt.so.0
    ln -sf libavutil.so.49.15.0 libavutil.so.49
    ln -sf libxtables.so.4.0.0 libxtables.so.4
    ln -sf libxtables.so.4.0.0 libxtables.so
    ln -sf libutil-0.9.30.1.so libutil.so.0
    ln -sf libsqlite3.so.0.8.6 libsqlite3.so.0
    ln -sf libvorbis.so.0.4.3 libvorbis.so.0
    ln -sf libuci.so.12012009 libuci.so.0
    ln -sf libuci.so.12012009 libuci.so
    ln -sf libid3tag.so.0.3.0 libid3tag.so.0
    ln -sf librt-0.9.30.1.so librt.so.0
    ln -sf libjpeg.so.62.0.0 libjpeg.so.62
    ln -sf libexif.so.12.3.1 libexif.so.12
    ln -sf libdl-0.9.30.1.so libdl.so.0
    ln -sf libm-0.9.30.1.so libm.so.0
    ln -sf libFLAC.so.8.2.0 libFLAC.so.8
    ln -sf libFLAC.so.8.2.0 libFLAC.so
    ln -sf libogg.so.0.6.0 libogg.so.0
    ln -sf libuuid.so.1.2 libuuid.so.1
    ln -sf libz.so.1.2.5 libz.so.1
    ln -sf libz.so.1.2.5 libz.so


    Also, you need to use the export command to point to the libraries since they aren't in the default directory. You may already have this in your router's start-up script, or in another program's script. If not, you can add this to the minidlna script in init.d (before the minidlna run command) or to the start-up commands in the web interface.
    export LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib'

     
  4. Test it!
    Run it with the command:

    minidlna -f opt/etc/minidlna.conf


    Now, try it out on your device(s) to see if it is working to your expectations. If you decide to edit the conf file more, make sure to kill minidlna first, or the file will not save.
    killall minidlna


  5. Set it to run on reboot.
    Change directory to /opt/etc/init.d and edit the file minidlna, if the file isn't there, create it. Replace all contents with:

    minidlna -f /opt/etc/minidlna.conf


    Set it to run on boot by running:

    chmod a+x /opt/etc/init.d/minidlnaln -s /opt/etc/init.d/minidlna /opt/etc/init.d/S99minidlna

    Reboot your router and verify that the program ran on boot.
    'ps' is the command to see running programs.

    If at any point you want to re-build your library fully you can delete the contents of your db_dir folder, or minidlna using the -R switch at the end. (ie: minidlna -f /opt/etc/minidlna.conf -R)
     

23 comments:

hello what formats support minidlna?

Minidlna supports a ton of formats. Format support issues are usually with the client. You can find more help on Minidlna at their forums: http://sourceforge.net/projects/minidlna/forums

Could you share a network drive using this?

No, for Windows shares check the Samba tutorial.

Hi man, I can´t find the libraries at the link that you provided. Do you have the files?
Thanks!

I have to dig. They were taken with MegaUpload.com - I know, legal files on MegaUpload, weird.

Sorry for the delay. Here is an updated link: http://dl.dropbox.com/u/1198269/lib.zip

Hello, I've follow the instructions for installing the opkg module and everything seems fine, but when I enter:
"opkg install minidlna"
I got this error:
"Collected errors:
*verify_pkg_installable: Only 0kb available on filesystem /opt, pkg minidlna needs 120"

I've tried changing the location in the opkg.conf file but still I got the same error.
Do you have any idea where might the problem be?

Iskren, your router should have a DLNA client in the stock firmware. Netgear's firmware looks to be pretty good, are you sure you need DD-WRT?

Thanks for the reply. Yes, the router does have a stock verions of minidlna. The problem is that the version is 1.01.18 and I'm trying to stream movies to LG Smart TV and I need minidlna ver.1.0.20 or above to play subtitles.

Ah, I see.

It looks like your /opt folder isn't writeable. From the OPKG install post, the /opt folder should be mounted to /mnt/opt. Try running 'mount -o bind /mnt/opt /opt' before the minidlna install to be sure it is mounted correctly.

To those wanting to play MKVs on their dlna players, I haven't checked the updates to the media libraries or minidlna in a long time (since 1.0.19). I will try to update these to the latest soon, but I don't have a player that supports MKVs so I cannot test.

Hi,

I have two problems if you can help me pls:

1. minidlna: can't load library 'libexif.so.12'
2. If I set the startup script to the router GUI I can't ssh as root anymore, it says: access denied. Startup script used from here (step 7):
http://arouter.blogspot.ro/2011/07/software-installation-on-dd-wrt.html

Thanks.

@Catalin

I don't have this router anymore, but I'm guessing the library issue is connected with the start-up script conflict. First, make sure the library is in the indicated location with the same filename and directory (including capitalizations). If it is, try starting the whole unit from scratch (but save your configuration first, then you have a quick backup). I may get the unit back soon, if I do I will help as much as I can. Also, can you post the dd-wrt version?

Thanks for the reply. I will try to start from the beginning, maybe I missed something.

Router Model TP-Link TL-WR842ND v1
DD-WRT v24-sp2 (04/15/13) std

Hi, the problem is solved, the ln command on the lib files was not working....I don't know why. I copied the libs with the correct name and it worked.

7030 1 0 S 13220 45.3 0 0.0 minidlna -f /opt/etc/minidlna.con

Now I will have to understand how the starting script affects my ssh login..

Thanks,
Catalin.

Hi,
I do have issue I can see Videos on my TV but no Pictures or Music, even the Pictures and Music are on my HDD attached to my router.
Could you please advice?

BR,
Peter

@Peter

Check your library locations that you have set in your configuration file from step 2. ex:

media_dir=P,/mnt/share/Pictures

make sure there are no spaces - they should be ignored when parsed, but who knows. Make sure the library type matches the folder - P for pictures, A for audio, V for video. And make sure capitalizations match exactly - if a folder is capitalized in your file system, the settings need to match. If those are correct, try deleting all of the folders and test each individually, fully restarting your router between each settings change.

...also make sure to double check your folder permissions.

Hi mdneilson,
thanks for the hint, but its not working/working. If Im trying it separately then it works. Just pictures - no problem, just videos - no problem, just Music - no problem. If Im having shared Pictures, Videos and Music at the same time - then one poit for this - I can see Videos (as before) and Music as well - but no Pictures.... Strange...I will try combination of 2 of each and I will see...Or do you have any other suggestion?
Permissions are OK (rwx------).

BR,
Peter

@Peter

I'm guessing that the library scanner is hanging somewhere since they work individually. It builds your library in the order that the sections are entered into the settings. Putting the pictures and music sections above the video section will likely make those work. You can take a look at the media scanner log to find where exactly it is hanging. I had a couple files that would cause troubles while scanning.

...when looking at the scanner log, the last line should indicate that the scan was completed successfully. If you don't see a line indicating that, it didn't finish. The culprit is likely an old lib dependency or a bug in the scanner. I'd try finding an older version of minidlna to try things out, if the scanner is hanging. I don't have this router anymore, nor is my compiling server active, so I can't help much with creating new libs.

Hi mdneilson,
thanks for your help. Your suggestion - all above video section helped!
Great - thank you.
I have also reimaged everything (router, usb...) and now Im not able to log on to the external USB drive directly...but this is not an issue since Im able to FTP....

Once again thanks!
BR,
Peter

Post a Comment

Note: Only a member of this blog may post a comment.