Mediatomb ogg transcoding and the Playstation 3

December 18th, 2009 Comments Off

(My most astute readers will notice that this is being posted after 5AM in the morning Eastern. My web server is on the west coast so it says 2 but don’t be fooled! No I did not just wake up, I’ve been hacking on this for the past 4 hours.)

I bought a PS3 several months ago to act as, among other things, a UPnP Media Renderer (although not by the real technical definition… its more of a gimped control point that can render locally… but thats a gripe for another day). I’ve known since I started using it that the PS3 was only picking up the MP3 songs from my Mediatomb server. I decided that it was time to fix this.

No matter what got in the way.

I knew mediatomb was capable of doing on the fly transcoding (as any good server is, Rygel can too!) so I figured I would play with those settings. This is where we had the first bad omen — to configure it I needed to copy some XML from a gentoo wiki doc. Oh boy, bad sign.

Of course it doesn’t work at first. Hell, the oggs don’t even show up! Some flacs do though, so I decide i’ll try and tackle making the flacs work first and then work on making the oggs show up.

1.5 hours go by. Transcoding works fine if i pull the URL by hand and run it in mplayer but the ps3 is stubborn. It is at this point that I notice that mediatomb has a DNLA non-compliance issue in 0.11 which causes the ps3 to not be able to pick up transcoded media. Go figure! Now… wait…. version 0.12 has the fix but… its been 2 years and 0.12 isn’t out… time to compile from source! Sigh.

10 minutes later I have mediatomb “0.12” (aka SVN HEAD) installed and ready to go.

Yay! This time it looks like its trying to actually transcode the flac, (e.g. the ps3 doesnt immediatly bail out with a non-compatible error) but I do get just static. I messed with some things and I thought I had it working so I moved on to getting oggs to show up.

Now, in the mediatomb configuration itself oggs are classified as “application/ogg” (not audio/ogg for some reason) and the upnp_class for musicTrack is only for audio/* so I thought that was fishy. I did some poking and prodding using Zeeshan’s fantastic gupnp-universal-cp and some custom GUPnP-Python scripts (woot!) to investigate. Turns out my ogg files are getting the wrong UPnP Class! They are showing up as object.item instead of object.item.music.musicTrack (or something like that).

I patch up the config to change things to be mime-type “audio/ogg” instead of “application/ogg” and… bupkis. Turns out (after another 30 minutes of poking) that mediatomb stores the upnp class and mime type hardcoded inside its database. Sure, why not? Lets just dump the whole thing! So I did, and had mediatomb rescan all my media with the new mime-types for ogg.

Low and behold now my gupnp-universal-cp shows oggs with the right class AND they show up in the PS3!

We’re not out of the woods yet! Remember when I said I *thought* I had flacs playing correctly before? I was wrong. The music was somehow playing at half speed (what the heck?). Well, this is a purely transcoding issue so I dove into the transcoding script. I confirmed that its the exact same thing the gentoo wiki had, yet still my media played at half speed.

Well… one fix for that is to simply half the frequency at the encoder, right? So i did, I told ffmpeg to output 22050 instead of 44100hz and magically everything sounds right!

Whew! And to think, in the 4 hours all that took I probably could’ve converted my 1500 or so flac + oggs to mp3s.

In the end though, I am not angry. I think its awesome that I am able to debug this at such a low level and have it work at the end of the day. But lets think about the things I had to fix:

  • “Add” the config to mediatomb’s config
  • “Upgrade” my mediatomb version
  • Application/ogg -> audio/ogg in mediatomb’s config
  • “fix” the transcoding script that i got from the gentoo wiki

Not that much, right? And none of those are really big changes. If Mediatomb simply shipped with sane defaults (audio/ogg) and an easy option to enable the transcoding configuration (instead of my having to copy and paste it in) this would have worked out of the box. I believe this is a very common problem in Linux. The basics work out of the box fine, but the VAST potential for extra AWESOME features is not accessible to the average user because we are simply too poor at unlocking those capabilities with sane defaults and reasonable configurability.

I hope this helps some other user figure out how to get transcoding with mediatomb/ps3 working and maybe even motivate a developer or two to perhaps ship these configs in working, sane, form so some other user won’t even have to google for this post.

p.s. If you do end up mucking around with this and are trying to get the transcoding just right, take my advice: Stick with pcm_s16be. Nothing else works, I tried.