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!

2 comments:

  1. Hi,

    Your post is really very useful. I am facing a similar problem. May be you could suggest a workaround.

    I am running MATLAB R 2011a on a cluster running RHEL5.0. My system wide libstdc++.so.6 is older compared to the newer provided in MATLAB.

    Upgrading libstdc++ is out of question. If I do a symlink to the older libstdc++ in /lib64/ MATLAB crashes even before videoreader or MMreader.

    What do you think I should do?

    Regards,
    Subh (subh.arya@gmail.com)

    ReplyDelete
  2. OMG, I am sorry, I just saw your comment 9 months later!

    There must be a difference in the ABI of your system's libstdc++ and the one from Matlab, in which case there is probably nothing that can be done... :(

    But maybe you found a workaround since then? Upgrading to RHEL6.0?

    ReplyDelete