Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

MediaTomb

From Gentoo Wiki
Jump to: navigation, search

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.

Installation

Kernel

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.

You need to activate the following kernel options:

Kernel configuration

 File systems --->
   [*] Inotify support for userspace

Software

→ Information about USE flags
USE flag Default Recommended Description
curl Yes Yes Enables YouTube support and is required when transcoding external sources.
debug No No Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see http://www.gentoo.org/proj/en/qa/backtraces.xml
exif Yes Yes Adds support for reading EXIF headers from JPEG and TIFF images
ffmpeg Yes Yes Enable ffmpeg-based audio/video codec support
id3tag No No Use media-libs/libid3tag for reading files' metadata rather than taglib
inotify No Yes Enable inotify filesystem monitoring support
javascript Yes Yes Enables SpiderMonkey JavaScript engine support. Creates a virtual container layout based on the extracted metadata.
lastfm No Enable last.fm support
libextractor No No Enables audio, image and video metadata extraction support. Can slow media import speed considerably.
magic Yes Yes Use libmagic to determine file types
mp4 Yes Yes Enables MP4 metadata extraction support.
mysql No Use dev-db/mysql as backend rather than SQLite3
sqlite Yes Yes Adds support for sqlite - embedded sql database
taglib Yes Yes Use media-libs/taglib for reading files' metadata rather than id3lib
thumbnail No Enables video thumbnails generation throughmedia-video/ffmpegthumbnailer
zlib Yes Yes Adds support for zlib (de)compression
root # emerge --ask mediatomb

Configuration

Network

  • To set the interface that MediaTomb binds to, add the following to the MEDIATOMB_OPTIONS variable.
File/etc/conf.d/mediatomb

MEDIATOMB_OPTIONS="-e eth0"
  • To set the IP address that MediaTomb binds to, add the following to the MEDIATOMB_OPTIONS variable.
File/etc/conf.d/mediatomb

MEDIATOMB_OPTIONS="-i 192.168.0.1"

MySQL

Note
The net-misc/mediatomb mysql USE flag needs to be enabled for MySQL support.
  • To enable MySQL support, set the enabled attribute to yes for the <mysql> element.
File/etc/mediatomb/config.xml

      <mysql enabled="yes">
  • Set the enabled attribute to no for the <sqlite3> element.
File/etc/mediatomb/config.xml

      <sqlite3 enabled="no">
  • Set the <host>, <database>, <username> and <password> elements.
File/etc/mediatomb/config.xml

        <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';

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.
File/etc/mediatomb/config.xml

  <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"/>
File/etc/mediatomb/config.xml

      <transcode mimetype="mimetype" using="profile">
Note
The media-video/ffmpeg encode USE flag needs to be enabled for transcoding support. If you want transcoding to take advantage of multithreading, the media-video/ffmpeg threads USE flag needs to be enabled.
root # emerge --ask ffmpeg

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.

VLC

Audio

  • To enable VLC audio transcoding, replace the <agent> element for the audio2pcm profile with the following:
File/etc/mediatomb/config.xml

        <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.
File/etc/mediatomb/config.xml

        <accept-url>yes</accept-url>

Video

  • To enable VLC video transcoding, replace the <agent> element for the video2mpeg profile with the following:
File/etc/mediatomb/config.xml

        <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.
File/etc/mediatomb/config.xml

        <accept-url>yes</accept-url>
Note
The media-video/vlc ffmpeg, encode and media-video/ffmpeg encode USE flags need to be enabled for transcoding support.
root # emerge --ask vlc
MPlayer

Video

  • To enable MPlayer video transcoding, replace the <agent> element for the video2mpeg profile with the following.
File/etc/mediatomb/config.xml

        <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.
File/etc/mediatomb/config.xml

        <accept-url>yes</accept-url>
Note
The media-video/mplayer encode USE flag needs to be enabled for transcoding support.
root # emerge --ask mplayer

DLNA

Note
MediaTomb doesn't implement the DLNA specification and is not a DLNA media server. It does however offer basic support for some DLNA devices e.g. PlayStation 3.
  • To enable DLNA support, set the extend attribute to yes for the <protocolInfo> element.
File/etc/mediatomb/config.xml

    <protocolInfo extend="yes">
  • If you have a DLNA enabled TV (e.g. Samsung), add the following section in between the <server> and </server> elements.
File/etc/mediatomb/config.xml

    <custom-http-headers>
      <add header="transferMode.dlna.org: Streaming"/>
      <add header="contentFeatures.dlna.org: DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01500000000000000000000000000000"/>
    </custom-http-headers>

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.

YouTube

Warning
There are reports on the MediaTomb forum indicating that YouTube support is currently broken.
Note
You need to specify the content you want to view, as the default Gentoo configuration file only provides a sample. For more information, please consult Section 6.2.2 of the MediaTomb documentation.
  • To enable YouTube support, set the enabled attribute to yes for the <YouTube> element.
File/etc/mediatomb/config.xml

      <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.
File/etc/mediatomb/config.xml

      <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.
File/etc/mediatomb/config.xml

      <transcode mimetype="video/mp4" using="video2mpeg"/>

Video Thumbnails

Note
The net-misc/mediatomb ffmpeg and thumbnail USE flags need to be enabled for video thumbnail support.
  • To enable video thumbnail support, set the enabled attribute to yes for the <ffmpegthumbnailer> element.
File/etc/mediatomb/config.xml

      <ffmpegthumbnailer enabled="yes">
  • If you want to overlay a filmstrip border on the generated thumbnail, set the <filmstrip-overlay> element to yes.
File/etc/mediatomb/config.xml

        <filmstrip-overlay>yes</filmstrip-overlay>
  • If you have a DLNA enabled device that supports video thumbnails (e.g. PlayStation 3), set the extend attribute to yes for the <protocolInfo> element.
File/etc/mediatomb/config.xml

    <protocolInfo extend="yes">

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.
File/etc/mediatomb/config.xml

      <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>
        <use-chunked-encoding>no</use-chunked-encoding>
        <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.
File/etc/mediatomb/config.xml

      <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"/>
File/etc/mediatomb/config.xml

        <map from="extension" to="image/raw"/>
  • Create the following script.
File/usr/local/bin/mediatomb-raw2jpeg

#!/bin/sh

DCRAW_PATH="/usr/bin/dcraw"
INPUT="$1"
OUTPUT="$2"

exec "${DCRAW_PATH}" -e -c "${INPUT}" > "${OUTPUT}"
root # emerge --ask dcraw

Starting

  • To start MediaTomb.
root # /etc/init.d/mediatomb start
  • To start MediaTomb at boot.
root # rc-update add mediatomb default

Troubleshooting

Mimetype Mapping

Note
If you have added or changed a mimetype mapping after importing your content, you will need to re-import it as mimetype mappings are only set during import.

MediaTomb (via libmagic) can identify certain files with an incorrect mimetype. A common case is where videos with the mp4 extension are identified as the mimetype audio/mp4. To override the mimetype returned by libmagic, add the following section in between the <extension-mimetype ignore-unknown="no"> and </extension-mimetype> elements and substitute extension and mimetype with the appropriate values e.g. <map from="mp4" to="video/mp4"/>

File/etc/mediatomb/config.xml

        <map from="extension" to="mimetype">

External resources