2011/09/03

Using MATLAB's mmreader function on Kubuntu

A problem I always encounter when using a recent MATLAB version on a recent Kubuntu version is that the mmreader function does not work "out of the box" (this is also true for the related functions VideoReader, VideoWriter, mmfileinfo, and mmcompinfo).  These MATLAB functions are used in order to read and write video files that are supported by the underlying operating system. On a fresh installation of Kubuntu, I always get the following error when I try to open a video file with the mmreader function on MATLAB 2010b and 2011a:

>> video = mmreader('videofile.avi')
??? The file requires the following codec(s) to be installed on your system:
    video/x-huffyuv

This error happens  with all video files, even if the needed codec is actually installed on the system. This error is due to the fact that MATLAB is shipping its own version of libstdc++, which seems to be incompatible with the version that is installed on a fresh Kubuntu installation.  Thus, MATLAB cannot use the multimedia backend on Kubuntu (GStreamer) since MATLAB uses it own version of libstdc++ while GStreamer uses the system version of libstdc++. The solution is to make MATLAB use the system version of libstdc++. This can be done by performing the following operations (for MATLAB 64 bits on Kubuntu 64 bits):
  1. First, open a terminal and change the current directory to the following directory:

    cd ${MATLAB}/sys/os/glnxa64/

    where ${MATLAB} must be replaced with the path to the actual MATLAB installation on the system (on my system, MATLAB is installed in /opt/matlab2011a)

  2. Next, make a backup of the files libstdc++.so.X and libstdc++.so.X.Y.Z as follows:

    sudo mv libstdc++.so.6 libstdc++.so.6.bkp
    sudo mv libstdc++.so.6.X.Y libstdc++.so.6.X.Y.bkp


    where X and Y must be replaced according to the file in the current directory (on my system, this file is libstdc++.so.6.0.10)

  3. Finally, make a symbolic link to the system version of libstdc++ as follows:

    sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.X.Z libstdc++.so.6

    where X and Y must be replaced according to the file located in the /usr/lib/x86_64-linux-gnu/ (on Kubuntu 11.04, this file is libstdc++.so.6.0.14)

Now the video file should open correctly in MATLAB:

>> video = mmreader('videofile.avi')

Summary of Multimedia Reader Object for 'videofile.avi'.

  Video Parameters:  30.00 frames per second, RGB24 1024x768.
                     339 total video frames available.


On Kubuntu, some packages must be installed on the system so that MATLAB can handle different file formats and video codecs:

sudo apt-get install gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse

I hope this post will be useful!

2011/07/12

First post

I will post on this blog what I think could be useful to other people on subjects related to computer vision, general programming, Linux configuration and tweaking, etc.  For instance, I might post solutions for problem I encountered while developing computer vision algorithms in programming languages such as C/C++, MATLAB, and Python. I might also post on issues related to the installation and/or the use of the tools needed to develop computer vision algorithm (e.g. OpenCV and others). I am a Linux user since 1998,  so I might share my experiences with configuring or trying new software on this awesome operating system. Of course, I will post on other subjects that I think will be of interest to programmers, Linux fans, and computer vision experts.

I already have an idea for 2 or 3 posts that will be of interests for the future readers of this blog.  Now I just need to find the time to write them...