Mediatomb and the PS3 with mencoder

Wednesday, January 07, 2009 Posted by Psyk


After some mucking around, I'm successfully streaming from my Fedora/Linux PC to the PS3 over wireless.

A great guide to get this going is from the mediatomb website and more specifically the transcoding section:

http://mediatomb.cc/dokuwiki/transcoding:transcoding

Take note to adjust your config.xml.

The site describes using ffmpeg and/or VLC as the transcoding engine, but I've always liked mencoder as I'm more familiar with it and have a lot of profiles defined already in ~/.mplayer/mencoder.conf.

In regards to the mediatomb config.xml file (located at ~/.mediatomb/config.xml), like with most things, it needs to be heavily customised. I have a stack of AVI's that aren't in DivX/XviD format (which is what mediatomb tells the PS3 by default) and I have some AVI files which ffmpeg borks on... however, mencoder works very well on all these files. As a result, I transcode everything rather than pass the DivX/XviD to the PS3 - and surprisingly it streams well over wireless.

So here's the "~/bin/mencoder-tr" script I use that mediatomb calls to transcode the video's from the PC to a format the PS3 can understand. In this case I'm transcoding to a DVD compliant MPEG2 stream and AC3 audio in 720x576 format:
exec mencoder \
-oac lavc -ovc lavc \
-of mpeg \
-mpegopts format=dvd:tsaf \
-vf softskip,scale=720:576,hqdn3d,harddup \
-srate 48000 \
-af lavcresample=48000:volnorm=2 \
-ofps 25 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=5120:vstrict=0:keyint=15:vbitrate=5120:acodec=ac3:abitrate=192:autoaspect \
"$1" -o "$2"
The "$1" and "$2" designations are mediatomb specific...

Lastly, I have the following "transcoding" section in my "~/.mediatomb/config.xml" file:
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="audio/mpeg" using="vlcwav"/>
<transcode mimetype="video/x-flv" using="transvideo"/>
<transcode mimetype="video/mp4" using="transvideo"/>
<transcode mimetype="video/x-quicktime" using="transvideo"/>
<transcode mimetype="application/ogg" using="vlcwav"/>
<transcode mimetype="audio/x-ms-wma" using="vlcwav"/>
<transcode mimetype="audio/x-ms-asf" using="vlcwav"/>
<transcode mimetype="audio/x-flac" using="ffmpegwav"/>
<transcode mimetype="audio/x-aac" using="vlcwav"/>
<transcode mimetype="audio/mp4" using="vlcwav"/>
<transcode mimetype="video/x-msvideo" using="transvideo"/>
<transcode mimetype="video/x-ms-wmv" using="transvideo"/>
<transcode mimetype="video/mpeg" using="mpeg2trans"/>
<transcode mimetype="video/x-matroska" using="transvideo"/>
<transcode mimetype="image/jpeg" using="rescalejpeg"/>
</mimetype-profile-mappings>
<profiles>
<profile name="transvideo" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<agent command="mencoder-tr" arguments="%in %out"/>
<buffer size="10485760" chunk-size="262144" fill-size="524288"/>
</profile>
<profile name="mpeg2trans" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<agent command="mencoder-tr" arguments="%in %out"/>
<buffer size="28800000" chunk-size="512000" fill-size="120000"/>
</profile>
<profile name="ffmpegwav" enabled="yes" type="external">
<use-chunked-encoding>no</use-chunked-encoding>
<mimetype>audio/wav</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<agent command="ffmpegaudio" arguments="%in %out"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
</profile>
<profile name="vlcwav" enabled="yes" type="external">
<use-chunked-encoding>no</use-chunked-encoding>
<mimetype>audio/wav</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{acodec=s16l,ab=192,channels=2}:standard{access=file,mux=wav,dst=%out} vlc:quit"/>
<buffer size="512000" chunk-size="32000" fill-size="64000"/>
</profile>
<profile name="rescalejpeg" enabled="yes" type="external">
<mimetype>image/jpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<agent command="convert" arguments="-size 1080x720 %in -auto-orient -resize 1080x720 +profile '*' %out"/>
<buffer size="50000" chunk-size="100" fill-size="100"/>
</profile>
</profiles>
</transcoding>



Note the "mencoder-tr" entries that allows mediatomb to execute the required script to perform the transcoding.

The advantage of this method means that using mencoder's engine it can read pretty much any format and convert to any format, in this case a standard DVD mpeg stream.

As requested, here is my entire ~/.mediatomb/config.xml

<?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">
<accounts enabled="no" session-timeout="30">
<account user="mediatomb" password="mediatomb"/>
</accounts>
</ui>
<name>MediaTomb</name>
<udn>uuid:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</udn>
<home>/home/xxxxxxxxxxxxx</home>

<webroot>/usr/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.db</database-file>
</sqlite3>
<mysql enabled="no">
<host>localhost</host>
<username>mediatomb</username>
<database>mediatomb</database>
</mysql>
</storage>
<protocolInfo extend="yes"/>
</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="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="ts" to="video/mpeg"/>
<map from="vob" to="video/mpeg"/>
<map from="wav" to="audio/wav"/>
<map from="mpg" to="video/mpeg"/>
<map from="aac" to="audio/x-aac"/>
<map from="m4a" to="audio/mp4"/>
<map from="mkv" to="video/x-matroska"/>
<map from="mov" to="video/x-quicktime"/>
<map from="flv" to="video/x-flv"/>
<map from="divx" to="video/x-divx"/>
</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="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"/>
</mimetype-contenttype>
</mappings>
</import>
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="audio/mpeg" using="vlcwav"/>
<transcode mimetype="video/x-flv" using="transvideo"/>
<transcode mimetype="video/mp4" using="transvideo"/>
<transcode mimetype="video/x-quicktime" using="transvideo"/>
<transcode mimetype="application/ogg" using="vlcwav"/>
<transcode mimetype="audio/x-ms-wma" using="vlcwav"/>
<transcode mimetype="audio/x-ms-asf" using="vlcwav"/>
<transcode mimetype="audio/x-flac" using="ffmpegwav"/>
<transcode mimetype="audio/x-aac" using="vlcwav"/>
<transcode mimetype="audio/mp4" using="vlcwav"/>
<transcode mimetype="video/x-msvideo" using="transvideo"/>
<transcode mimetype="video/x-ms-wmv" using="transvideo"/>
<transcode mimetype="video/mpeg" using="mpeg2trans"/>
<transcode mimetype="video/x-matroska" using="transvideo"/>
<transcode mimetype="image/jpeg" using="rescalejpeg"/>
</mimetype-profile-mappings>
<profiles>
<profile name="transvideo" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<agent command="mencoder-tr" arguments="%in %out"/>
<buffer size="10485760" chunk-size="262144" fill-size="524288"/>
</profile>
<profile name="mpeg2trans" enabled="yes" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<agent command="mencoder-tr" arguments="%in %out"/>
<buffer size="28800000" chunk-size="512000" fill-size="120000"/>
</profile>
<profile name="ffmpegwav" enabled="yes" type="external">
<use-chunked-encoding>no</use-chunked-encoding>
<mimetype>audio/wav</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<agent command="ffmpegaudio" arguments="%in %out"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
</profile>
<profile name="vlcwav" enabled="yes" type="external">
<use-chunked-encoding>no</use-chunked-encoding>
<mimetype>audio/wav</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{acodec=s16l,ab=192,channels=2}:standard{access=file,mux=wav,dst=%out} vlc:quit"/>
<buffer size="512000" chunk-size="32000" fill-size="64000"/>
</profile>
<profile name="rescalejpeg" enabled="yes" type="external">
<mimetype>image/jpeg</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<agent command="convert" arguments="-size 1080x720 %in -auto-orient -resize 1080x720 +profile '*' %out"/>
<buffer size="50000" chunk-size="100" fill-size="100"/>
</profile>
<profile name="vlcyoutube" enabled="no" type="external">
<mimetype>video/mpeg</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="vlc" arguments="-I dummy %in --sout #transcode{vcodec=mp2v,vb=4096,canvas-width=448,canvas-height=252,acodec=mpga,ab=64,samplerate=44100,channels=1}:standard{access=file,mux=ts,dst=%out} vlc:quit"/>
<buffer size="14400000" chunk-size="256000" fill-size="80000"/>
</profile>
</profiles>
</transcoding>
</config>


Note the bold and italicized regions. The home designation should be your "/home/(username)/.mediatomb" directory, and the uuid is a unique 32 alpha-numeric string.

Lastly, my config.xml probably needs a lot of cleaning up also. I basically heavily modified the one avialable from the mediatomb website and didn't go and clean it up. Fo example, I could probably delete the "vlcyoutube" transcoding trigger as I'm using the transvideo one instead.
Labels:
  1. Anonymous

    Any possibility to post youe whole config.xml?

    I cant seem to get it 100% working.
    thanks

  2. Anonymous
  3. Anonymous

    I get a error on ffmpegwav can you post it?

  4. Could you perhaps share your mencoder.conf ?

    I'm looking for some good formats to encode dvds to to play back via mediatomb on my ps3.

    So this is almost completely there, and it might be completely there, I'm just too much of a noob with transcoding ;)

    Anyways, just some background, I'm trying to take a stack of dvds, some already ripped into folders, and scriptedly convert them into something that the ps3 can play back.

    Thanks for the great post on mediatomb, I need to go customize mine to make it more smarter :)

  5. Psyk

    @ dkowis
    Thanks for the feedback.

    I'm currently using the following profile in mencoder.conf to encode to h.264/mp4 and aac for playback on the PS3:
    --------
    [PS3]
    vf=pullup,softskip,pp=fd,scale=720:-2,hqdn3d,harddup
    ovc=x264=yes
    x264encopts=subq=6:crf=18:partitions=p8x8,b8x8,i4x4:weight_b=yes:threads=auto:nopsnr=yes:nossim=yes:frameref=3:mixed_refs=yes:level_idc=41:direct_pred=auto:trellis=1:deblock=-2,-1
    oac=faac=yes
    faacopts=br=256:raw=yes:mpeg=4:tns=yes:object=2
    af=volnorm=2
    of=lavf=yes
    lavfopts=format=mp4
    sws=9
    --------

    and because mencoder's MP4 muxing is a little broken, I then mux it into an MP4 via ffmpeg.

    It's in a little script as follows:
    ----
    mencoder -profile PS3 "$1" -o _temp_0_0.mp4 && ffmpeg -y -i _temp_0_0.mp4 -f mp4 -acodec copy -vcodec copy "$1".mp4 && rm _temp_0_0.mp4
    ----

    Very simple, but works well. I favour mencoder a lot because I have my profiles setup that way and have played with it for quite a while. I'm sure there are other ways using ffmpeg and MP4Box etc.

  6. Very nice!!! i spent quite a lot of time with experimenting different parameters with ffmpeg , but your config seems to work pretty good .. good luck. ;] thanks again.

  7. JJ

    Buddy, I wish I could kiss you right now - I've spent all night working on transcoding and your script worked for me as is! Now I'm setting up all my TV streams on mediatomb.

    XOXOXOX

    (working on Ubuntu 11.04)

Post a Comment