1
votes

I have been struggling to get VideoReader working on Ubuntu 17.04. If I run a simple program:

v = VideoReader('flame.avi')

I get the following:

Error using VideoReader/init (line 619)

Could not read file due to an unexpected error. Reason: Unable to initialize the video obtain properties

Error in VideoReader (line 172)
        obj.init(fileName);

Now, I have done a little bit of digging, and most people say that this error comes from not having gstreamer0.10 installed.

See: https://www.mathworks.com/matlabcentral/answers/165584-cannot-read-video-matlab-2014b-linux

This one says that gstreamer1.0 is not sufficient to fix this problem: https://www.mathworks.com/matlabcentral/answers/255157-can-t-load-video-using-videoreader-in-matlab-r2015-on-ubuntu-15-04-could-not-read-file-due-to-an-un

The problem comes from trying to install gstreamer0.10. It doesn't appear to be working in Ubuntu 17.

This one talks about how gstreamer isn't working on Ubuntu 17: https://www.mathworks.com/matlabcentral/answers/294258-hello-i-have-a-problem-with-videoreader-on-matlab-r2016a-with-ubtuntu-lts16-04

I was wondering if anyone had any ideas on how to overcome this issue? Is there a different package that I could install that would fulfill the same requirements? I have tried installing matlab-support, and that hasn't helped either. Is there a different issue other than gstreamer0.10?

I would prefer not to re-install Ubuntu 16.04, but understand if that is the only way. But surely, someone has gotten MATLAB working on Ubuntu 17?

2

2 Answers

4
votes

A colleague of mine found a link to a post that solved my problem https://www.mathworks.com/matlabcentral/answers/329796-issue-with-libstdc-so-6

Essentially, you need to redirect MATLAB and tell it to not use its default libstdc++6 file and use your Linux system's instead. I went with the solution at the bottom, and wrote an alias for my .bashrc file.

alias matlab='LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 /usr/local/bin/matlab -desktop'

After testing it out, I have confirmed it works.

0
votes

I had the exact same problem and I was able to solve it by running

sudo apt install gstreamer1.0-plugins-*

on Ubuntu 20.04 with MATLAB R2018a

Moreover, forcing MATLAB to use the system libstdc++ in ways 1. and 2. did not solve the problem:

  1. Write in ~/.bashrc alias matlab='LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 /usr/local/bin/matlab -desktop' closing the terminal, open again, run matlab and still did not work.

  2. going to /usr/local/MATLAB/R2018a/sys/os/glnxa64 and adding .bak to all libstdc++ files (as a means of making them "invisible" to matlab and force it to look for them in the system) did not work either.

EDIT This is working for at least one video, but still other videos give me the same error. So it is not a full solution

EDIT

One such video I could not open with matlab's video reader becomes accessible after converting it with this script (using opencv).

import cv2
import tqdm

cap = cv2.VideoCapture("output.avi")

vw = None
nframes = 100
# for fast test, change the for loop to
# while True:
# to convert the whole video

for _ in tqdm.tqdm(range(nframes)):
    ret, frame = cap.read()
    if not ret:
        break
    if vw is None:
        vw = cv2.VideoWriter("output_safe.avi", cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame.shape[1], frame.shape[0]))
    vw.write(frame)


cap.release()
if vw is None:
    vw.release()

These were the properties of the original video as reported with ffmpeg -i output.avi

Input #0, avi, from 'output.avi':
  Metadata:
    encoder         : Lavf58.64.100
  Duration: 00:01:00.00, start: 0.000000, bitrate: 1822 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 2592x1944 [SAR 1:1 DAR 4:3], 1817 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc

and these are the new properties

Input #0, avi, from 'output_safe.avi':
  Metadata:
    encoder         : Lavf58.61.100
  Duration: 00:00:10.00, start: 0.000000, bitrate: 7594 kb/s
    Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 2592x1944, 7650 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc