Mediatomb on Ubuntu 12.04

One of the things I use Ubuntu for is to run my home server, which serves my video collection to various players around the house. This is achieved with a DNLA server that ships with Ubuntu called Mediatomb.

Unfortunately, despite having all the needed function, and being remarkably stable, Mediatomb hasn’t been under active development for the last year or two, and when I upgraded to the latest version of Ubuntu server, I discovered that a key feature of Mediatomb had been disabled; namely the support for writing import filters in Javascript.

This allows the collection of video to be sorted and filtered by their characteristics into a series of virtual folders, which can then be used by the media players to find whatever content is required. You could have folders of films sorted by leading actor, or director. Or folders of films by certification. Or date of release. The options are endless. It’s a great feature, and utterly indispensable when it’s suddenly removed.

The reason the feature is disabled is that Mediatomb depends on an out of support version of libjs, or Spidermonkey, the Mozilla Javascript engine. The Ubuntu developers don’t have time to fix this, so until the Mediatomb developers do, the Ubuntu developers have applied a quick fix and disabled the Javascript support so the package can still be shipped.

This post shows how to re-enable that Javascript support on Ubuntu 12.04 Server. It’s a bit of a dirty hack, but it will work until either:

  1. The Mediatomb developers fix this
  2. Someone (such as Raik Bieniek or Saito Kiyoshi) packages & maintains a better fix for 12.04 in a PPA
  3. This effort to replace the Javascript support with Python support completes (I couldn’t get it to compile)

The basic approach here is to rebuild the shipped package of Mediatomb, but re-enabling the Javascript support. This requires that we have a version of Javascript on the system that Mediatomb can use. The current version in the 12.04 repositories won’t work (the API’s have changed), so we need to install an older “back-level” version, which we can get from Debian, who have still been applying security fixes to it.

  1. cd;mkdir temp;cd temp
  2. sudo apt-get install build-essential, to install the tools you will need to build packages on Ubuntu
  3. sudo apt-get build-dep mediatomb, to install all the dependencies needed for mediatomb to compile
  4. sudo apt-get source mediatomb, to get the source code for mediatomb, and unpack it into a convenient subdirectory
  5. sudo vi mediatomb-0.12.1/debian/rules, and change the line that says “–disable-libjs” to “–enable-libjs” (note that those are prefixed by double-dashes)
  6. Add a new entry to the changelog file in the same directory, incrementing the version number from zero to one. This will help prevent your changes being overwritten.
  7. Get an old copy of Spidermonkey from the Debian Squeeze distribution (on which Ubuntu is ultimately based). You need libmozjs2d and libmozjs-dev, in either the amd64 or i386 versions, depending on whether you are running in 64-bit or 32-bit mode. To determine which version you need, enter the command “dpkg –print-architecture” in a terminal. Then install the appropriate packages using sudo dpkg -i packagename
  8. In all likelihood you will get an error from one or both of those installs, complaining about dependencies. To resolve them and complete the installs, simply enter sudo apt-get install -f
  9. cd mediatomb-0.12.1 and then sudo ./configure. Lots of content will scroll past, but at the end there should be a summary; look for a line that says something like “libjs : yes”. If present then you have enabled Javascript support in the build, and satisfied the dependencies. You can now install any additional dependencies and reconfigure the build further if you wish.
  10. Switch back to your source code with cd ~/temp/mediatomb-0.12.1
  11. Start the compilation with sudo fakeroot debian/rules binary. Lots of compilation messages should scroll past.
  12. When it stops, you should have three .deb files in ~/temp. You can install them with sudo dpkg -i mediatomb*.deb

Finally, switch to root (sudo su) and then issue the command echo packagename hold | dpkg –set-selections for each of mediatomb, mediatomb-common, mediatomb-daemon, libmozjs2d and libmozjs-dev. Then drop back to your user by entering control-D. This will prevent your customised packages being overwritten as part of the normal update processes (they will be “held”.)

You can now configure Mediatomb normally, including the use of custom import.js scripts by altering /etc/mediatomb/config.xml as desired.

Update: Having just been through a reboot on my server it seems that Mediatomb isn’t installed to autostart properly. To resolve this you need to run the command sudo update-rc.d mediatomb defaults which will install the various rcn.d startup and shutdown links.

Update2: I’ve noticed that sometimes after a reboot Mediatomb still isn’t autostarted properly. Turns out that there is a message in /var/log/mediatomb.log referring to The connection to the MySQL database has failed: mysql_error (2002). What this means is that if you are using MySQL rather than SQLite, there is a race condition where Upstart sometimes tries to bring up Mediatomb before the MySQL database is available. You can resolve this by editing /etc/init/mediatomb.conf, and changing:

start on (local-filesystems and net-device-up IFACE!=lo)

to

start on (started mysql and local-filesystems and net-device-up IFACE!=lo)

Upstart will then ensure that MySQL is running before attempting to start Mediatomb.

Advertisements

25 thoughts on “Mediatomb on Ubuntu 12.04

  1. thanks for the post but getting errors with debian/rules binary
    …..
    ../src/metadata/ffmpeg_handler.cc:110:3: error: ‘AVMetadataTag’ was not declared in this scope
    ../src/metadata/ffmpeg_handler.cc:110:18: error: ‘tag’ was not declared in this scope
    ../src/metadata/ffmpeg_handler.cc:111:65: error: ‘av_metadata_get’ was not declared in this scope
    ../src/metadata/ffmpeg_handler.cc: In member function ‘virtual void FfmpegHandler::fillMetadata(zmm::Ref )’:
    ../src/metadata/ffmpeg_handler.cc:291:69: error: ‘av_open_input_file’ was not declared in this scope
    ../src/metadata/ffmpeg_handler.cc:295:9: warning: ‘int av_find_stream_info(AVFormatContext*)’ is depreca ted (declared at /usr/local/include/libavformat/avformat.h:1357) [-Wdeprecated-declarations]
    ../src/metadata/ffmpeg_handler.cc:295:39: warning: ‘int av_find_stream_info(AVFormatContext*)’ is deprec ated (declared at /usr/local/include/libavformat/avformat.h:1357) [-Wdeprecated-declarations]
    ../src/metadata/ffmpeg_handler.cc:297:9: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprec ated (declared at /usr/local/include/libavformat/avformat.h:1533) [-Wdeprecated-declarations]
    ../src/metadata/ffmpeg_handler.cc:297:39: warning: ‘void av_close_input_file(AVFormatContext*)’ is depre cated (declared at /usr/local/include/libavformat/avformat.h:1533) [-Wdeprecated-declarations]
    ../src/metadata/ffmpeg_handler.cc:306:5: warning: ‘void av_close_input_file(AVFormatContext*)’ is deprec ated (declared at /usr/local/include/libavformat/avformat.h:1533) [-Wdeprecated-declarations]
    ../src/metadata/ffmpeg_handler.cc:306:35: warning: ‘void av_close_input_file(AVFormatContext*)’ is depre cated (declared at /usr/local/include/libavformat/avformat.h:1533) [-Wdeprecated-declarations]
    make[3]: *** [libmediatomb_a-ffmpeg_handler.o] Error 1
    make[3]: Leaving directory `/root/temp/mediatomb-0.12.1/build’
    make[2]: *** [all-recursive] Error 1
    make[2]: Leaving directory `/root/temp/mediatomb-0.12.1′
    make[1]: *** [all] Error 2
    make[1]: Leaving directory `/root/temp/mediatomb-0.12.1′
    dh_auto_build: make -j1 returned exit code 2
    make: *** [binary] Error 2

    • I can’t really tell what might be going wrong from the snippet of information you’ve included. However, I’d check the dependencies first; do you have all the required development libraries installed? Something FFMPEG related missing, perhaps? The “sudo apt-get build-dep mediatomb” should have fixed that for you, but perhaps it doesn’t work if you are on a different release than 12.04?

  2. Hi There,
    I tried it today.
    The Libjs is “missing” in the summary.
    After all Software Center keeps sending me the following error message
    installArchives() failed: dpkg: dependency problems prevent configuration of libnspr4-dev:
    libnspr4-dev depends on libnspr4-0d (<= 4.8.6-1.1~); however:
    Version of libnspr4-0d on system is 4.8.9-1ubuntu2.3.
    dpkg: error processing libnspr4-dev (–configure):
    dependency problems – leaving unconfigured
    No apport report written because MaxReports is reached already
    Errors were encountered while processing:
    libnspr4-dev
    Error in function:
    dpkg: dependency problems prevent configuration of libnspr4-dev:
    libnspr4-dev depends on libnspr4-0d (<= 4.8.6-1.1~); however:
    Version of libnspr4-0d on system is 4.8.9-1ubuntu2.3.
    dpkg: error processing libnspr4-dev (–configure):
    dependency problems – leaving unconfigured

    How can I solve this?
    Thanks a Lot

  3. You, Sir, are a hero!

    I’ve been struggling along with an old static build of mediatomb for about two years and it recently even stopped autostarting with teh server. Thanks to your post, the kids can now simply start the server and all is good again.

    My only comment would be regarding step 7 which I struggled with a little (though eventually resolved) – perhaps you could expand a little on that part for those less well versed in Linux.

    Nonetheless, many, many thanks.

    • Thanks for the kind comments. Step 7 is a bit of a beast – not helped by the format of the Debian pages that I linked to, which seem to assume that everyone is as technically switched on as they are! I struggled to even get it to what it is now, but I’m very happy to accept suggestions for improvement!

  4. Richard:

    On step 7 could you add the version you used of those two files. Visiting the links I could see the files. But are they the old ones or new ones? I’am still pretty much a noob at this. Thanks.

  5. Pingback: Compiling MediaTomb UPnP server on the Cubox to stream DVD ISO files by chapter/section « Technological must-shares

  6. This worked for me. I tool a while to realise that the ‘.’ in pasted lines were actually ‘–‘ and an additional ‘sudo apt-get install -f’ was needed at step 12. After that it worked great with my mythbuntu 12.04 LTS system. Many thanks for clarifying something that had seemed impossible to achieve.

    • The WordPress fonts are not kind for quoting code 🙂

      I suspect that there may be dependencies in step 12 that expect you to install the packages in some specific order. If you get that “wrong” then as you point out, “apt-get install -f” will resolve the problem for you. Glad it’s all working now.

  7. My experience with Ubuntu 14.04 mediatomb with(out) javascript

    I follow your blog:

    cd;mkdir temp;cd temp
    sudo apt-get install build-essential
    sudo apt-get build-dep mediatomb
    sudo apt-get source mediatomb
    sudo vi mediatomb-0.12.1/debian/rules, and change the line that says “–disable-libjs” to “–enable-libjs” (note that those are prefixed by double-dashes)
    Add a new entry to the changelog file in the same directory, incrementing the version number from zero to one. This will help prevent your changes being overwritten.
    Get an old copy of Spidermonkey from the Debian Squeeze distribution (on which Ubuntu is ultimately based). You need libmozjs2d and libmozjs-dev, in either the amd64 or i386 versions, depending on whether you are running in 64-bit or 32-bit mode. To determine which version you need, enter the command “dpkg –print-architecture” in a terminal. Then install the appropriate packages using sudo dpkg -i packagename.
    In all likelihood you will get an error from one or both of those installs, complaining about dependencies. To resolve them and complete the installs, simply enter
    sudo apt-get install -f
    cd mediatomb-0.12.1 && sudo ./configure
    —————————————

    Till here all is quiet and smooth, but
    cd ~/temp/mediatomb-0.12.1 && sudo fakeroot debian/rules binary
    leads too a lots of errors and I tried it often
    under ubuntu 14.04 and under lubuntu 14.04 (virtual) no luck.

    The reason are the patches under
    /mediatomb-0.12.1/debian/patches, which will
    patch with sudo apt-get source mediatomb
    /mediatomb-0.12.1/src/scripting.

    Hopefully there is a mediatomb_0.12.1.orig.tar.gz,
    so I copy the original /scripting folder
    over the patch scripting folder /mediatomb-0.12.1/src/scripting
    change the configure script with the original from mediatomb_0.12.1.orig.tar.gz,
    and that’s it.

    One more try with
    cd ~/temp/mediatomb-0.12.1 && sudo fakeroot debian/rules binary
    and I got under Ubuntu 14.04 mediatomb with javascript, playlist. etc.

    Nice blog and sorry about the english, its not my main language 😉
    Hope you got it too if you change to 14.04 (Trusty Tahr).
    Good luck

    • What a coincidence! I upgraded my home server to 14.04 this weekend, and hit exactly the same problem as you.

      I wondered about disabling the patches (as you did) but I was concerned that I might cause other problems by doing that. So instead, I decided that (as I would have to recompile the code anyway) I would alter the C++ code that implements the built-in importer so it acts the same way as my old Javascript importer script.

      You can find the built-in importer code in ~/temp/mediatomb-0.12.1/src/layout/fallback_layout.cc; it took a while to get my head around the detail of how it works, but after that it’s easy to alter it to do whatever you need. The only draw-back is that it’s not as convenient to change as an external script, but given that I never changed my old importer once in the last couple of years, I don’t see that as a major issue.

      And no worries about your English – it’s a lot better than my German or French 🙂

      • Thank you for this 2 years ago…. and again today as i upgraded to 14.04. (i settled on rain’s approach (thanks!), maybe next time i will attack the c++ code)
        It has been fun reminiscing…. 🙂

  8. @richard
    Also back here again after almost exactly two years (and a dead hard drive) and once more I am in your debt.

    Setting this up on a new Mint install (17.1, 64bit) and I had the same patch issues as you and rain – my thanks also to @rain for the suggested disabling patches approach. It’s been too many years since I looked at C++ for me to try redoing the code, too much C# and Java these days for me.

    Thank you all

  9. hi, i tried to compile mediatomb in kubuntu 14.04 according your guide. and i get ‘JS_AddNamedObjectRoot’ was not declared in this scope error. i set up a vm to reproduce side effects. did anything change during the last year in the linked js dependencies?

    libmozjs2d_1.9.1.16-20_amd64.deb
    libmozjs-dev_1.9.1.16-20_amd64.deb

    these files are linked in your guide.i also tried rains method. without any success. Can anyone help me please?

    • I’ve switched over to altering the base C++ code now, so I’ve not tried this method recently. Rain however did report that he had it working only a few months ago (well, last year). It’s certainly possible that there have been changes in the Debian versions of SpiderMonkey that could break the method that we’re discussing in this post. They may simply have stopped supporting such an old level of SpiderMonkey. The best I can suggest is that you try Rains method again, and if that now doesn’t work, then bear in mind that it’s possible to alter the default import routine (that is written in C++ and compiled into the application) instead.
      Doing it that way actually gives you more flexibility, as you have access to all the power of C++, and are not constrained by any limits places on the original Javascript user exit, but the code has no comments, can’t be so easily changed, and (if I remember correctly) uses macros that make it quite difficult to understand. I’m very time constrained at the moment, but will try to put up something to help with that approach in the next few weeks.
      Forgot to add a link to the C++ writeup. You can find it here.
      I hope that helps

  10. Pingback: Overcoming the broken javascript importer in Mediatomb | Richard's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s