Difference between revisions of "ReadyMedia"

From ArchWiki
Jump to: navigation, search
m (Local)
(semi-automatic style fixes, see Help:Style)
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
[[Category:Audio/Video]]
 
[[Category:Audio/Video]]
 
[[es:MiniDLNA]]
 
[[es:MiniDLNA]]
[https://sourceforge.net/projects/minidlna MiniDLNA] is server software with the aim of being fully compliant with [http://en.wikipedia.org/wiki/Digital_Living_Network_Alliance DLNA]/[http://en.wikipedia.org/wiki/Universal_Plug_and_Play UPnP] clients.  The MiniDNLA daemon serves media files (music, pictures, and video) to clients on a network.  Example clients include applications such as totem and xbmc, and devices such as portable media players, Smartphones, Televisions, and gaming systems (such as PS3 and Xbox 360).
+
{{Out of date|miniDLNA has been updated by the developer.  Pending more transitions, it is being renamed to "ReadyMedia", with an inbuilt daemon and different .conf files, locations, paths, and more.  Many elements of this guide still apply, however.}}
 +
 
 +
[https://sourceforge.net/projects/minidlna MiniDLNA] is server software with the aim of being fully compliant with [[wikipedia:Digital_Living_Network_Alliance|DLNA]]/[[wikipedia:Universal_Plug_and_Play|UPnP]] clients.  The MiniDNLA daemon serves media files (music, pictures, and video) to clients on a network.  Example clients include applications such as totem and xbmc, and devices such as portable media players, Smartphones, Televisions, and gaming systems (such as PS3 and Xbox 360).
  
 
MiniDLNA (ReadyDLNA) is a simple, lightweight alternative to [[MediaTomb]], but has fewer features. It does not have a web interface for administration and must be configured by editing a text file.
 
MiniDLNA (ReadyDLNA) is a simple, lightweight alternative to [[MediaTomb]], but has fewer features. It does not have a web interface for administration and must be configured by editing a text file.
Line 13: Line 15:
 
The MiniDLNA daemon can be run as either a global (config:{{ic|/etc/minidlna.conf}}) or per-user instance (config:user-defined), these are the necessary common settings:
 
The MiniDLNA daemon can be run as either a global (config:{{ic|/etc/minidlna.conf}}) or per-user instance (config:user-defined), these are the necessary common settings:
  
<pre>#network_interface=eth0                        # Self-discovers if commented (at times necessary to set)
+
{{bc|1=#network_interface=eth0                        # Self-discovers if commented (at times necessary to set)
 
media_dir=A,/home/user/Music                    # Mounted Media_Collection drive directories
 
media_dir=A,/home/user/Music                    # Mounted Media_Collection drive directories
 
media_dir=P,/home/user/Pictures                # Use A, P, and V to restrict media 'type' in directory
 
media_dir=P,/home/user/Pictures                # Use A, P, and V to restrict media 'type' in directory
Line 21: Line 23:
 
log_dir=/var/log                                # Log dir needs to be un-commented
 
log_dir=/var/log                                # Log dir needs to be un-commented
 
inotify=yes                                    # 'no' for less resources, restart required for new media
 
inotify=yes                                    # 'no' for less resources, restart required for new media
presentation_url=http://www.mylan/index.php    # or use your device static IP http://192.168.0.14:8200/</pre>
+
presentation_url=http://www.mylan/index.php    # or use your device static IP http://192.168.0.14:8200/}}
  
 
=== Global ===
 
=== Global ===
  
MiniDLNA scans your ''Media_Collection'' at startup and creates or updates database ''Media_DB'' browsable via media players. Set database cache and logging dirs in config, so the db and album art cache won't be re-created on every restart. By default MiniDLNA runs as ''nobody'' [https://wiki.archlinux.org/index.php/Users_and_Groups user] without shell access as set in ''/etc/conf.d/minidlna'', unless you set your own. That user needs rw permissions to cache and log directories you specified in conf.  Create the required directories and {{ic|chown}} them to {{ic|nobody:nobody}}.
+
MiniDLNA scans your ''Media_Collection'' at startup and creates or updates database ''Media_DB'' browsable via media players. Set database cache and logging dirs in config, so the db and album art cache will not be re-created on every restart. By default MiniDLNA runs as ''nobody'' [[Users_and_Groups|user]] without shell access as set in ''/etc/conf.d/minidlna'', unless you set your own. That user needs rw permissions to cache and log directories you specified in conf.  Create the required directories and {{ic|chown}} them to {{ic|nobody:nobody}}.  You can also specify a user to run as via the minidlna.conf file by setting
 +
 
 +
#user=jmaggard
 +
 +
Default cache and log directories need to be created and {{ic|chown}}ed to the chosen user.
  
 
  # mkdir /var/{cache,log}/minidlna
 
  # mkdir /var/{cache,log}/minidlna
Line 35: Line 41:
  
 
==== Service ====
 
==== Service ====
If using systemd, enable minidlna service to start at boot if you like:
+
 
# systemctl enable minidlna
+
The minidlna service can be managed by the ''minidlna'' [[daemon]].
 +
 
 +
===== Troubleshooting service autostart =====
 +
 
 +
Sometimes the minidlna daemon fails to start while booting. [[NetworkManager#Enable_NetworkManager_Wait_Online]] solves this issue. See {{Bug|35325}}
  
 
=== Local ===
 
=== Local ===
Line 42: Line 52:
 
Create the necessary files and directories locally and edit the configuration:
 
Create the necessary files and directories locally and edit the configuration:
  
  # mkdir -p ~/.config/.minidlna/cache
+
  # install -Dm644 /etc/minidlna.conf ~/.config/minidlna/minidlna.conf
# cp /etc/minidlna.conf ~/.config/.minidlna/
+
 
  # $EDITOR minidlna.conf
 
  # $EDITOR minidlna.conf
  
Configuring should be as it is globally, specifically:
+
Configuring should be as above, specifically:
  
 
  media_dir=/home/$USER/dir
 
  media_dir=/home/$USER/dir
Line 52: Line 61:
 
  log_dir=/home/$USER/.config/minidlna
 
  log_dir=/home/$USER/.config/minidlna
  
A local daemon script to stop, start... MiniDLNA is available in the AUR ({{AUR|minidlnad}}) along with an autostart .desktop file that looks like this:
+
As of version 1.1.0, a daemon is included in the minidlna package, which is confusingly also called "minidlnad", similar to the previous method detailed below.  To run, simply call:
 +
 
 +
# minidlnad
 +
 
 +
Previously, a local daemon script to stop, start... MiniDLNA was available in the AUR ({{AUR|minidlnad}}) along with an autostart .desktop file.  To run:
  
 
  # minidlnad
 
  # minidlnad
 
   minidlnad [start|stop|restart|rescan] - actions for the MiniDLNA daemon
 
   minidlnad [start|stop|restart|rescan] - actions for the MiniDLNA daemon
 +
 +
Alternatively you can autostart by adding in your {{ic|.bash_profile}} :
 +
 +
minidlna -f /home/$USER/.config/minidlna/minidlna.conf -P /home/$USER/.config/minidlna/minidlna.pid
  
 
==== Automatic Media_DB Update ====
 
==== Automatic Media_DB Update ====
  
Kernel adds one [http://en.wikipedia.org/wiki/Inotify inotify] watch per each folder/subfolder in ''Media_Collection'' Directories set in {{ic|/etc/minidlna.conf}} to monitor changes thus allowing MiniDLNA to update ''Media_DB'' in real time. When MiniDLNA is run as a regular user, it does not have the ability to change the kernel's ''inotify'' limits. If default number of ''inotify'' watches is non-sufficient to have MiniDLNA monitor all your media folders, increase ''inotify'' watches through {{ic|sysctl}} (100000 should be enough for most uses):
+
Kernel adds one [[wikipedia:Inotify|inotify]] watch per each folder/subfolder in ''Media_Collection'' Directories set in {{ic|/etc/minidlna.conf}} to monitor changes thus allowing MiniDLNA to update ''Media_DB'' in real time. When MiniDLNA is run as a regular user, it does not have the ability to change the kernel's ''inotify'' limits. If default number of ''inotify'' watches is non-sufficient to have MiniDLNA monitor all your media folders, increase ''inotify'' watches through {{ic|sysctl}} (100000 should be enough for most uses):
  
 
  # sudo sysctl fs.inotify.max_user_watches=100000
 
  # sudo sysctl fs.inotify.max_user_watches=100000
Line 68: Line 85:
 
  fs.inotify.max_user_watches = 100000
 
  fs.inotify.max_user_watches = 100000
  
''inotify'' performance may depend on device type. Some don't rescan media drives on a consistent basis or at all.  If files are added/deleted to monitored media directories, they may not be noticed until the device DLNA client is restarted.
+
''inotify'' performance may depend on device type. Some do not rescan media drives on a consistent basis or at all.  If files are added/deleted to monitored media directories, they may not be noticed until the device DLNA client is restarted.
  
Check ''inotify'' updates via MiniDLNA ''presentation_url'' by comparing files count. If it doesn't change, make sure the user running MiniDLNA has ''rw'' access to the DB folder. If the issue persists, copy or download new files first to a non-watched by ''inotify'' '''Downloads''' folder on the same drive, and then move them to appropriate media folders, since lengthy media files copying or downloading may confuse ''inotify''.
+
Check ''inotify'' updates via MiniDLNA ''presentation_url'' by comparing files count. If it does not change, make sure the user running MiniDLNA has ''rw'' access to the DB folder. If the issue persists, copy or download new files first to a non-watched by ''inotify'' '''Downloads''' folder on the same drive, and then move them to appropriate media folders, since lengthy media files copying or downloading may confuse ''inotify''.
  
 
You can also clean or rebuild MiniDLNA DB manually after stopping MiniDLNA daemon, or analyze its debug output (Ctrl+C to exit):
 
You can also clean or rebuild MiniDLNA DB manually after stopping MiniDLNA daemon, or analyze its debug output (Ctrl+C to exit):
  
To stop MiniDLNA daemon for systemd:
+
Stop the MiniDLNA daemon:
 
  # systemctl stop minidlna
 
  # systemctl stop minidlna
Or, initscripts:
 
# rc.d stop minidlna
 
  
 
To rebuild Media_DB forcibly:
 
To rebuild Media_DB forcibly:
Line 100: Line 115:
 
=== File System and Localization ===
 
=== File System and Localization ===
  
When keeping MiniDLNA ''Media_DB'' on an external drive accessible in both Linux and Windows, choose proper [https://wiki.archlinux.org/index.php/File_Systems file system] for it. '''NTFS''' preserves in Windows its Linux defaults: ''rw'' access for ''root'' user and ''UTF8'' font ''encoding'' for file names, so media titles in your language are readable when browsing ''Media_DB'' in terminal and media players, since most support ''UTF8''. If you prefer '''Vfat''' (FAT32) for better USB drive compatibility with older players when hooked directly, or your ''Media_Collection'' drive is Vfat and has folder & file names in your local language, MiniDLNA can transcode them to ''UTF8'' charset while scanning folders to ''Media_DB''. Add to ''Media_Collection'' and ''Media_DB'' drives' mount options your FS language [http://en.wikipedia.org/wiki/Code_page codepage] for transcoding to short DOS file names, and [http://en.wikipedia.org/wiki/Character_encoding iocharset] for converting long file names to your terminal's locale, i.g. ''codepage=cp866,iocharset=utf8 (or ISO-8859-5)''. Set ''rw'' permissions for all users, since ''Vfat'' doesn't preserve Linux access permissions:
+
When keeping MiniDLNA ''Media_DB'' on an external drive accessible in both Linux and Windows, choose proper [[File_Systems|file system]] for it. '''NTFS''' preserves in Windows its Linux defaults: ''rw'' access for ''root'' user and ''UTF8'' font ''encoding'' for file names, so media titles in your language are readable when browsing ''Media_DB'' in terminal and media players, since most support ''UTF8''. If you prefer '''Vfat''' (FAT32) for better USB drive compatibility with older players when hooked directly, or your ''Media_Collection'' drive is Vfat and has folder & file names in your local language, MiniDLNA can transcode them to ''UTF8'' charset while scanning folders to ''Media_DB''. Add to ''Media_Collection'' and ''Media_DB'' drives' mount options your FS language [[wikipedia:Code_page|codepage]] for transcoding to short DOS file names, and [[wikipedia:Character_encoding|iocharset]] for converting long file names to your terminal's locale, i.g. ''codepage=cp866,iocharset=utf8 (or ISO-8859-5)''. Set ''rw'' permissions for all users, since ''Vfat'' does not preserve Linux access permissions:
  
 
{{bc|1=UUID=6140-75F7 /media/MyDrive/Media_DB vfat user,rw,async,noatime,umask=111,dmask=000,codepage=cp866,iocharset=utf8 0 0}}
 
{{bc|1=UUID=6140-75F7 /media/MyDrive/Media_DB vfat user,rw,async,noatime,umask=111,dmask=000,codepage=cp866,iocharset=utf8 0 0}}
Line 108: Line 123:
 
  ls /usr/share/fonts/encodings
 
  ls /usr/share/fonts/encodings
  
MiniDLNA lists ''Movies'' and ''Photos'' by file name in its DB, and ''Music'' entries by [http://id3lib.sourceforge.net/id3/ ID3 tags] instead of file names. If Music collection wasn't tagged in UTF8 but in a local charset, MiniDLNA might not identify and transcode it correctly to UTF8 for display in media players, or the original tags ''codepage(s)'' may be absent in your system, so the tags won't be readable even when media file names are. In this case consider re-tagging your collection to ''UTF-16BE'' or ''UTF-8'' encoding with an '''ID3 Tag Converter'''.
+
MiniDLNA lists ''Movies'' and ''Photos'' by file name in its DB, and ''Music'' entries by [http://id3lib.sourceforge.net/id3/ ID3 tags] instead of file names. If Music collection was not tagged in UTF8 but in a local charset, MiniDLNA might not identify and transcode it correctly to UTF8 for display in media players, or the original tags ''codepage(s)'' may be absent in your system, so the tags will not be readable even when media file names are. In this case consider re-tagging your collection to ''UTF-16BE'' or ''UTF-8'' encoding with an '''ID3 Tag Converter'''.
  
Picking the "right" ''file system'' for your ''Media_Collection'' is a trade-off: XFS and EXT4 show fast read/write for HDs and lower CPU load critical for small [http://archlinuxarm.org/platforms/armv5/pogoplug-series-4 Plug Computers] with attached storage. NTFS is most compatible with Windows when plugging a drive directly for faster copy, while network file systems like Samba, NFS or iSCSI allow import to Windows any Linux FS with slower data copy. As file fragmentation affects playback, store your Movies on a non-system drive formatted in XFS (prevents fragments), NTFS (fragment resistant and easy to defrag), or EXT4 (uses large file ''extents''), and [https://trac.transmissionbt.com/ticket/849 avoid] EXT3 or [http://en.wikipedia.org/wiki/File_Allocation_Table#Fragmentation less] resistant FAT32. For smaller Flash drives with seldom fragmented Music and Photo files, VFAT (FAT32) and EXT4 show faster writes with less CPU load, but EXT4 may affect memory wear due to journaling, and less compatible with media players. Proper drive partitioning, block [http://lwn.net/Articles/428584/ alignment] and ''mount options'' (i.e. ''async,noatime''...- choice depends on file system and memory type) can greatly [http://linux-howto-guide.blogspot.ca/2009/10/increase-usb-flash-drive-write-speed.html accelerate] flash and HD drive speed among other [http://en.wikipedia.org/w/index.php?title=Logical_Disk_Manager&section=6 advantages].
+
Picking the "right" ''file system'' for your ''Media_Collection'' is a trade-off: XFS and EXT4 show fast read/write for HDs and lower CPU load critical for small [http://archlinuxarm.org/platforms/armv5/pogoplug-series-4 Plug Computers] with attached storage. NTFS is most compatible with Windows when plugging a drive directly for faster copy, while network file systems like Samba, NFS or iSCSI allow import to Windows any Linux FS with slower data copy. As file fragmentation affects playback, store your Movies on a non-system drive formatted in XFS (prevents fragments), NTFS (fragment resistant and easy to defrag), or EXT4 (uses large file ''extents''), and [https://trac.transmissionbt.com/ticket/849 avoid] EXT3 or [[wikipedia:File_Allocation_Table#Fragmentation|less]] resistant FAT32. For smaller Flash drives with seldom fragmented Music and Photo files, VFAT (FAT32) and EXT4 show faster writes with less CPU load, but EXT4 may affect memory wear due to journaling, and less compatible with media players. Proper drive partitioning, block [http://lwn.net/Articles/428584/ alignment] and ''mount options'' (i.e. ''async,noatime''...- choice depends on file system and memory type) can greatly [http://linux-howto-guide.blogspot.ca/2009/10/increase-usb-flash-drive-write-speed.html accelerate] flash and HD drive speed among other [[wikipedia:Logical_Disk_Manager#Advantages_of_using_a_1-MiB_alignment_boundary|advantages]].
  
 
=== Media Handling ===
 
=== Media Handling ===
  
MiniDLNA is aimed for small devices, so doesn't generate movie thumbnails to lower CPU load and DB built time. It uses either thumbs in the same folder with movie if any, or extracts them where present from media containers like MP4 or MKV with embedded Album Art tags, but not AVI. One can add thumbs (JPG 160x160 pxl or less) to media folders with a '''Thumbnail Maker''', and miniDLNA will link them to media files after rescan. Larger thumbs will be resized and stored in ''Media_DB'' that slows scan. At one movie per folder, follow thumb naming rules in ''minidlna.conf''. For multiple show episodes per folder, each thumb name should match its episode name without ext. (''<file>.cover.jpg'' or ''<file>.jpg''). To handle ''MS Album Art'' thumb names with GUID, add * to the end ''"AlbumArt_{*".jpg'' . MiniDLNA will list on screen only chosen media type (i.e. Movies), but won't other files in the same folder.
+
MiniDLNA is aimed for small devices, so does not generate movie thumbnails to lower CPU load and DB built time. It uses either thumbs in the same folder with movie if any, or extracts them where present from media containers like MP4 or MKV with embedded Album Art tags, but not AVI. One can add thumbs (JPG 160x160 pxl or less) to media folders with a '''Thumbnail Maker''', and miniDLNA will link them to media files after rescan. Larger thumbs will be resized and stored in ''Media_DB'' that slows scan. At one movie per folder, follow thumb naming rules in ''minidlna.conf''. For multiple show episodes per folder, each thumb name should match its episode name without ext. (''<file>.cover.jpg'' or ''<file>.jpg''). To handle ''MS Album Art'' thumb names with GUID, add * to the end ''"AlbumArt_{*".jpg'' . MiniDLNA will list on screen only chosen media type (i.e. Movies), but will not other files in the same folder.
 +
 
 +
When viewing photos, progressive and/or lossless compression JPG may not be supported by your player via DLNA. Also resize photos to "suggested photo size" by the player's docs for problem free image slideshow. DLNA spec restricts image type to JPG or PNG, and max size to 4096 x 4096 pixels - and that is if the DLNA server implementation supports the LARGE format. The next size limit down (MEDIUM) is 1024 x 768, so resizing may help to show photos correctly.
 +
 
 +
To decrease system load, MiniDLNA does not transcode on the fly unsupported media files into supported by your player formats. When building ''Media_DB'', it might not correctly identify whether certain formats are supported by your player, which may play via UPnP a broader formats choice. DLNA standard is quite limiting UPnP subset in media containers and codec ''profiles'' allowed. If you do not see on TV screen or cannot play some media files listed in ''Media_DB'', check if your HD started spinning or try connecting to your media player via USB for their playback. MiniDLNA might not support choosing audio tracks, subtitles, disk chapters, list sorting, and other advanced playback features for your player model.
 +
 
 +
== Building a media server ==
 +
Media served could be based on lightweight and cheap system like development board (Raspberry Pi, CubeBoard, etc.). You do not even need to put X Server on this board.
 +
 
 +
=== Automount external drives ===
 +
To make external plugged drives mounted automaticly the following scripts could be used:
 +
Rules for udev {{ic|/etc/udev/rules.d/automount.rules}}
 +
 
 +
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
 +
ACTION=="add", ENV{DEVTYPE}=="partition", RUN+="domount %N", GOTO="media_by_label_auto_mount_end"
 +
ACTION=="add", KERNEL=="sd[a-z]*", PROGRAM="/sbin/blkid -p -o value -s TYPE %N", RESULT!="", RUN+="domount %N", GOTO="media_by_label_auto_mount_end"
 +
ACTION=="remove", ENV{DEVTYPE}=="partition", RUN+="doumount %N", GOTO="media_by_label_auto_mount_end"
 +
ACTION=="remove", KERNEL=="sd[a-z]*", RUN+="doumount %N", GOTO="media_by_label_auto_mount_end"
 +
LABEL="media_by_label_auto_mount_end"
 +
 
 +
This rule call domount script each time drive is plugged. Script doumount called when you unplug your drive.
 +
It mounts drive in /mnt/media and create symlink to /media {{ic|/usr/lib/udev/domount}}:
 +
 
 +
#!/bin/sh
 +
#edit the following variables to suit your needs
 +
MYUID=1001              # your user uid
 +
MYGID=1001              # your user gid
 +
MYLOGIN=share            # your login
 +
TMPFILE=`basename $1`
 +
MYUUID=`blkid -p -o value -s LABEL $*`
 +
if [ "x$MYUUID" = "x" ]; then
 +
    MYUUID=`blkid -p -o value -s UUID $*`
 +
fi
 +
FSTYPE=`blkid -p -o value -s TYPE $*`
 +
EXT4_OPTS=""
 +
if [[ $FSTYPE = "ext4" ]]; then
 +
    EXT4_OPTS="defaults,noatime,data=writeback,barrier=0,nobh"
 +
fi
 +
DIR=/mnt/media/$MYUUID
 +
DIR1=/media/$MYUUID
 +
mkdir -p /mnt/media
 +
mkdir -p /media
 +
cat > /run/m.$TMPFILE << EOF
 +
#!/bin/sh
 +
echo "$* will be mounted on $DIR. "
 +
mkdir -p "$DIR"
 +
chown $MYLOGIN:$MYLOGIN "$DIR"
 +
if [ "x$EXT4_OPTS" = "x" ]; then
 +
    /bin/mount -o uid=$MYUID,gid=$MYGID $* "$DIR"
 +
else
 +
    /bin/mount -o $EXT4_OPTS $* "$DIR"
 +
fi
 +
rm "$DIR1"
 +
rmdir "$DIR1"
 +
ln -s "$DIR" /media
 +
EOF
 +
cat > /run/u.$TMPFILE << EOF
 +
#!/bin/sh
 +
echo "$* will be unmounted on $DIR. "
 +
/bin/umount -f -l "$DIR"
 +
rmdir "$DIR"
 +
rm "$DIR1"
 +
EOF
 +
chmod a+x /run/m.$TMPFILE
 +
chmod a+x /run/u.$TMPFILE
 +
at -f /run/m.$TMPFILE now + 1 min
 +
 
 +
You need to change MYLOGIN and MYUID/MYGID to your IDs
 +
 
 +
Unmount script {{ic|/usr/lib/udev/doumount}}:
 +
 
 +
#!/bin/sh
 +
TMPFILE=`basename $1`
 +
echo $TMPFILE> /run/doumount
 +
/run/u.$TMPFILE
  
When viewing photos, progressive and/or lossless compression JPG may not be supported by your player via DLNA. Also resize photos to "suggested photo size" by the player's docs for problem free image slideshow. DLNA spec restricts image type to JPG or PNG, and max size to 4096 x 4096 pixels - and that's if the DLNA server implementation supports the LARGE format. The next size limit down (MEDIUM) is 1024 x 768, so resizing may help to show photos correctly.
+
Now you could put something like "media_dir=V,/media" in your {{ic|/etc/minidlna.conf}} file
  
To decrease system load, MiniDLNA doesn't transcode on the fly unsupported media files into supported by your player formats. When building ''Media_DB'', it might not correctly identify whether certain formats are supported by your player, which may play via UPnP a broader formats choice. DLNA standard is quite limiting UPnP subset in media containers and codec ''profiles'' allowed. If you don't see on TV screen or can't play some media files listed in ''Media_DB'', check if your HD started spinning or try connecting to your media player via USB for their playback. MiniDLNA might not support choosing audio tracks, subtitles, disk chapters, list sorting, and other advanced playback features for your player model.
+
===Issues===
 +
Media server based on MiniDLNA could face the drive re-scan issue. Ex.: external HDD you have plugged will be scanned each time again and again. This happens due to MiniDLNA removes DB records for unplugged drive. If your drive plugged all the time it is not a problem, but if you have "pluggable" media library on large external drives this could take a big while till you start watching your video.

Revision as of 01:58, 27 July 2013

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: miniDLNA has been updated by the developer. Pending more transitions, it is being renamed to "ReadyMedia", with an inbuilt daemon and different .conf files, locations, paths, and more. Many elements of this guide still apply, however. (Discuss in Talk:ReadyMedia#)

MiniDLNA is server software with the aim of being fully compliant with DLNA/UPnP clients. The MiniDNLA daemon serves media files (music, pictures, and video) to clients on a network. Example clients include applications such as totem and xbmc, and devices such as portable media players, Smartphones, Televisions, and gaming systems (such as PS3 and Xbox 360).

MiniDLNA (ReadyDLNA) is a simple, lightweight alternative to MediaTomb, but has fewer features. It does not have a web interface for administration and must be configured by editing a text file.

Installation

Install minidlna from the official repositories.

Configuration

The MiniDLNA daemon can be run as either a global (config:/etc/minidlna.conf) or per-user instance (config:user-defined), these are the necessary common settings:

#network_interface=eth0                         # Self-discovers if commented (at times necessary to set)
media_dir=A,/home/user/Music                    # Mounted Media_Collection drive directories
media_dir=P,/home/user/Pictures                 # Use A, P, and V to restrict media 'type' in directory
media_dir=V,/home/user/Videos
friendly_name=Media Server                      # Optional
db_dir=/var/cache/minidlna                      # MiniDLNA Media_DB dir needs to be un-commented
log_dir=/var/log                                # Log dir needs to be un-commented
inotify=yes                                     # 'no' for less resources, restart required for new media
presentation_url=http://www.mylan/index.php     # or use your device static IP http://192.168.0.14:8200/

Global

MiniDLNA scans your Media_Collection at startup and creates or updates database Media_DB browsable via media players. Set database cache and logging dirs in config, so the db and album art cache will not be re-created on every restart. By default MiniDLNA runs as nobody user without shell access as set in /etc/conf.d/minidlna, unless you set your own. That user needs rw permissions to cache and log directories you specified in conf. Create the required directories and chown them to nobody:nobody. You can also specify a user to run as via the minidlna.conf file by setting

#user=jmaggard

Default cache and log directories need to be created and chowned to the chosen user.

# mkdir /var/{cache,log}/minidlna
# chown nobody:nobody /var/{cache,log}/minidlna

If you change MiniDLNA user, you can login as that user and create a symbolic link in the default Media_DB directory to a mounted in the system external Media_Collection drive, just make sure to set the user's rw permissions and other mount options for the drive in fstab if present at boot, or udev automount rules if attached after boot:

# ln -s /media/MyDrive/Media_DB /var/cache/minidlna

Service

The minidlna service can be managed by the minidlna daemon.

Troubleshooting service autostart

Sometimes the minidlna daemon fails to start while booting. NetworkManager#Enable_NetworkManager_Wait_Online solves this issue. See FS#35325

Local

Create the necessary files and directories locally and edit the configuration:

# install -Dm644 /etc/minidlna.conf ~/.config/minidlna/minidlna.conf
# $EDITOR minidlna.conf

Configuring should be as above, specifically:

media_dir=/home/$USER/dir
db_dir=/home/$USER/.config/minidlna/cache
log_dir=/home/$USER/.config/minidlna

As of version 1.1.0, a daemon is included in the minidlna package, which is confusingly also called "minidlnad", similar to the previous method detailed below. To run, simply call:

# minidlnad

Previously, a local daemon script to stop, start... MiniDLNA was available in the AUR (minidlnadAUR) along with an autostart .desktop file. To run:

# minidlnad
 minidlnad [start|stop|restart|rescan] - actions for the MiniDLNA daemon

Alternatively you can autostart by adding in your .bash_profile :

minidlna -f /home/$USER/.config/minidlna/minidlna.conf -P /home/$USER/.config/minidlna/minidlna.pid

Automatic Media_DB Update

Kernel adds one inotify watch per each folder/subfolder in Media_Collection Directories set in /etc/minidlna.conf to monitor changes thus allowing MiniDLNA to update Media_DB in real time. When MiniDLNA is run as a regular user, it does not have the ability to change the kernel's inotify limits. If default number of inotify watches is non-sufficient to have MiniDLNA monitor all your media folders, increase inotify watches through sysctl (100000 should be enough for most uses):

# sudo sysctl fs.inotify.max_user_watches=100000

To have it permanently changed, add to /etc/sysctl.conf

# Increase inotify max watchs per user for local minidlna
fs.inotify.max_user_watches = 100000

inotify performance may depend on device type. Some do not rescan media drives on a consistent basis or at all. If files are added/deleted to monitored media directories, they may not be noticed until the device DLNA client is restarted.

Check inotify updates via MiniDLNA presentation_url by comparing files count. If it does not change, make sure the user running MiniDLNA has rw access to the DB folder. If the issue persists, copy or download new files first to a non-watched by inotify Downloads folder on the same drive, and then move them to appropriate media folders, since lengthy media files copying or downloading may confuse inotify.

You can also clean or rebuild MiniDLNA DB manually after stopping MiniDLNA daemon, or analyze its debug output (Ctrl+C to exit):

Stop the MiniDLNA daemon:

# systemctl stop minidlna

To rebuild Media_DB forcibly:

$ sudo -u nobody minidlna -R

Stop the daemon after rebuilding Media_DB e.g. killall minidlna.

To run in debug mode:

$ sudo -u nobody minidlna -d

Template:Keypress to exit it.

Other aspects

Other aspects and MiniDLNA limitations may need to be considered beforehand to ensure satisfaction from its performance.

Firewall

If using a firewall the the ssdp (1900/udp) and trivnet1 (8200/tcp) ports will need to be opened. For example, this can be done with arno's iptables firewall by editing firewall.conf and opening the ports by doing:

OPEN_TCP="8200"
OPEN_UDP="1900"

File System and Localization

When keeping MiniDLNA Media_DB on an external drive accessible in both Linux and Windows, choose proper file system for it. NTFS preserves in Windows its Linux defaults: rw access for root user and UTF8 font encoding for file names, so media titles in your language are readable when browsing Media_DB in terminal and media players, since most support UTF8. If you prefer Vfat (FAT32) for better USB drive compatibility with older players when hooked directly, or your Media_Collection drive is Vfat and has folder & file names in your local language, MiniDLNA can transcode them to UTF8 charset while scanning folders to Media_DB. Add to Media_Collection and Media_DB drives' mount options your FS language codepage for transcoding to short DOS file names, and iocharset for converting long file names to your terminal's locale, i.g. codepage=cp866,iocharset=utf8 (or ISO-8859-5). Set rw permissions for all users, since Vfat does not preserve Linux access permissions:

UUID=6140-75F7 /media/MyDrive/Media_DB vfat user,rw,async,noatime,umask=111,dmask=000,codepage=cp866,iocharset=utf8 0 0

While your iocharset would be present in the system with a matching locale, if your terminal or player supports only short file names, check if the set codepage is also present and enabled (like ru_RU.CP866), i.e. was included in system config when ArchLinux release was compiled, or consider recompiling the release to add it:

ls /usr/share/fonts/encodings

MiniDLNA lists Movies and Photos by file name in its DB, and Music entries by ID3 tags instead of file names. If Music collection was not tagged in UTF8 but in a local charset, MiniDLNA might not identify and transcode it correctly to UTF8 for display in media players, or the original tags codepage(s) may be absent in your system, so the tags will not be readable even when media file names are. In this case consider re-tagging your collection to UTF-16BE or UTF-8 encoding with an ID3 Tag Converter.

Picking the "right" file system for your Media_Collection is a trade-off: XFS and EXT4 show fast read/write for HDs and lower CPU load critical for small Plug Computers with attached storage. NTFS is most compatible with Windows when plugging a drive directly for faster copy, while network file systems like Samba, NFS or iSCSI allow import to Windows any Linux FS with slower data copy. As file fragmentation affects playback, store your Movies on a non-system drive formatted in XFS (prevents fragments), NTFS (fragment resistant and easy to defrag), or EXT4 (uses large file extents), and avoid EXT3 or less resistant FAT32. For smaller Flash drives with seldom fragmented Music and Photo files, VFAT (FAT32) and EXT4 show faster writes with less CPU load, but EXT4 may affect memory wear due to journaling, and less compatible with media players. Proper drive partitioning, block alignment and mount options (i.e. async,noatime...- choice depends on file system and memory type) can greatly accelerate flash and HD drive speed among other advantages.

Media Handling

MiniDLNA is aimed for small devices, so does not generate movie thumbnails to lower CPU load and DB built time. It uses either thumbs in the same folder with movie if any, or extracts them where present from media containers like MP4 or MKV with embedded Album Art tags, but not AVI. One can add thumbs (JPG 160x160 pxl or less) to media folders with a Thumbnail Maker, and miniDLNA will link them to media files after rescan. Larger thumbs will be resized and stored in Media_DB that slows scan. At one movie per folder, follow thumb naming rules in minidlna.conf. For multiple show episodes per folder, each thumb name should match its episode name without ext. (<file>.cover.jpg or <file>.jpg). To handle MS Album Art thumb names with GUID, add * to the end "AlbumArt_{*".jpg . MiniDLNA will list on screen only chosen media type (i.e. Movies), but will not other files in the same folder.

When viewing photos, progressive and/or lossless compression JPG may not be supported by your player via DLNA. Also resize photos to "suggested photo size" by the player's docs for problem free image slideshow. DLNA spec restricts image type to JPG or PNG, and max size to 4096 x 4096 pixels - and that is if the DLNA server implementation supports the LARGE format. The next size limit down (MEDIUM) is 1024 x 768, so resizing may help to show photos correctly.

To decrease system load, MiniDLNA does not transcode on the fly unsupported media files into supported by your player formats. When building Media_DB, it might not correctly identify whether certain formats are supported by your player, which may play via UPnP a broader formats choice. DLNA standard is quite limiting UPnP subset in media containers and codec profiles allowed. If you do not see on TV screen or cannot play some media files listed in Media_DB, check if your HD started spinning or try connecting to your media player via USB for their playback. MiniDLNA might not support choosing audio tracks, subtitles, disk chapters, list sorting, and other advanced playback features for your player model.

Building a media server

Media served could be based on lightweight and cheap system like development board (Raspberry Pi, CubeBoard, etc.). You do not even need to put X Server on this board.

Automount external drives

To make external plugged drives mounted automaticly the following scripts could be used: Rules for udev /etc/udev/rules.d/automount.rules

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
ACTION=="add", ENV{DEVTYPE}=="partition", RUN+="domount %N", GOTO="media_by_label_auto_mount_end"
ACTION=="add", KERNEL=="sd[a-z]*", PROGRAM="/sbin/blkid -p -o value -s TYPE %N", RESULT!="", RUN+="domount %N", GOTO="media_by_label_auto_mount_end"
ACTION=="remove", ENV{DEVTYPE}=="partition", RUN+="doumount %N", GOTO="media_by_label_auto_mount_end"
ACTION=="remove", KERNEL=="sd[a-z]*", RUN+="doumount %N", GOTO="media_by_label_auto_mount_end"
LABEL="media_by_label_auto_mount_end"

This rule call domount script each time drive is plugged. Script doumount called when you unplug your drive. It mounts drive in /mnt/media and create symlink to /media /usr/lib/udev/domount:

#!/bin/sh
#edit the following variables to suit your needs
MYUID=1001              # your user uid
MYGID=1001              # your user gid
MYLOGIN=share            # your login
TMPFILE=`basename $1`
MYUUID=`blkid -p -o value -s LABEL $*`
if [ "x$MYUUID" = "x" ]; then
   MYUUID=`blkid -p -o value -s UUID $*`
fi
FSTYPE=`blkid -p -o value -s TYPE $*`
EXT4_OPTS=""
if  $FSTYPE = "ext4" ; then
   EXT4_OPTS="defaults,noatime,data=writeback,barrier=0,nobh"
fi
DIR=/mnt/media/$MYUUID
DIR1=/media/$MYUUID
mkdir -p /mnt/media
mkdir -p /media
cat > /run/m.$TMPFILE << EOF
#!/bin/sh
echo "$* will be mounted on $DIR. "
mkdir -p "$DIR"
chown $MYLOGIN:$MYLOGIN "$DIR"
if [ "x$EXT4_OPTS" = "x" ]; then
   /bin/mount -o uid=$MYUID,gid=$MYGID $* "$DIR"
else
   /bin/mount -o $EXT4_OPTS $* "$DIR"
fi
rm "$DIR1"
rmdir "$DIR1"
ln -s "$DIR" /media
EOF
cat > /run/u.$TMPFILE << EOF
#!/bin/sh
echo "$* will be unmounted on $DIR. "
/bin/umount -f -l "$DIR"
rmdir "$DIR"
rm "$DIR1"
EOF
chmod a+x /run/m.$TMPFILE
chmod a+x /run/u.$TMPFILE
at -f /run/m.$TMPFILE now + 1 min

You need to change MYLOGIN and MYUID/MYGID to your IDs

Unmount script /usr/lib/udev/doumount:

#!/bin/sh
TMPFILE=`basename $1`
echo $TMPFILE> /run/doumount
/run/u.$TMPFILE

Now you could put something like "media_dir=V,/media" in your /etc/minidlna.conf file

Issues

Media server based on MiniDLNA could face the drive re-scan issue. Ex.: external HDD you have plugged will be scanned each time again and again. This happens due to MiniDLNA removes DB records for unplugged drive. If your drive plugged all the time it is not a problem, but if you have "pluggable" media library on large external drives this could take a big while till you start watching your video.