MediaTomb and PS3: Adding subtitles

Native english speakers usually don't bother much with them, but movie subtitles are a good thing. When you're fond of Asian movies, like I am, they move from "good thing" to "absolute necessity". Why not setup mediatomb to serve those movies with embedded subtitles to the PS3?

The trick is telling mediatomb that a subtitle actually is a movie itself. First job is creating a mimetype for the subtitle extensions:

<map from="srt" to="video/subtitle"/>
<map from="sub" to="video/subtitle"/>

And, just like any other mimetype that needs transcoding, add a mapping line...

<transcode mimetype="video/subtitle" using="mencoder-sub"/>

... and a matching transcoding profile.

<profile name="mencoder-sub" enabled="yes" 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="/usr/local/bin/mediatomb-mencoder-sub" arguments="%in %out"/>
        <buffer size="1000000" chunk-size="512000" fill-size="20480"/>
</profile>

If you're unfamiliar with the mediatomb config.xml structure, my full config file is up here. The mediatomb-mencoder-sub script looks up the movie for the given subtitle, and for this to work the filenames must be identical, except for the extension. MyFile.srt requires a MyFile.avi.

#!/bin/bash
exec mencoder "$(echo $1 | sed 's/...$/avi/')" \
-oac lavc -ovc lavc -of mpeg \
-lavcopts vcodec=mpeg2video:keyint=1:vbitrate=2000:vrc_maxrate=8000:vrc_buf_size=1835 \
-vf harddup,scale -zoom -xy 720 -mpegopts muxrate=12000 \
-sub "$1" -font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf" \
-subfont-autoscale 0 -subfont-text-scale 25 -subpos 100 \
-o "$2" &>/dev/null

This has a few things hardcoded: first of all, the simple extension replacement, a font for the subtitles (pick your own favourite) and various options for the scaling thereof, and last but not least scaling of the movie to 720px wide. This was only included to allow me to stream HD divxes with subtitles - my processors aren't powerful enough to decode and re-transcode HD divx on the fly. Once again, edit to suit your needs.

Once you re-import your movies and subtitles, you'll notice the .srt or .sub showing up as separate movie files below the original .avi in the PS3's menu. The .avi will be just the movie, without subtitles; the .srt/.sub will give you a transcoded stream of movie + subtitles.

Enjoy!