Dec 22, 2008

HOWTO: compiling mediatomb + ffmpegthumbnailer + all libraries for Ubuntu... and PS3 :)

Today I'd like to talk about mediatomb, a media server with a nice web user interface allowing you to stream your digital media through your home network on a variety of 'Universal Plug and Play' (UPnP) compatible devices... such as the PS3 :)

Of course, you could just go and install a packaged version of the last official release (0.11) with apt-get, but:
  1. 0.11 was released in March'08, which means that you'll be missing the newest features
  2. that's not fun :)
So, let's get to work and take care of all dependencies needed to build mediatomb from source. This procedure was successfully performed on Ubuntu 8.04 and 8.10.

1) Installing ffmpegthumbnailer

ffmpegthumbnailer is a small tool which uses ffmpeg to generate video thumbnails. These thumbnails will be displayed by mediatomb while you're browsing your video collection.

[Updated on 2008/01/02] This supposes that you have built ffmpeg. If not, you may be missing a number of libraries: please check the comments below for solutions.

First, we need to install libpng:

ubuntu% sudo apt-get install libpng12-dev

Now, let's fetch the ffmpegthumbnailer source and build it:

ubuntu% wget http://ffmpegthumbnailer.googlecode.com/files/ffmpegthumbnailer-1.3.0.tar.gz
ubuntu% tar xvfz ffmpegthumbnailer-1.3.0.tar.gz
ubuntu% cd ffmpegthumbnailer-1.3.0
ubuntu% ./configure --prefix=/usr/local
ubuntu% make
ubuntu% sudo make install

OK, let's move on.

2a) Installing libdvdnav and libdvdread from source

These two libraries are used to browse DVD file structures: mediatomb needs them to read and stream DVD ISO images.

Since we're going to build the very latest mediatomb version, let's make sure we have up to date libs as well.

You do need to build and install libdvdread before libdvdnav, or the latter won't link.

ubuntu% wget ftp://ftp6.mplayerhq.hu/MPlayer/releases/dvdnav/libdvdread-4.1.3.tar.bz2
ubuntu% bzip2 -d libdvdread-4.1.3.tar.bz2
ubuntu% tar xvf libdvdread-4.1.3.tar
ubuntu% ./configure2 --prefix=/usr/local --enable-shared
ubuntu% make
ubuntu% sudo make install

ubuntu% wget ftp://ftp6.mplayerhq.hu/MPlayer/releases/dvdnav/libdvdnav-4.1.3.tar.bz2
ubuntu% bzip2 -d libdvdnav-4.1.3.tar.bz2
ubuntu% tar xvf libdvdnav-4.1.3.tar
ubuntu% ./configure2 --prefix=/usr/local --enable-shared
ubuntu% make
ubuntu% sudo make install

2b) Installing libdvdnav and libdvdread from APT

Both are available as APT packages (libdvdread-dev and libdvdnav-dev), but they're not up to date on Ubuntu 8.04. Anyway, if you don't want to build them, here's how to install them quickly:

ubuntu% sudo apt-get install libdvdread-dev libdvdnav-dev

3) Installing everything else

Sqlite3 is one of the two databases that mediatomb can use (the other is mySQL).

ubuntu% sudo apt-get install libsqlite3-dev

Libtag is needed to read tags in MP3 files, FLAC files and so on:

ubuntu% sudo apt-get install libtag1-dev

Libexpat is needed parse XML files:

ubuntu% sudo apt-get install libexpat1-dev

Libexif is needed to read tags stored in some digital pictures.

ubuntu% sudo apt-get install libexif-dev

Libmp4v2 is needed to parse mp4 files.

ubuntu% sudo apt-get install libmp4v2-dev

Libmagic helps to find the MIME type of a file based on the 'magic number' usually stored in the file header.

ubuntu% sudo apt-get install libmagic-dev

Libcurl is used to fetch web content using HTTP requests. This is how mediatomb can fetch YouTube content and stream it.

ubuntu% sudo apt-get install libcurl4-openssl-dev

Last, libmozjs is the JavaScript engine used by mediatomb.

ubuntu% sudo apt-get install libmozjs-dev

4) Building mediatomb

Let's fetch the latest sources from the Subversion repository:

ubuntu% svn co https://svn.mediatomb.cc/svnroot/mediatomb/trunk/mediatomb mediatomb

Now, let's generate the configure script and run it (you need autoconf and automake for this):

ubuntu% cd mediatomb
ubuntu% autoreconf -i
ubuntu% ./configure --prefix=/usr/local
lots of output removed
CONFIGURATION SUMMARY ----
sqlite3 : yes
mysql : missing
libjs : yes
libmagic : yes
inotify : yes
libexif : yes
id3lib : disabled
taglib : yes
libmp4v2 : yes
libdvdnav : yes
ffmpeg : yes
ffmpegthumbnailer : yes
external transcoding : yes
curl : yes
YouTube : yes
Weborama : disabled
Apple Trailers : yes
SopCast : disabled
libextractor : disabled
db-autocreate : yes

As you can see, we have pretty much enabled everything (again, sqlite3 is preferred over mySQL, and taglib over id3lib). Support for SopCast and Weborama isn't completely ready yet, so it's probably safer to leave them out.

All right, let's build mediatomb:

ubuntu% make
ubuntu% sudo make install
ubuntu% sudo ldconfig

And now...

ubuntu% mediatomb
MediaTomb UPnP Server version 0.12.0 - http://mediatomb.cc/
===============================================================================
Copyright 2005-2008 Gena Batsyan, Sergey Bostandzhyan, Leonhard Wimmer.
MediaTomb is free software, covered by the GNU General Public License version 2


All right. Let's power up the PS3 and see if it can see the mediatomb server.



Yes it does. Now using the mediatomb GUI, in just a few clicks, I added some pictures and music to my library. They are almost immediately visible on the PS3:



Not bad at all! That's it for the mediatomb installation. There's still plenty of configuration to do, but this will be the subject of another entry :)

40 comments:

  1. Thanks for this, linking to it from my blog.

    A little pointer to anyone compiling the ffmpegthumbnailer that gets the error

    configure: error: +Could not find ffmpeg. Please update PKG_CONFIG_PATH to point at location of ffmpeg pkgconfig files directory.

    Run this...

    cat config.log | grep "No package"

    and that will tell you what packages you need to download. Make sure they are the dev ones!

    i.e. mine said

    No package 'libavformat' found
    No package 'libswscale' found

    so i ran

    sudo apt-get install libavformat-dev libswscale-dev

    Cheers,
    Dean
    My Coding Blog

    ReplyDelete
  2. Hi Dean, you're right: I assumed ffmpeg was already installed. I'll update the entry accordingly. Cheers!

    ReplyDelete
  3. Hi JS,

    I've really enjoyed your blog and using your howtos. I'm having a problem compiling mediatomb though.
    I started with your other tutorial compiling ffmpeg + x264 + MP3 + Xvid + AMR on Ubuntu (everything
    appears to have gone smooth) and have since moved on to this mediatomb howto. When I 'make'
    mediatomb I receive the following.

    /usr/local/lib/libavformat.so: undefined reference to `av_fifo_realloc2'
    /usr/local/lib/libavcodec.so.52: undefined reference to `av_memcpy_backptr'
    /usr/local/lib/libavcodec.so.52: undefined reference to `av_lfg_init'

    I read on another one of your howtos how someone else was having similar issues. It was recommended
    to remove the a and so files for the offending. Where do I delete from if these files exist? My /usr/lib
    or the source directory for what I'm compiling?

    Thanks for some great reading!

    Ig

    ReplyDelete
  4. I get the same.

    Did apt-get remove libavcodec-dev, then deleted libavcodec.a and libavcodec.so from /usr/local/lib, then installed libavcodec-dev again. Still got the same error when doing 'make'

    ReplyDelete
  5. @iglooc00l:

    yes, it's the same problem as the other person. You need to remove any previous copy of these libraries (.a & .so). They have probably been installed using APT, so you may first try to remove them with 'apt-get remove libavcodec-dev', etc.

    If that doesn't work, just look for the offending files in /usr/lib and delete them (or move them to a backup directory if you're worried). Then just run 'ldconfig' to refresh the library cache and you should be fine.

    ReplyDelete
  6. @Magnus:

    you need to check for older libs in /usr/lib. The ones in /usr/local/lib are the one you built :)

    ReplyDelete
  7. Okay, new snag. "./configure" ffmpegthumbnailer

    configure: error: +Could not find ffmpeg. Please update PGK_CONFIG_PATH to point at location of ffmpeg pkgconfig files directory.

    What gives...When I "./configure" mediatomb, it says it finds ffmpeg. Why doesnte ffmpegthumbnailer suddenly?

    This is hard for someone who hasn't used linux in 10 years :D

    ReplyDelete
  8. @Magnus: looks like you have the same problem as Dean (1st comment on this entry). Please try his suggestion, it should help.

    ReplyDelete
  9. Hi JS,
    what do I need to add to the config.xml to make mediatomb play DVD ISO files?
    The original config.xml contains only these two lines (less-than signs removed because of html code...):

    treat mimetype="application/x-iso9660" as="dvd"/>
    treat mimetype="application/x-iso9660-image" as="dvd">

    Well, that's obviously not enough to make mediatomb recognize iso files so I added

    map from="iso" to="application/x-iso-9660-image"/>

    to the mappings section, but that did'nt help... My PS3 shows iso files on mediatomb as "incompatible data".

    As there's an extra import script (import-dvd.js) I assume a new category should show up if mediatomb recognizes an iso file?

    Maybe you could post the lines I need to add/edit in the config.xml?

    Greets Stefan

    ReplyDelete
  10. Oh, of course it's

    map from="iso" to="application/x-iso9660-image"/>

    ReplyDelete
  11. 'sudo apt-get remove libavcodec-dev' and removing the .a and .so files in /usr/lib did the trick.

    Couldn't have done it without this blog. And I learned a LOT in the process, thanks a bunch JS.

    Now I just need to figure out how to set up transcoding =)

    ReplyDelete
  12. Guess I spoke too soon.

    'MediaTomb UPnP Server version 0.12.0 - http://mediatomb.cc/

    Output removed

    2009-01-02 20:07:35 INFO: Loading configuration from: /home/nannus/.mediatomb/config.xml
    2009-01-02 20:07:35 INFO: Checking configuration...
    2009-01-02 20:07:35 ERROR: /usr/share/mediatomb/web : 20 x No such file or directory'

    ReplyDelete
  13. Fixed. Just needed to delete config.xml

    Sorry for chattering all over your blog =)

    ReplyDelete
  14. Uhm, my typo was only in the comment, not in the config.xml...
    So my problem still persists: How do I need to configure mediatomb to play DVD ISO files? :-/

    By the way, JS, thanks for your great tutorials on how to set up mediatomb for online content, last.fm, ffmpegthumbnailer and stuff... I got it all up and running - perfect :)

    ReplyDelete
  15. @Stefan: AFAIK, this is not fully functional yet. The mediatomb guys will try to complete for the 0.12 release.

    ReplyDelete
  16. Alright, thanks a lot :)
    Do you know when 0.12 will be released? The last news entry on mediatomb.cc regarding the release date (2008-09-27) says "[...] we can release it this year"...

    ReplyDelete
  17. Small typo, the path to libdvdread should be:

    wget ftp://ftp6.mplayerhq.hu/MPlayer/releases/dvdnav/libdvdread-4.1.3.tar.bz2

    i.e., ../dvdnav/.. instead of ../dvdread/..

    Thank you

    ReplyDelete
  18. @royw: grrr, just fixed it. Thanks :)

    ReplyDelete
  19. Thanks for all your work on this... I found it after getting everything except ffmpegthumbnailer working and installed. When I try to install it I receive the same error over and over again no matter which version I try to install:

    libffmpegthumbnailer/.libs/libffmpegthumbnailer.so: undefined reference to `BZ2_bzDecompress'
    libffmpegthumbnailer/.libs/libffmpegthumbnailer.so: undefined reference to `BZ2_bzDecompressEnd'
    libffmpegthumbnailer/.libs/libffmpegthumbnailer.so: undefined reference to `BZ2_bzDecompressInit'
    collect2: ld returned 1 exit status
    make[2]: *** [ffmpegthumbnailer] Error 1


    Have any clues on how to fix it?

    ReplyDelete
  20. @Anonymous: that's weird. I can't find these symbols in my build:

    ubuntu% pwd
    /home/julien/tmp/ffmpegthumbnailer-1.3.0/src/libffmpegthumbnailer/.libs
    ubuntu% nm *.o *.so |grep BZ2
    ubuntu%

    Can you run the same command and post the output?

    ReplyDelete
  21. sorry it took a bit to get back to you. I appreciate the fast response. After the initial tries it started spewing errors about gcc 4.2 and a bug. Rebooted the system and tried to compile ffmpegthumbnailer again and it succeeded! I now have all working that should be working. Not sure if thumbnails are supposed to show on the PS3 or not but I do have flac transcoding.

    Did I get you right when you said the ISO stuff is still not functional yet for the PS3?

    Thx again!

    ReplyDelete
  22. Thanks for this how-to all is working well except I can't seem to get mediatomb start at boot, any ideas?

    ReplyDelete
  23. so first off thanks for such a great tutorial!! I am having one tiny problem with getting mediatomb to start properly. Everything compiled without errors but when I start mediatomb I get the following error:

    mediatomb: symbol lookup error: /usr/local/lib/libavcodec.so.52: undefined symbol: av_gcd

    I have tried reinstalling libavcodec without any luck. Any ideas? Thanks in advance!

    ReplyDelete
  24. @Bert: one way to do it is "System" > "Preferences" > "Sessions" and add mediatomb to the list.

    @Wheaties: this symbol is in libavutil. My guess is that you have an older version of the library in /usr/lib. You should either uninstall it, or define LD_LIBRARY_PATH in you .cshrc (or equivalent):

    LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH

    ReplyDelete
  25. @Anonymous: yes, AFAIK, ISO support is not there yet. I haven't seen any recent SVN update on this but I'll keep my eyes peeled :)

    ReplyDelete
  26. @js I'm running mediatomb on a server, so adding it to sessions isn't an option. I did find some startup-scripts but somehow they don't do the job. So if someone has it working, please post it.

    greetings Bert

    ReplyDelete
  27. I thought I read in one of the TUT's, thanks by the way working great, that vlc was used in the past to stream the youtub content, or the apple trailers? if that's the case would it be possible to do the same with the iso files until mediatomb is ready? Iso saves so much space and for us poor folk means less $$

    ReplyDelete
  28. I'm getting this error when running mediatomb.

    $ mediatomb
    mediatomb: error while loading shared libraries: libavcodec.so.51: cannot open shared object file: No such file or directory

    I compiled ffmpeg from source following an earlier post on this blog:
    /usr/lib/libavcodec.a
    /usr/lib/libavcodec.so
    /usr/lib/libavcodec.so.52
    /usr/lib/libavcodec.so.52.14.0

    Any ideas?

    Also ran into this error on ffmpegthumbnailer make: http://code.google.com/p/ffmpegthumbnailer/issues/detail?id=24&q=moviedecoder

    Managed to get around it by following the solution of someone on the ubuntu forums, using prevu to install 1.3.0 from jaunty:
    http://ubuntuforums.org/showthread.php?t=1064609

    ReplyDelete
  29. Fixed by recompiling/installing everything with --prefix=/usr/local instead of --prefix=/usr.

    Had to go back and reinstall a lot of other stuff for /usr/local as well, but I should probably have done that a long time ago.

    ReplyDelete
  30. Great tutorial!

    Almost everything is working ok.

    Somebody asked for a /etc/init.d startup service script. Here is mine for Ubuntu 8.10 (based in te script from package mediatomb-daemon, slightly modified). It works fine for me. Configuration un /etc/mediatomb/config.xml.
    Create autostart/autostop links with "sudo update-rc.d mediatomb defaults"

    Good luck



    # Read configuration variable file if it is present
    [ -r $DEFAULT ] && . $DEFAULT

    # Load the VERBOSE setting and other rcS variables
    [ -f /etc/default/rcS ] && . /etc/default/rcS

    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
    . /lib/lsb/init-functions

    # Start the daemon if NO_START is disabled in DEFAULT
    if [ "$NO_START" = "yes" ]; then
    test "$1" = "start" && \
    {
    log_warning_msg "$NAME: Not starting $DESC."
    log_warning_msg "$NAME: Disabled in $DEFAULT."
    }
    exit 0
    fi

    # Run as root if USER not specified
    if [ ! $USER ]; then
    USER=root
    fi

    # Check for an invalid user or one without a home directory
    eval USERHOME=~$USER
    if [ "${USERHOME#/}" = "${USERHOME}" ]; then
    log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid."
    exit 1
    fi

    # Check if group is not specified and assign a proper group
    if [ -z $GROUP ]; then
    GROUP="$USER"
    fi

    if [ "$INTERFACE" != "" ] ; then
    INTERFACE_ARG="-e $INTERFACE"
    else
    INTERFACE_ARG=""
    fi

    DAEMON_ARGS="-c /etc/mediatomb/config.xml -d -u $USER -g $GROUP -P $PIDFILE -l $LOGFILE $INTERFACE_ARG $OPTIONS"

    #
    # Function that starts the daemon/service.
    #
    do_start() {
    # Return
    # 0 if daemon has been started
    # 1 if daemon was already running
    # 2 if daemon could not be started
    touch $PIDFILE
    chown $USER:$GROUP $PIDFILE
    touch $LOGFILE
    chown $USER:$GROUP $LOGFILE
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
    --test > /dev/null \
    || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
    $DAEMON_ARGS \
    || return 2
    }

    #
    # Function that stops the daemon/service.
    #
    do_stop() {
    # Return
    # 0 if daemon has been stopped
    # 1 if daemon was already stopped
    # 2 if daemon could not be stopped
    # other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    rm -f $PIDFILE
    return "$RETVAL"
    }

    #
    # Function that sends a SIGHUP to the daemon/service.
    #
    do_reload() {
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
    }

    case "$1" in
    start)
    if [ -n "$INTERFACE" ]; then
    # try to add the multicast route
    if [ "$VERBOSE" != no ]; then
    {
    log_action_begin_msg \
    "$NAME: Trying to add the multicast route"
    $ROUTE_ADD $INTERFACE \
    && log_action_end_msg 0
    } || {
    true && \
    log_warning_msg "Failed to add multicast route. skipping."
    }
    else
    $ROUTE_ADD $INTERFACE >/dev/null 2>&1 || true
    fi
    fi
    log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;;
    2) log_end_msg 1 ;;
    esac
    ;;
    stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
    0)
    log_end_msg 0
    if [ -n "$INTERFACE" ]; then
    # try to add the multicast route
    if [ "$VERBOSE" != no ]; then
    {
    log_action_begin_msg \
    "$NAME: Trying to delete the multicast route"
    $ROUTE_DEL $INTERFACE \
    && log_action_end_msg 0
    } || {
    true && \
    log_warning_msg \
    "Failed to delete multicast route. skipping."
    }
    else
    $ROUTE_DEL $INTERFACE >/dev/null 2>&1 || true
    fi
    fi
    ;;
    1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;;
    2) log_end_msg 1 ;;
    esac
    ;;
    reload|force-reload)
    log_daemon_msg "Reloading $DESC" "$NAME"
    do_reload
    log_end_msg $?
    ;;
    restart)
    #
    # If the "reload" option is implemented, move the "force-reload"
    # option to the "reload" entry above. If not, "force-reload" is
    # just the same as "restart".
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1)
    sleep 1
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;; # Old process is still running
    *) log_end_msg 1 ;; # Failed to start
    esac
    ;;
    *)
    # Failed to stop
    log_end_msg 1
    ;;
    esac
    ;;
    *)
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
    exit 3
    ;;
    esac

    ReplyDelete
  31. Hi, thanks for an excellent guide. I myself is using Fedora so I had a lite bit of work to do before i got it all right. However when I read DVD:s (ISO) something goes wrong :


    libdvdnav: Using dvdnav version 4.1.3
    libdvdread: Using libdvdcss version 1.2.10 for DVD access
    libdvdnav: DVD Title: Jumper Sample - FDSCR
    libdvdnav: DVD Serial Number: 386C306300005321
    libdvdnav: DVD Title (Alternative):
    libdvdnav: Unable to find map file '/home/Caine/.dvdnav/Jumper Sample - FDSCR.map'
    libdvdnav: DVD disk reports itself with Region mask 0x00400000. Regions: 1 2 3 4 5 6 8


    Anyone else seen this? <:P

    ReplyDelete
  32. Might add that i get this when i run the file from the ps3

    ERROR: DVD Image requested but title parameter is missing!

    ReplyDelete
  33. the include path for mp4 support seems wrong. Its looking for mp4.h but no package provides that header file on Debian. Shouldn't this be mp4v2.h?

    ReplyDelete
  34. When i transcode a .mkv file
    i get corrupt format.

    (on the top of my head, at work)
    in the terminal i can see a %in %out message beeing displayed twice.

    ffmpegthumbnailer however seems to be able to create a screenshot of the file .. This didn't go as smotth as i hoped < : )

    ReplyDelete
  35. @Hed:

    AFAIK, ISO support isn't there yet (see http://juliensimon.blogspot.com/2009/01/status-update-on-mediatomb-012.html for more).

    Transcoding MKV is tricky (I don't do it myself). You should try converting the file from the command line using ffmpeg: if it doesn't work, then it's an ffmpeg issue, not a mediatomb issue.

    ReplyDelete
  36. @julien

    Ahh my bad. I just thougt it was as i saw that you had it in your config. < = )

    about the matroska issue:
    ffmpeg seems to be working correctly.
    When i run it with the ffmpeg script is outputs allot of :

    [mpeg4 @ 0x9dc0c50]Invalid and inefficient vfw-avi packed B frames detected

    but other then that it keeps on going. I must confess that i don't really know what that in tails. Video en/decoding is very new to me. :P

    ReplyDelete
  37. This is a great tutorial, and I've used it to install Mediatomb with 9.04 Jaunty. But I'm wondering how to install it so Mediatomb runs as a daemon, instead of forcing me to start it manually. There is nothing inside /etc/default/mediatomb and no program in the init.d folder. I'm also worried that if I install the daemon from the repository, it will overwrite this compiled version. Any suggestions?

    ReplyDelete
  38. it is worth mentioning that jpeg support is only enabled when jpeglib is installed before configureing ffmpegthumbnailer

    apt-get install libjpeg62-dev

    ReplyDelete
  39. Hi guys,
    I am new to ubuntu. I am trying to follow this utility. I installed ffmpegthumbnailer using apt, followed the rest of the tutorial using Jaunty, when I go to compile it says ffmpegthumbnailer ins not there. I installed it anyway and now I get the error "ERROR: /usr/share/mediatomb/web : 20 x No such file or directory"

    i can install mediatomb from apt, but I can't get my mp3 files to play so Itried this. Any suggestions

    ReplyDelete
  40. Error on last post, I meant to say I am using Karmic, not Jaunty

    ReplyDelete