In a
previous article, I explained how to build
mediatomb, an open source media server able to stream music and video to UPnP devices, such as the Playstation 3. This build is based on the latest development source tree, so although the next official release (0.12) is still ahead of us, we can already take a look at some new features, namely:
- improved on-the-fly transcoding.
- built-in support for video thumbnails (using ffmpegthumbnailer),
- Apple movie trailers,
- YouTube video feeds
In this article, I'm going to demonstrate these features on my PS3 and I'm also going to explain how to set them up.
FYI, I'm using Ubuntu 8.04,
ffmpeg SVN-r16245 (built from source),
ffmpegthumbnailer 1.3.0 (built from source) and x264 0.65.1057 (built from source).
1) Basic configurationmediatomb only has one config file, located in
~/.mediatomb/config.xml. For more information, please check the
mediatomb documentation.
Let's start from the default settings and add a few things.
In the <
server> section, set the extended UPnP protocol information for the PS3:
<protocolInfo extend="yes"/>
[Updated on 2009/01/02] Reportedly not needed anymore if you're running the latest PS3 firmware (2.53). Try changing it to 'no' if you're experiencing issues with movie playback.In the <
extension-mimetype> section, add a few entries to map common extensions for video files to the appropriate MIME type:
<map from="avi" to="video/divx"/>
<map from="mkv" to="video/x-matroska"/>
<map from="mts" to="video/mpeg"/>
<map from="ts" to="video/mpeg"/>
<map from="m2ts" to="video/mpeg"/>
<map from="mov" to="video/x-quicktime"/>
<map from="vob" to="video/mpeg"/>
<map from="m4v" to="video/mp4"/>
In the <
mimetype-contenttype> section, add a few entries to map MIME types to extensions, so that
mediatomb can use the proper method to extract metadata:
<treat mimetype="video/quicktime" as="mov"/>
<treat mimetype="video/x-quicktime" as="mov"/>
2) On-the-fly transcodingThe PS3 supports a limited set of
audio &
video file formats. For example, it can't play
FLAC,
FLV,
Quicktime, etc. In order to play these files anyway, we need
mediatomb to transcode them on the fly and then stream them to the PS3 in a format it can play. Transcoding itself is performed by external tools, such as
VLC and
ffmpeg.
All we have to do is:
- list all MIME types which require transcoding,
- associate each of them to a transcoding profile,
- define the actual transcoding profiles.
Here's the complete configuration I use:
- for audio transcoding (OGG and FLAC), a profile based on ffmpeg, which outputs 16-bit PCM stereo audio at 44.1KHz and 192 Kbit/s,
- for video transcoding (ASF, FLV, Quicktime), a profile also based on ffmpeg, which outputs MPEG-2 video at 25 fps and 4Mbit/s, as well as MPEG stereo audio at at 44.1KHz and 192 Kbit/s.
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="application/ogg" using="audio-generic"/>
<transcode mimetype="audio/x-flac" using="audio-generic"/>
<transcode mimetype="video/x-ms-asf" using="video-generic"/>
<transcode mimetype="video/x-flv" using="video-generic"/>
<transcode mimetype="video/x-matroska" using="video-generic"/>
<transcode mimetype="video/x-quicktime" using="video-generic"/>
<transcode mimetype="video/quicktime" using="video-generic"/>
</mimetype-profile-mappings>
<profiles>
<profile name="audio-generic" enabled="yes" type="external" >
<mimetype>audio/L16</mimetype>
<first-resource>yes</first-resource>
<accept-url>yes</accept-url>
<sample-frequency>44100</sample-frequency>
<audio-channels>2</audio-channels>
<hide-original-resource>yes</hide-original-resource>
<agent command="ffmpeg" arguments="-ac 2 -ar 44100 -y -i %in -f s16be %out"/>
<buffer size="1048576" chunk-size="4096" fill-size="1024"/>
</profile>
<profile name="video-generic" enabled="yes" type="external">
<avi-fourcc-list mode="ignore">
<fourcc>DX50</fourcc>
<fourcc>DM4V</fourcc>
<fourcc>M4S2</fourcc>
</avi-fourcc-list>
<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>
<agent command="/usr/local/bin/mediatomb-video-generic" arguments="%in %out"/>
<buffer size="1048576" chunk-size="26214" fill-size="52428"/>
</profile>
</profiles>
</transcoding>
Now, here's the '
mediatomb-video-generic' script. Don't forget to change the path to
ffmpeg if needed and to set execute rights ('
chmod 755 /usr/local/bin/mediatomb-video-generic'):
[this updated script works for Youtube, Apple trailers and mkv files and doesn't require VLC anymore : thanks to the anonymous reader who contributed it].#!/bin/bash
INPUT="$1"
OUTPUT="$2"
VIDEO_CODEC="mpeg2video"
VIDEO_BITRATE="4096k"
AUDIO_CODEC="mp2"
AUDIO_BITRATE="192k"
AUDIO_SAMPLERATE="48000"
AUDIO_CHANNELS="2"
FORMAT="dvd"
exec /usr/local/bin/ffmpeg -threads 2 -i "${INPUT}" -vcodec ${VIDEO_CODEC} -b ${VIDEO_BITRATE} \
-acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} -ar ${AUDIO_SAMPLERATE} -ac ${AUDIO_CHANNELS} \
-f ${FORMAT} - > "${OUTPUT}" 2>/dev/null
All right, let's get to the good stuff.
3) Video thumbnailsAssuming you have installed
ffmpegthumbnailer, enabling on-the-fly thumbnail generation only requires this addition to the <
server> section:
<extended-runtime-options>
<ffmpegthumbnailer enabled="yes">
<thumbnail-size>128</thumbnail-size>
<seek-percentage>5</seek-percentage>
<filmstrip-overlay>yes</filmstrip-overlay>
<workaround-bugs>no</workaround-bugs>
</ffmpegthumbnailer>
</extended-runtime-options>
Let's save these changes, restart
mediatomb and browse some videos:
MPEG-2 on the left,
DivX on the right. Thumbnails are generated on the fly when videos are browsed.
Let's try some different file types.
- Below on the left: VOB files ripped from a DVD. VOB files really are MPEG-2 files, but since they have a different extension, they wouldn't be viewable if we hadn't mapped the .vob extension to the video/mpeg MIME type.
- Below on the right: some MKV (Matroska) samples.
This looks much nicer than blank icons :)
4) Apple movie trailersThis feature, found in the
Online Services menu, allows you to view movies trailers hosted on an
Apple website.
This is very easy to configure. In the <
online-content> section, add:
<AppleTrailers enabled="yes" refresh="43200" update-at-start="yes" resolution="640"/>
Save the changes, restart
mediatomb and...
It works like this. First,
mediatomb fetches an
RSS feed, then it parses it and dynamically creates menus where trailers are sorted by genre, release date, etc. Let's go to action movies and hmmm...
2012? What is this?
Wow, the Himalaya overrun by a giant wave, the end of the world, etc. My kind of movie :)
Come on, is this a cool feature or what?
5) YouTube videos
Now, let's go back to the
Online Services and enter the
YouTube menu. In the
mediatomb configuration file, we need to define:
- a valid YouTube account (username and password),
- the list of video feeds that we'd like to browse.
So, in the <
accounts> section, add:
<account user="your_YouTube_username" password="your_YouTube_password"/>
And in the <
;online-content> section, add:
<YouTube enabled="yes" refresh="28800" update-at-start="yes" purge-after="604800" racy-content="exclude">
<favorites user="your_YouTube_username"/>
<playlists user="your_YouTube_username"/>
<uploads user="your_YouTube_username"/>
<standardfeed feed="most_viewed" time-range="today"/>
<standardfeed feed="top_rated" time-range="this_week"/>
</YouTube>
This is quite customizable, but no official documentation is out yet. A quick look at the code will give you some pointers, though ;)
Save the changes, restart
mediatomb and now you can browse your YouTube playlists.
You can also browse the standard YouTube feeds that you have defined:
Most Viewed,
Top Rated, etc.
All right, that's it for today. Mediatomb is a GREAT project, I can't wait for the official release. In the meantime, there's already plenty to explore.
And by the way, Merry Christmas to all you geeks out there ;)
===================================
As requested, here's my
config.xml file. You just change to change
YouTube_Username,
YouTube_Password,
LastFM_Username &
LastFM password to your own values.
<?xml version="1.0" encoding="UTF-8"?>
<config version="1" xmlns="http://mediatomb.cc/config/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/1 http://mediatomb.cc/config/1.xsd">
<server>
<ui enabled="yes" show-tooltips="yes">
<accounts enabled="no" session-timeout="30">
<account user="YouTube_Username" password="YouTube_Password"/>
</accounts>
</ui>
<name>MediaTomb</name>
<udn>uuid:b8b13d59-378e-4cb8-9a87-14f70c70f847</udn>
<home>/home/julien/.mediatomb</home>
<webroot>/usr/local/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.db</database-file>
</sqlite3>
</storage>
<protocolInfo extend="yes"/><!-- For PS3 support change to "yes" -->
<extended-runtime-options>
<ffmpegthumbnailer enabled="yes">
<thumbnail-size>128</thumbnail-size>
<seek-percentage>5</seek-percentage>
<filmstrip-overlay>yes</filmstrip-overlay>
<workaround-bugs>no</workaround-bugs>
</ffmpegthumbnailer>
<mark-played-items enabled="no" suppress-cds-updates="yes">
<string mode="prepend">*</string>
</mark-played-items>
</extended-runtime-options>
</server>
<import hidden-files="no">
<scripting script-charset="UTF-8">
<common-script>/usr/local/share/mediatomb/js/common.js</common-script>
<playlist-script>/usr/local/share/mediatomb/js/playlists.js</playlist-script>
<virtual-layout type="builtin">
<import-script>/usr/local/share/mediatomb/js/import.js</import-script>
<dvd-script>/usr/local/share/mediatomb/js/import-dvd.js</dvd-script>
</virtual-layout>
</scripting>
<mappings>
<extension-mimetype ignore-unknown="no">
<map from="mp3" to="audio/mpeg"/>
<map from="ogg" to="application/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="avi" to="video/divx"/>
<map from="mkv" to="video/x-matroska"/>
<map from="mts" to="video/mpeg"/>
<map from="ts" to="video/mpeg"/>
<map from="m2ts" to="video/mpeg"/>
<map from="flac" to="audio/x-flac"/>
<map from="mov" to="video/x-quicktime"/>
<map from="vob" to="video/mpeg"/>
<map from="m4v" to="video/mp4"/>
<map from="iso" to="application/x-iso9660-image"/>
</extension-mimetype>
<mimetype-upnpclass>
<map from="audio/*" to="object.item.audioItem.musicTrack"/>
<map from="video/*" to="object.item.videoItem"/>
<map from="application/x-iso9660-image" 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="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="video/x-msvideo" as="avi"/>
<treat mimetype="video/divx" as="avi"/>
<treat mimetype="video/mp4" as="mp4"/>
<treat mimetype="audio/mp4" as="mp4"/>
<treat mimetype="video/quicktime" as="mov"/>
<treat mimetype="video/x-quicktime" as="mov"/>
<treat mimetype="application/x-iso9660-image" as="dvd"/>
</mimetype-contenttype>
</mappings>
<online-content>
<!-- Make sure to setup a transcoding profile for flv -->
<YouTube enabled="yes" refresh="28800" update-at-start="yes" purge-after="604800" racy-content="exclude">
<favorites user="YouTube_Username"/>
<playlists user="YouTube_Username"/>
<uploads user="YouTube_Username"/>
<standardfeed feed="most_viewed" time-range="today"/>
<standardfeed feed="top_rated" time-range="this_week"/>
</YouTube>
<AppleTrailers enabled="yes" refresh="43200" update-at-start="yes" resolution="640"/>
</online-content>
</import>
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="application/ogg" using="audio-generic"/>
<transcode mimetype="audio/x-flac" using="audio-generic"/>
<transcode mimetype="video/x-ms-asf" using="video-generic"/>
<transcode mimetype="video/x-flv" using="video-generic"/>
<transcode mimetype="video/x-matroska" using="video-generic"/>
<transcode mimetype="video/x-quicktime" using="video-generic"/>
<transcode mimetype="video/quicktime" using="video-generic"/>
</mimetype-profile-mappings>
<profiles>
<profile name="audio-generic" enabled="yes" type="external" >
<mimetype>audio/L16</mimetype>
<first-resource>yes</first-resource>
<accept-url>yes</accept-url>
<sample-frequency>44100</sample-frequency>
<audio-channels>2</audio-channels>
<hide-original-resource>yes</hide-original-resource>
<agent command="ffmpeg" arguments="-ac 2 -ar 44100 -y -i %in -f s16be %out"/>
<buffer size="1048576" chunk-size="4096" fill-size="1024"/>
</profile>
<profile name="video-generic" enabled="yes" type="external">
<avi-fourcc-list mode="ignore">
<fourcc>DX50</fourcc>
<fourcc>DM4V</fourcc>
<fourcc>M4S2</fourcc>
</avi-fourcc-list>
<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>
<agent command="/usr/local/bin/mediatomb-video-generic" arguments="%in %out"/>
<buffer size="1048576" chunk-size="26214" fill-size="52428"/>
</profile>
</profiles>
</transcoding>
<lastfm enabled="yes">
<username>LastFM_Username</username>
<password>LastFM_Password</password>
</lastfm>
</config>