MediaTomb
From Gentoo Linux Wiki
Contents |
[edit] Introduction
MediaTomb is an open source (GPL) UPnP MediaServer with a nice web user interface. It allows you to stream your digital media through your home network and access it on a variety of UPnP compatible devices.
[edit] Preparation
[edit] Kernel Configuration
[edit] Inotify
MediaTomb supports Inotify which is a file-monitoring mechanism that allows MediaTomb to be notified about changes to files immediately. For more information, please consult Section 2.1.5 of the MediaTomb User Interface documentation.
- To enable Inotify support, build your kernel with the following options.
| Linux Kernel Configuration: Inotify |
File systems ---> [*] Inotify support for userspace |
[edit] Package Configuration
[edit] USE Flags
| USE | Description | Recommended |
| debug | Enables debug output support. | - |
| exif | Enables image (EXIF) metadata extraction support. | Yes |
| ffmpeg | Enables audio and video metadata extraction including FourCC processing support. | Yes |
| inotify | Enables Inotify autoscan support. | Yes |
| javascript | Enables SpiderMonkey JavaScript engine support. If this USE flag is enabled, a virtual container layout based on the extracted metadata will be created. | Yes |
| lastfm | Enables last.fm support. | - |
| libextractor | Enables audio, image and video metadata extraction support. If this USE flag is enabled, media import speed will be slowed considerably. | No |
| mp4 | Enables MP4 metadata extraction support. | Yes |
| mysql | Enables MySQL backend support. If this USE flag is disabled, SQLite will be used by default. | - |
| taglib | Enables audio metadata extraction support. If this USE flag is disabled, id3lib will be used by default. | Yes |
| thumbnail | Enables video thumbnail generation support. | - |
[edit] Installation
- To install MediaTomb:
[edit] Configuration
[edit] Network
- To set the interface that MediaTomb binds to, add the following to the MEDIATOMB_OPTIONS variable.
MEDIATOMB_OPTIONS="-e eth0"
- To set the IP address that MediaTomb binds to, add the following to the MEDIATOMB_OPTIONS variable.
MEDIATOMB_OPTIONS="-i 192.168.0.1"
[edit] MySQL
- To enable MySQL support, set the enabled attribute to yes for the <mysql> element.
<mysql enabled="yes">
- Set the enabled attribute to no for the <sqlite3> element.
<sqlite3 enabled="no">
- Set the <host>, <database>, <username> and <password> elements.
<host>host</host>
<database>database</database>
<username>username</username>
<password>password</password>
- Login to MySQL and create the MediaTomb database and user, using the host, database, username and password values set in the MediaTomb configuration file.
mysql> CREATE DATABASE database; mysql> GRANT ALL ON database.* TO 'username'@'host' IDENTIFIED BY 'password';
[edit] Transcoding
MediaTomb allows you to transcode unsupported media files to formats that are supported by your UPnP device. The default Gentoo configuration file uses FFmpeg to transcode FLAC, Flash, Theora and Vorbis files. For more information, please consult section 6.3 of the MediaTomb documentation.
- To enable transcoding support, set the enabled attribute to yes for the <transcoding> element.
<transcoding enabled="yes">
- For every additional mimetype that requires transcoding, add the following section in between the <mimetype-profile-mappings> and </mimetype-profile-mappings> elements and substitute mimetype and profile with the appropriate values e.g. <transcode mimetype="video/quicktime" using="video2mpeg"/>
<transcode mimetype="mimetype" using="profile"/>
- Install FFmpeg.
[edit] Alternative Transcoders
MediaTomb's transcoding support is very flexible and any application capable of transcoding can be used. For more information, please consult the MediaTomb Transcoding documentation.
[edit] VLC
Audio
- To enable VLC audio transcoding, replace the <agent> element for the audio2pcm profile with the following.
<agent command="vlc" arguments="%in -I dummy --sout=#transcode{acodec=s16b,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=raw,dst=%out} vlc://quit"/>
- Set the <accept-url> element to yes for the audio2pcm profile.
<accept-url>yes</accept-url>
Video
- To enable VLC video transcoding, replace the <agent> element for the video2mpeg profile with the following.
<agent command="vlc" arguments="%in -I dummy --sout=#transcode{vcodec=mp2v,vb=4096,fps=25,acodec=mpga,ab=192,samplerate=48000,channels=2,audio-sync}:standard{access=file,mux=ps,dst=%out} vlc://quit"/>
- Set the <accept-url> element to yes for the video2mpeg profile.
<accept-url>yes</accept-url>
- Install VLC.
[edit] MPlayer
Video
- To enable MPlayer video transcoding, replace the <agent> element for the video2mpeg profile with the following.
<agent command="mencoder" arguments="%in -o %out -ovc lavc -oac lavc -lavcopts vcodec=mpeg2video:vbitrate=4096:vrc_minrate=0:vrc_maxrate=9800:vrc_buf_size=1835:keyint=15:vstrict=0:acodec=mp2:abitrate=192
-vf harddup -af lavcresample=48000:channels=2 -srate 48000 -ofps 25 -of mpeg -mpegopts format=mpeg2:tsaf"/>
- Set the <accept-url> element to yes for the video2mpeg profile.
<accept-url>yes</accept-url>
- Install MPlayer.
[edit] PlayStation 3
- To enable PlayStation 3 support, set the extend attribute to yes for the <protocolInfo> element.
<protocolInfo extend="yes"/>
[edit] DivX
- To enable PlayStation 3 DivX support, add the following section in between the <extension-mimetype ignore-unknown="no"> and </extension-mimetype> elements.
<map from="avi" to="video/divx"/>
- Add the following section in between the <mimetype-contenttype> and </mimetype-contenttype> elements.
<treat mimetype="video/divx" as="avi"/>
[edit] Online Services
MediaTomb allows you to stream online content to your UPnP device from services such as YouTube. For more information, please consult Section 6.2.1 of the MediaTomb documentation.
[edit] YouTube
- To enable YouTube support, set the enabled attribute to yes for the <YouTube> element.
<YouTube enabled="yes" refresh="28800" update-at-start="yes" purge-after="604800" racy-content="exclude" format="mp4" hd="no">
- If you want to view YouTube videos in high definition (if available), set the hd attribute to yes for the <YouTube> element.
<YouTube enabled="yes" refresh="28800" update-at-start="yes" purge-after="604800" racy-content="exclude" format="mp4" hd="yes">
- If your UPnP device doesn't support MP4 videos, enable transcoding and add the following section in between the <mimetype-profile-mappings> and </mimetype-profile-mappings> elements.
<transcode mimetype="video/mp4" using="video2mpeg"/>
[edit] Video Thumbnails
- To enable video thumbnail support, set the enabled attribute to yes for the <ffmpegthumbnailer> element.
<ffmpegthumbnailer enabled="yes">
- If you want to overlay a filmstrip border on the generated thumbnail, set the <filmstrip-overlay> element to yes.
<filmstrip-overlay>yes</filmstrip-overlay>
- If you have a DLNA compliant device that supports video thumbnails (i.e. PlayStation 3), set the extend attribute to yes for the <protocolInfo> element.
<protocolInfo extend="yes"/>
[edit] Raw Images
- To enable (Canon CR2 and Nikon NEF) raw image support, enable transcoding and add the following section in between the <profile> and </profile> elements.
<profile name="raw2jpeg" enabled="yes" type="external">
<mimetype>image/jpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<agent command="/usr/local/bin/mediatomb-raw2jpeg" arguments="%in %out"/>
<buffer size="524288" chunk-size="512" fill-size="1024"/>
</profile>
- Add the following section in between the <mimetype-profile-mappings> and </mimetype-profile-mappings> elements.
<transcode mimetype="image/raw" using="raw2jpeg"/>
- For every additional raw image format (supported by dcraw), add the following section in between the <extension-mimetype ignore-unknown="no"> and </extension-mimetype> elements and substitute extension with the appropriate value e.g. <map from="kdc" to="image/raw"/>
<map from="extension" to="image/raw"/>
- Create the following script.
#!/bin/bash
DCRAW_PATH="/usr/bin/dcraw"
INPUT="$1"
OUTPUT="$2"
exec "${DCRAW_PATH}" -e -c "${INPUT}" > "${OUTPUT}"
- Install dcraw.
[edit] Starting
- To start MediaTomb:
- To start MediaTomb at boot:
[edit] Complete Working Setup
[edit] Requirements
- media-video/ffmpeg encode
- media-video/vlc ffmpeg stream
- media-gfx/dcraw (including the mediatomb-raw2jpeg script)
- net-misc/mediatomb exif ffmpeg inotify javascript mp4 taglib thumbnail -mysql
[edit] Supported Formats
- Audio: AAC, FLAC*, M4A, MP3, Vorbis*, WAV, WMA.
- Images: GIF, JPEG, PNG, Raw* (Canon CR2, Nikon NEF).
- Video: AVI, DivX, Flash*, M2TS, MP4, MPEG-2, MKV*, Theora*, QuickTime*, WMV.
* Available via transcoding.
[edit] Configuration File
The following configuration file is optimised for the PlayStation 3 but should also work with other UPnP devices.
<?xml version="1.0" encoding="UTF-8"?>
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/2 http://mediatomb.cc/config/2.xsd">
<server>
<ui enabled="yes" show-tooltips="yes">
<accounts enabled="no" session-timeout="30">
<account user="mediatomb" password="mediatomb"/>
</accounts>
</ui>
<name>MediaTomb</name>
<udn></udn>
<home>/var/lib/mediatomb</home>
<webroot>/usr/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.db</database-file>
</sqlite3>
<mysql enabled="no">
<host>host</host>
<database>database</database>
<username>username</username>
<password>password</password>
</mysql>
</storage>
<protocolInfo extend="yes"/>
<pc-directory upnp-hide="no"/>
<extended-runtime-options>
<ffmpegthumbnailer enabled="yes">
<thumbnail-size>160</thumbnail-size>
<seek-percentage>10</seek-percentage>
<filmstrip-overlay>no</filmstrip-overlay>
<workaround-bugs>no</workaround-bugs>
<image-quality>8</image-quality>
</ffmpegthumbnailer>
<mark-played-items enabled="no" suppress-cds-updates="yes">
<string mode="prepend">*</string>
<mark>
<content>video</content>
</mark>
</mark-played-items>
<lastfm enabled="no">
<username>username</username>
<password>password</password>
</lastfm>
</extended-runtime-options>
</server>
<import hidden-files="no">
<scripting script-charset="UTF-8">
<common-script>/usr/share/mediatomb/js/common.js</common-script>
<playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
<virtual-layout type="builtin">
<import-script>/usr/share/mediatomb/js/import.js</import-script>
</virtual-layout>
</scripting>
<mappings>
<extension-mimetype ignore-unknown="no">
<map from="mp3" to="audio/mpeg"/>
<map from="ogx" to="application/ogg"/>
<map from="ogv" to="video/ogg"/>
<map from="oga" to="audio/ogg"/>
<map from="ogg" to="audio/ogg"/>
<map from="ogm" to="video/ogg"/>
<map from="asf" to="video/x-ms-asf"/>
<map from="asx" to="video/x-ms-asf"/>
<map from="wma" to="audio/x-ms-wma"/>
<map from="wax" to="audio/x-ms-wax"/>
<map from="wmv" to="video/x-ms-wmv"/>
<map from="wvx" to="video/x-ms-wvx"/>
<map from="wm" to="video/x-ms-wm"/>
<map from="wmx" to="video/x-ms-wmx"/>
<map from="m3u" to="audio/x-mpegurl"/>
<map from="pls" to="audio/x-scpls"/>
<map from="flv" to="video/x-flv"/>
<map from="mkv" to="video/x-matroska"/>
<map from="mka" to="audio/x-matroska"/>
<map from="avi" to="video/divx"/>
<map from="m2ts" to="video/avc"/>
<map from="m4a" to="audio/mp4"/>
<map from="m4v" to="video/mp4"/>
<map from="cr2" to="image/raw"/>
<map from="nef" to="image/raw"/>
</extension-mimetype>
<mimetype-upnpclass>
<map from="audio/*" to="object.item.audioItem.musicTrack"/>
<map from="video/*" to="object.item.videoItem"/>
<map from="image/*" to="object.item.imageItem"/>
</mimetype-upnpclass>
<mimetype-contenttype>
<treat mimetype="audio/mpeg" as="mp3"/>
<treat mimetype="application/ogg" as="ogg"/>
<treat mimetype="video/ogg" as="ogg"/>
<treat mimetype="audio/ogg" as="ogg"/>
<treat mimetype="audio/x-flac" as="flac"/>
<treat mimetype="image/jpeg" as="jpg"/>
<treat mimetype="audio/x-mpegurl" as="playlist"/>
<treat mimetype="audio/x-scpls" as="playlist"/>
<treat mimetype="audio/x-wav" as="pcm"/>
<treat mimetype="audio/L16" as="pcm"/>
<treat mimetype="video/x-msvideo" as="avi"/>
<treat mimetype="video/mp4" as="mp4"/>
<treat mimetype="audio/mp4" as="mp4"/>
<treat mimetype="video/divx" as="avi"/>
</mimetype-contenttype>
</mappings>
<online-content>
<YouTube enabled="no" refresh="28800" update-at-start="yes" purge-after="604800" racy-content="exclude" format="mp4" hd="no">
<favorites user="NationalGeographic"/>
<playlists user="PlayStation"/>
<uploads user="Google"/>
<standardfeed feed="most_viewed" time-range="today"/>
<standardfeed feed="recently_featured" time-range="today"/>
</YouTube>
</online-content>
</import>
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="audio/ogg" using="audio2pcm"/>
<transcode mimetype="audio/x-flac" using="audio2pcm"/>
<transcode mimetype="video/ogg" using="video2mpeg"/>
<transcode mimetype="video/quicktime" using="video2mpeg"/>
<transcode mimetype="video/x-flv" using="video2mpeg"/>
<transcode mimetype="video/x-matroska" using="video2mpeg"/>
<transcode mimetype="image/raw" using="raw2jpeg"/>
</mimetype-profile-mappings>
<profiles>
<profile name="audio2pcm" enabled="yes" type="external">
<mimetype>audio/L16</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<sample-frequency>44100</sample-frequency>
<audio-channels>2</audio-channels>
<agent command="vlc" arguments="%in -I dummy --sout=#transcode{acodec=s16b,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=raw,dst=%out} vlc://quit"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
</profile>
<profile name="video2mpeg" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<sample-frequency>48000</sample-frequency>
<audio-channels>2</audio-channels>
<agent command="vlc" arguments="%in -I dummy --sout=#transcode{vcodec=mp2v,vb=4096,fps=25,acodec=mpga,ab=192,samplerate=48000,channels=2,audio-sync}:standard{access=file,mux=ps,dst=%out} vlc://quit"/>
<buffer size="10485760" chunk-size="262144" fill-size="524288"/>
</profile>
<profile name="raw2jpeg" enabled="yes" type="external">
<mimetype>image/jpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<agent command="/usr/local/bin/mediatomb-raw2jpeg" arguments="%in %out"/>
<buffer size="524288" chunk-size="512" fill-size="1024"/>
</profile>
</profiles>
</transcoding>
</config>
[edit] Issues
[edit] MP4 videos identified as audio
libmagic can incorrectly identify some videos with the mp4 suffix as mimetype audio/mp4. To solve this problem you can override the mimetype returned by libmagic by adding the following section in between the <extension-mimetype ignore-unknown="no"> and </extension-mimetype> elements.
<map from="mp4" to="video/mp4"/>